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": {
"nixpkgs": {
"locked": {
"lastModified": 1712791164,
"narHash": "sha256-3sbWO1mbpWsLepZGbWaMovSO7ndZeFqDSdX0hZ9nVyw=",
"lastModified": 1713537308,
"narHash": "sha256-XtTSSIB2DA6tOv+l0FhvfDMiyCmhoRbNB+0SeInZkbk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1042fd8b148a9105f3c0aca3a6177fd1d9360ba5",
"rev": "5c24cf2f0a12ad855f444c30b2421d044120c66f",
"type": "github"
},
"original": {

View File

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

View File

@ -3,5 +3,6 @@
imports = [
./cgnix
./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));
'')
];
};
}