diff --git a/README.md b/README.md index 2e64243..aa0f0e1 100644 --- a/README.md +++ b/README.md @@ -165,9 +165,10 @@ in { } ``` -This flake also provides a NixOS/Home Manager module, which can be imported by +This flake also provides a Home Manager module, which can be imported by adding this in your configuration: ```nix +# home.nix {pkgs, inputs, ...}: { imports = [ inputs.matugen.nixosModules.default @@ -177,12 +178,6 @@ adding this in your configuration: } ``` -The module does NOT automatically symlink the files. For an example of using this module with Home Manager, see https://github.com/InioX/matugen/issues/28 - -Option details can be found by reading the [module](./module.nix). A -[search.nixos.org](https://search.nixos.org/options)-like option viewer is -planned. -

diff --git a/flake.lock b/flake.lock index bb2002b..746e55d 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1691186842, - "narHash": "sha256-wxBVCvZUwq+XS4N4t9NqsHV4E64cPVqQ2fdDISpjcw0=", + "lastModified": 1716330097, + "narHash": "sha256-8BO3B7e3BiyIDsaKA0tY8O88rClYRTjvAp66y+VBUeU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "18036c0be90f4e308ae3ebcab0e14aae0336fe42", + "rev": "5710852ba686cc1fd0d3b8e22b3117d43ba374c2", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 6456e56..d9c249f 100644 --- a/flake.nix +++ b/flake.nix @@ -4,20 +4,26 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; systems.url = "github:nix-systems/default-linux"; }; - outputs = { self, nixpkgs, systems }: + outputs = + { + self, + nixpkgs, + systems, + }: let forAllSystems = nixpkgs.lib.genAttrs (import systems); pkgsFor = nixpkgs.legacyPackages; - in { + in + { packages = forAllSystems (system: { default = pkgsFor.${system}.callPackage ./. { }; }); devShells = forAllSystems (system: { default = pkgsFor.${system}.callPackage ./shell.nix { }; }); - nixosModules = { - matugen = import ./module.nix self; - default = self.nixosModules.matugen; + homeManagerModules = rec { + matugen = import ./hm-module.nix self; + default = matugen; }; }; } diff --git a/hm-module.nix b/hm-module.nix new file mode 100644 index 0000000..07c30e0 --- /dev/null +++ b/hm-module.nix @@ -0,0 +1,24 @@ +self: +{ + config, + pkgs, + lib, + ... +}: +let + cfg = config.programs.matugen; +in +{ + options.programs.matugen = { + enable = lib.mkEnableOption "matugen"; + package = lib.mkPackageOption pkgs "matugen" { }; + settings = lib.mkOption { type = lib.types.attrs; }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + xdg.configFile."matugen/config.toml".source = lib.mkIf (cfg.settings != null) ( + (pkgs.formats.toml { }).generate "matugen" cfg.settings + ); + }; +} diff --git a/module.nix b/module.nix deleted file mode 100644 index 212becb..0000000 --- a/module.nix +++ /dev/null @@ -1,139 +0,0 @@ -# this arg is the matugen flake input -matugen: { - pkgs, - lib, - config, - ... -} @ args: let - cfg = config.programs.matugen; - osCfg = args.osConfig.programs.matugen or {}; - - configFormat = pkgs.formats.toml {}; - - capitalize = str: let - inherit (builtins) substring stringLength; - firstChar = substring 0 1 str; - restOfString = substring 1 (stringLength str) str; - in - lib.concatStrings [(lib.toUpper firstChar) restOfString]; - - # don't use ~, use $HOME - sanitizedTemplates = - builtins.mapAttrs (_: v: { - mode = capitalize cfg.variant; - input_path = builtins.toString v.input_path; - output_path = builtins.replaceStrings ["$HOME"] ["~"] v.output_path; - }) - cfg.templates; - - matugenConfig = configFormat.generate "matugen-config.toml" { - config = {}; - templates = sanitizedTemplates; - }; - - # get matugen package - pkg = matugen.packages.${pkgs.system}.default; - - themePackage = pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} '' - mkdir -p $out - cd $out - export HOME=$(pwd) - - ${pkg}/bin/matugen \ - image ${cfg.wallpaper} \ - ${ - if cfg.templates != {} - then "--config ${matugenConfig}" - else "" - } \ - --mode ${cfg.variant} \ - --type ${cfg.type} \ - --json ${cfg.jsonFormat} \ - --quiet \ - > $out/theme.json - ''; - colors = builtins.fromJSON (builtins.readFile "${themePackage}/theme.json"); -in { - options.programs.matugen = { - enable = lib.mkEnableOption "Matugen declarative theming"; - - wallpaper = lib.mkOption { - description = "Path to `wallpaper` that matugen will generate the colorschemes from"; - type = lib.types.path; - default = osCfg.wallpaper or "${pkgs.nixos-artwork.wallpapers.simple-blue}/share/backgrounds/nixos/nix-wallpaper-simple-blue.png"; - defaultText = lib.literalExample '' - "${pkgs.nixos-artwork.wallpapers.simple-blue}/share/backgrounds/nixos/nix-wallpaper-simple-blue.png" - ''; - }; - - templates = lib.mkOption { - type = with lib.types; - attrsOf (submodule { - options = { - input_path = lib.mkOption { - type = path; - description = "Path to the template"; - example = "./style.css"; - }; - output_path = lib.mkOption { - type = str; - description = "Path where the generated file will be written to"; - example = "~/.config/sytle.css"; - }; - }; - }); - default = osCfg.templates or {}; - description = '' - Templates that have `@{placeholders}` which will be replaced by the respective colors. - See for a list of colors. - ''; - }; - - type = lib.mkOption { - description = "Palette used when generating the colorschemes."; - type = lib.types.enum ["scheme-content" "scheme-expressive" "scheme-fidelity" "scheme-fruit-salad" "scheme-monochrome" "scheme-neutral" "scheme-rainbow" "scheme-tonal-spot"]; - default = osCfg.palette or "scheme-tonal-spot"; - example = "triadic"; - }; - - jsonFormat = lib.mkOption { - description = "Color format of the colorschemes."; - type = lib.types.enum ["rgb" "rgba" "hsl" "hsla" "hex" "strip"]; - default = osCfg.jsonFormat or "strip"; - example = "rgba"; - }; - - variant = lib.mkOption { - description = "Colorscheme variant."; - type = lib.types.enum ["light" "dark" "amoled"]; - default = osCfg.variant or "dark"; - example = "light"; - }; - - theme.files = lib.mkOption { - type = lib.types.package; - readOnly = true; - default = - if builtins.hasAttr "templates" osCfg - then - if cfg.templates != osCfg.templates - then themePackage - else osCfg.theme.files - else themePackage; - description = "Generated theme files. Including only the variant chosen."; - }; - - theme.colors = lib.mkOption { - inherit (pkgs.formats.json {}) type; - readOnly = true; - default = - if builtins.hasAttr "templates" osCfg - then - if cfg.templates != osCfg.templates - then colors - else osCfg.theme.colors - else colors; - description = "Generated theme colors. Includes all variants."; - }; - }; -}