diff --git a/stylix/hm/palette.nix b/stylix/hm/palette.nix index e6e0abd7..2c358b21 100644 --- a/stylix/hm/palette.nix +++ b/stylix/hm/palette.nix @@ -7,7 +7,14 @@ args: config = { xdg.configFile = { # See ../nixos/palette.nix for the rational behind these two options - "stylix/palette.json".source = config.stylix.generated.json; + "stylix/generated.json".source = config.lib.stylix.scheme { + template = builtins.readFile ../palette.json.mustache; + extension = ".json"; + }; + "stylix/palette.json".source = config.lib.stylix.colors { + template = builtins.readFile ../palette.json.mustache; + extension = ".json"; + }; "stylix/palette.html".source = config.lib.stylix.colors { template = builtins.readFile ../palette.html.mustache; extension = ".html"; diff --git a/stylix/nixos/palette.nix b/stylix/nixos/palette.nix index b14bdcda..4694696b 100644 --- a/stylix/nixos/palette.nix +++ b/stylix/nixos/palette.nix @@ -10,7 +10,18 @@ args: # garbage collection, so future configurations can be evaluated without # having to generate the palette again. The generator is not kept, only # the palette which came from it, so this uses very little disk space. - "stylix/palette.json".source = config.stylix.generated.json; + # The extra indirection should prevent the palette generator from running + # when the theme is manually specified. generated.json is necessary in + # the presence of overrides. + "stylix/generated.json".source = config.lib.stylix.scheme { + template = builtins.readFile ../palette.json.mustache; + extension = ".json"; + }; + + "stylix/palette.json".source = config.lib.stylix.colors { + template = builtins.readFile ../palette.json.mustache; + extension = ".json"; + }; # We also provide a HTML version which is useful for viewing the colors # during development. diff --git a/stylix/palette.json.mustache b/stylix/palette.json.mustache new file mode 100644 index 00000000..e8dde342 --- /dev/null +++ b/stylix/palette.json.mustache @@ -0,0 +1,21 @@ +{ + "base00": "{{{base00}}}", + "base01": "{{{base01}}}", + "base02": "{{{base02}}}", + "base03": "{{{base03}}}", + "base04": "{{{base04}}}", + "base05": "{{{base05}}}", + "base06": "{{{base06}}}", + "base07": "{{{base07}}}", + "base08": "{{{base08}}}", + "base09": "{{{base09}}}", + "base0A": "{{{base0A}}}", + "base0B": "{{{base0B}}}", + "base0C": "{{{base0C}}}", + "base0D": "{{{base0D}}}", + "base0E": "{{{base0E}}}", + "base0F": "{{{base0F}}}", + "scheme": "Stylix", + "author": "Stylix", + "slug": "stylix" +} diff --git a/stylix/palette.nix b/stylix/palette.nix index 9cd04037..c8ef3939 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -8,16 +8,18 @@ let cfg = config.stylix; - paletteJSON = pkgs.runCommand "palette.json" { } '' - ${palette-generator}/bin/palette-generator ${cfg.polarity} ${cfg.image} $out - ''; - generatedPalette = importJSON paletteJSON; - - generatedScheme = generatedPalette // { - author = "Stylix"; - scheme = "Stylix"; - slug = "stylix"; - }; + paletteJSON = let + generatedJSON = pkgs.runCommand "palette.json" { } '' + ${palette-generator}/bin/palette-generator ${cfg.polarity} ${cfg.image} $out + ''; + palette = importJSON generatedJSON; + scheme = base16.mkSchemeAttrs palette; + json = scheme { + template = builtins.readFile ./palette.json.mustache; + extension = ".json"; + }; + in json; + generatedScheme = importJSON paletteJSON; override = (if cfg.base16Scheme == fromOs [ "base16Scheme" ] {} @@ -84,7 +86,7 @@ in { description = "The imported json"; readOnly = true; internal = true; - default = generatedPalette; + default = generatedScheme; }; }; @@ -124,5 +126,6 @@ in { # This attrset can be used like a function too, see # https://github.com/SenchoPens/base16.nix#mktheme lib.stylix.colors = (base16.mkSchemeAttrs cfg.base16Scheme).override override; + lib.stylix.scheme = base16.mkSchemeAttrs cfg.base16Scheme; }; }