Skip to content

Commit

Permalink
build(nix): improve nix build, step 1
Browse files Browse the repository at this point in the history
refs: #218
  • Loading branch information
nekowinston committed Nov 27, 2023
1 parent 235693b commit 92ecc8e
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
use nix
use nix ./nix/shell.nix
layout node
4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ plugins:
path: .yarn/plugins/yarn-plugin-nixify.cjs
spec: "https://raw.githubusercontent.com/stephank/yarn-plugin-nixify/main/dist/yarn-plugin-nixify.js"

# yarn-plugin-nixify options
generateDefaultNix: false
nixExprPath: nix/yarn-project.nix

yarnPath: .yarn/releases/yarn-4.0.2.cjs
57 changes: 0 additions & 57 deletions default.nix

This file was deleted.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
pkgs = nixpkgs.legacyPackages.${system};
in rec {
default = catppuccin-vsc;
catppuccin-vsc = pkgs.callPackage ./. {};
catppuccin-vsc = pkgs.callPackage ./nix {};
});

overlays.default = final: prev: let
Expand All @@ -32,7 +32,7 @@
devShells = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix {inherit pkgs;};
default = import ./nix/shell.nix {inherit pkgs;};
});
};
}
87 changes: 87 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
pkgs ? import <nixpkgs> {},
accentColor ? "mauve",
boldKeywords ? true,
italicComments ? true,
italicKeywords ? true,
extraBordersEnabled ? false,
workbenchMode ? "default",
bracketMode ? "rainbow",
colorOverrides ? {},
customUIColors ? {},
} @ inputs: let
inherit (pkgs) lib;

packageJSON = builtins.fromJSON (builtins.readFile ../package.json);
properties = (builtins.head packageJSON.contributes.configuration).properties;
validAccents = properties."catppuccin.accentColor".enum;
validWorkbenchModes = properties."catppuccin.workbenchMode".enum;
validBracketModes = properties."catppuccin.bracketMode".enum;

inherit (packageJSON) name version;
pname = "${name}-${version}";

options = builtins.removeAttrs inputs ["pkgs"];
src = pkgs.nix-gitignore.gitignoreSource [] ../.;

builder = pkgs.callPackage ./yarn-project.nix {} {
inherit src;
overrideAttrs = {
pname = "${pname}-builder";

buildPhase = ''
runHook preBuild
yarn compile
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out
cp -r dist/* $out
runHook postInstall
'';
};
};

extension = pkgs.stdenvNoCC.mkDerivation {
inherit name version pname src;
buildInputs = [pkgs.nodejs pkgs.vsce pkgs.yarn];

# check in the ./themes/.flag so it doesn't prompt for initial rebuilds
patchPhase = ''
runHook prePatch
printf "\n!themes/.flag\n" >> .vscodeignore
runHook postPatch
'';

buildPhase = ''
runHook preBuild
mkdir -p themes dist
cp -r ${builder}/* dist/
touch ./themes/.flag
node dist/hooks/generateThemes.js '${builtins.toJSON options}'
vsce package --allow-star-activation --yarn
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out
# rename the file extension to zip for the buildVSCodeMarketplaceExtension builder
mv catppuccin-vsc-*.vsix $out/catppuccin-vsc.zip
runHook postInstall
'';
};
in
(lib.checkListOfEnum "${pname}: accent" validAccents [accentColor])
(lib.checkListOfEnum "${pname}: workbenchMode" validWorkbenchModes [workbenchMode])
(lib.checkListOfEnum "${pname}: bracketMode" validBracketModes [bracketMode])
pkgs.vscode-utils.buildVscodeMarketplaceExtension {
vsix = "${extension.outPath}/catppuccin-vsc.zip";
mktplcRef = {
# lowercase since it is used in the pname
publisher = "catppuccin";
inherit name version;
};
}
2 changes: 2 additions & 0 deletions shell.nix → nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ in
buildInputs = [
nodejs
(pkgs.yarn.override {inherit nodejs;})
pkgs.alejandra
pkgs.nil
];
}
4 changes: 2 additions & 2 deletions yarn-project.nix → nix/yarn-project.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"chromatic": "chromatic --exit-zero-on-changes --exit-once-uploaded --project-token chpt_e3cba49738d7554",
"compile": "tsup",
"compile:theme": "tsx src/hooks/generateThemes.ts",
"dev": "DEBUG=1 yarn build",
"dev": "yarn compile:theme && yarn compile --env.NODE_ENV development",
"lint": "eslint . --ext .ts",
"package": "vsce package --allow-star-activation --yarn",
"postbuild": "prettier -w ./themes",
Expand Down
8 changes: 6 additions & 2 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { defineConfig } from "tsup";

const dev = process.env.NODE_ENV === "development";

export default defineConfig({
entry: ["src/browser.ts", "src/main.ts"],
entry: ["src/browser.ts", "src/main.ts", "src/hooks/generateThemes.ts"],
external: ["vscode"],
sourcemap: true,
sourcemap: dev,
minify: !dev,
target: "node16",
clean: true,
splitting: true,
});

0 comments on commit 92ecc8e

Please sign in to comment.