Skip to content

Commit

Permalink
build(nix): final refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nekowinston committed Sep 12, 2023
1 parent 9f09768 commit f5993c2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
58 changes: 39 additions & 19 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,56 @@
boldKeywords ? true,
italicComments ? true,
italicKeywords ? true,
colorOverrides ? {},
extraBordersEnabled ? false,
workbenchMode ? "default",
bracketMode ? "rainbow",
extraBordersEnabled ? false,
colorOverrides ? {},
customUIColors ? {},
}: 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 = {
inherit accent boldKeywords italicComments italicKeywords colorOverrides workbenchMode bracketMode extraBordersEnabled customUIColors;
};
project = (pkgs.callPackage ./yarn-project.nix {} {src = ./.;}).overrideAttrs (old: {
src = pkgs.nix-gitignore.gitignoreSource [] ./.;
buildPhase = ''
yarn compile
yarn compile:theme '${builtins.toJSON options}'
yarn package
'';
installPhase = ''
mkdir -p $out
# rename the file extension to zip for the buildVSCodeMarketplaceExtension builder
mv catppuccin-vsc-*.vsix $out/catppuccin-vsc.zip
'';
});
packageJSON = builtins.fromJSON (builtins.readFile ./package.json);
inherit (packageJSON) name version;
inherit (packageJSON.__metadata) publisherDisplayName;
project =
(pkgs.callPackage ./yarn-project.nix {} {
src = pkgs.nix-gitignore.gitignoreSource [] ./.;
})
.overrideAttrs (old: {
# check in the ./themes/.flag so it doesn't prompt for initial rebuilds
patchPhase = ''
printf "\n!themes/.flag\n" >> .vscodeignore
'';
buildPhase = ''
yarn compile
yarn compile:theme '${builtins.toJSON options}'
touch ./themes/.flag
yarn package
'';
installPhase = ''
mkdir -p $out
# rename the file extension to zip for the buildVSCodeMarketplaceExtension builder
mv catppuccin-vsc-*.vsix $out/catppuccin-vsc.zip
'';
});
in
(lib.checkListOfEnum "${pname}: accent" validAccents [accent])
(lib.checkListOfEnum "${pname}: workbenchMode" validWorkbenchModes [workbenchMode])
(lib.checkListOfEnum "${pname}: bracketMode" validBracketModes [bracketMode])
pkgs.vscode-utils.buildVscodeMarketplaceExtension {
vsix = "${project.outPath}/catppuccin-vsc.zip";
mktplcRef = {
publisher = publisherDisplayName;
# lowercase since it is used in the pname
publisher = "catppuccin";
inherit name version;
};
}
8 changes: 7 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
prev.vscode-extensions
// {
catppuccin =
prev.catppuccin
(prev.vscode-extensions.catppuccin or {})
// {
catppuccin-vsc = pkg;
};
};
};

devShells = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix {inherit pkgs;};
});
};
}

0 comments on commit f5993c2

Please sign in to comment.