90 lines
2.3 KiB
Nix
90 lines
2.3 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
cfg = config.programs.matugen;
|
|
|
|
sanitizedTemplates = builtins.mapAttrs (_: v: {
|
|
input_path = v.source;
|
|
output_path = builtins.replaceStrings ["$HOME"] ["~"] v.destination;
|
|
}) cfg.templates;
|
|
|
|
configFormat = pkgs.formats.toml {};
|
|
matugenConfig = configFormat.generate "matugen-config.toml" {
|
|
config = {};
|
|
templates = sanitizedTemplates;
|
|
};
|
|
|
|
themePackage = pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} ''
|
|
mkdir -p $out
|
|
cd $out
|
|
export HOME=$(pwd)
|
|
|
|
# Ok so the problem here is that /etc/ is not 'mounted' in the build environment.
|
|
# So yeah :D
|
|
|
|
${cfg.pkg}/bin/matugen \
|
|
image ${cfg.wallpaper} \
|
|
--config ${matugenConfig} \
|
|
--mode ${cfg.variant} \
|
|
--json hex \
|
|
--quiet \
|
|
> $out/theme.json
|
|
'';
|
|
|
|
colorsFile = builtins.fromJSON (builtins.readFile "${themePackage}/theme.json");
|
|
colors = colorsFile.colors.${cfg.variant};
|
|
|
|
in
|
|
{
|
|
options.programs.matugen = {
|
|
enable = lib.mkEnableOption "Matugen declarative theming";
|
|
|
|
wallpaper = lib.mkOption {
|
|
description = "Path to `wallpaper` that matugen will generate colors from";
|
|
type = lib.types.path;
|
|
};
|
|
|
|
variant = lib.mkOption {
|
|
description = "";
|
|
type = lib.types.enum [ "light" "dark" ];
|
|
default = "dark";
|
|
example = "light";
|
|
};
|
|
|
|
pkg = lib.mkPackageOption pkgs "matugen" {};
|
|
|
|
templates = lib.mkOption {
|
|
description = "Templates to generate output with.";
|
|
type = with lib.types;
|
|
attrsOf (submodule {
|
|
options = {
|
|
source = lib.mkOption {
|
|
type = path;
|
|
description = "Path to the source template";
|
|
example = "./gtk.css";
|
|
};
|
|
destination = lib.mkOption {
|
|
type = str;
|
|
description = "Destination path";
|
|
example = "gtk.css";
|
|
};
|
|
};
|
|
});
|
|
default = {};
|
|
};
|
|
|
|
theme.files = lib.mkOption {
|
|
description = "Generated theme files. Includes chosen variant only.";
|
|
type = lib.types.package;
|
|
readOnly = true;
|
|
default = themePackage;
|
|
};
|
|
|
|
theme.colors = lib.mkOption {
|
|
inherit (pkgs.formats.json {}) type;
|
|
description = "Generated theme colors";
|
|
readOnly = true;
|
|
default = colors;
|
|
};
|
|
};
|
|
}
|