Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nix build #147

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dist/
node_modules/
result
storybook-static/
themes/
.eslintcache
Expand Down
1 change: 1 addition & 0 deletions .yarn/plugins/yarn-plugin-nixify.cjs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ plugins:
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/plugin-list.cjs
spec: "https://github.com/arendjr/yarn-plugin-list/releases/latest/download/yarn-plugin-list.js"
- path: .yarn/plugins/yarn-plugin-nixify.cjs
spec: "https://raw.githubusercontent.com/stephank/yarn-plugin-nixify/main/dist/yarn-plugin-nixify.js"

yarnPath: .yarn/releases/yarn-3.6.3.cjs
yarnPath: .yarn/releases/yarn-3.6.3.cjs
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,50 @@ You can find the compiled theme JSON files (with default settings as documented

This can be useful if you want to use syntax highlighters that work with VSCode themes (like Shiki and derivatives), or if your work environment only allows you to install allowlisted extensions.

**Nix (Home-Manager) users**

If you want to change the theme configuration, the theme expects to have a mutable directory to write it's JSON files into.
This means that you will have to either

- Install this extension in a non-declarative way, so that the extension has permissions to write files.\
This means fully excluding `nixpkgs.vscode-extensions.catppuccin.catppuccin-vsc` from your configuration; Just using `programs.vscode.mutableExtensionsDir = true;` will **NOT WORK**.
- Use the `flake.nix` to build it with your VSCode configuration, using overrides.\
This is a declarative way to compile the theme with your preferred options. Please see the example below for a sample configuration.

<details>
<summary>❄️ Nix Configuration</summary>

```nix
{
# in your inputs:
inputs.catppuccin-vsc.url = "github.com:catppuccin/vscode";

# add the overlay:
nixpkgs.overlays = [inputs.catppuccin-vsc.overlays.default];
# the package will be available as
# - pkgs.catppuccin-vsc
# - pkgs.vscode-extensions.catppuccin.catppuccin-vsc

# in your home-manager options:
programs.vscode.extensions = [
# all the theme options will be available as overrides, these are defaults:
(pkgs.catppuccin-vsc.override {
accentColor = "mauve";
boldKeywords = true;
italicComments = true;
italicKeywords = true;
extraBordersEnabled = false;
workbenchMode = "default";
bracketMode = "rainbow";
colorOverrides = {};
customUIColors = {};
})
];
}
```

</details>

## Customization

> **Note**\
Expand Down
57 changes: 57 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
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"];
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 [accentColor])
(lib.checkListOfEnum "${pname}: workbenchMode" validWorkbenchModes [workbenchMode])
(lib.checkListOfEnum "${pname}: bracketMode" validBracketModes [bracketMode])
pkgs.vscode-utils.buildVscodeMarketplaceExtension {
vsix = "${project.outPath}/catppuccin-vsc.zip";
mktplcRef = {
# lowercase since it is used in the pname
publisher = "catppuccin";
inherit name version;
};
}
27 changes: 27 additions & 0 deletions flake.lock

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

38 changes: 38 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs = {nixpkgs, ...} @ inputs: let
systems = ["aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
in {
packages = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in rec {
default = catppuccin-vsc;
catppuccin-vsc = pkgs.callPackage ./. {};
});

overlays.default = final: prev: let
pkg = inputs.self.packages.${prev.stdenv.hostPlatform.system}.default;
in {
# create a new package
catppuccin-vsc = pkg;
# overwrite the vscode-extensions package
vscode-extensions =
prev.vscode-extensions
// {
catppuccin =
(prev.vscode-extensions.catppuccin or {})
// {
catppuccin-vsc = pkg;
};
};
};

devShells = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix {inherit pkgs;};
});
};
}
5 changes: 4 additions & 1 deletion src/hooks/generateThemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import type { CatppuccinFlavour } from "../types";
const themeDir = path.join(__dirname, "../../themes");
const flavours = Object.keys(variants) as CatppuccinFlavour[];

// options can also be passed as a JSON string
const options = process.argv[2] ? JSON.parse(process.argv[2]) : {};

flavours.map((flavour) => {
const theme = compileTheme(flavour, defaultOptions);
const theme = compileTheme(flavour, { ...defaultOptions, ...options });
// ignore error if directory exists
fs.mkdir(themeDir, { recursive: true }).then(() => {
fs.writeFile(
Expand Down
Loading