add nix derivation to build catppuccin userstyles

This commit is contained in:
LordMZTE 2024-04-21 16:22:11 +02:00
parent a541d203bd
commit 7413815278
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
4 changed files with 43 additions and 4 deletions

View file

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1712791164, "lastModified": 1713537308,
"narHash": "sha256-3sbWO1mbpWsLepZGbWaMovSO7ndZeFqDSdX0hZ9nVyw=", "narHash": "sha256-XtTSSIB2DA6tOv+l0FhvfDMiyCmhoRbNB+0SeInZkbk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "1042fd8b148a9105f3c0aca3a6177fd1d9360ba5", "rev": "5c24cf2f0a12ad855f444c30b2421d044120c66f",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -23,7 +23,7 @@
config._module.args = { config._module.args = {
inherit inputs; inherit inputs;
inherit pkgs system; inherit pkgs system;
inherit (pkgs) lib stdenv; inherit (pkgs) lib stdenv stdenvNoCC;
}; };
# Local user nix env # Local user nix env

View file

@ -3,5 +3,6 @@
imports = [ imports = [
./cgnix ./cgnix
./mcdev.nix ./mcdev.nix
./userstyles.nix
]; ];
} }

38
nix/userstyles.nix Normal file
View file

@ -0,0 +1,38 @@
# Module that provides an output for a stylus import file with catppuccin themes.
{ pkgs, stdenvNoCC, ... }:
let
flavor = "mocha";
accent-color = "red";
in
{
packages.userstyles = stdenvNoCC.mkDerivation {
name = "userstyles.json";
src = pkgs.fetchurl {
url = "https://github.com/catppuccin/userstyles/releases/download/all-userstyles-export/import.json";
hash = "sha256-eYU9Y95au9mI3muS4+1QJt31W7s2zVmurdKbQ1dU+pk=";
};
dontUnpack = true;
# TODO: use better language
realBuilder = "${pkgs.deno}/bin/deno";
args = [
"run"
"-A"
(pkgs.writeText "build.js" ''
const json = await import(Deno.env.get("src"), { with: { type: "json" } });
const processed = json.default.map(theme => {
if (theme.usercssData?.vars?.accentColor?.default)
theme.usercssData.vars.accentColor.default = "${accent-color}";
if (theme.usercssData?.vars?.darkFlavor?.default)
theme.usercssData.vars.darkFlavor.default = "${flavor}";
return theme;
});
Deno.writeTextFileSync(Deno.env.get("out"), JSON.stringify(processed));
'')
];
};
}