diff --git a/flake/flake-modules/auto.nix b/flake/flake-modules/auto.nix new file mode 100644 index 00000000..2d6f2100 --- /dev/null +++ b/flake/flake-modules/auto.nix @@ -0,0 +1,62 @@ +{ lib, config, ... }: +let + cfg = config.nixvim; +in +{ + options.nixvim = { + packages = { + enable = lib.mkEnableOption "automatically installing packages for each nixvimConfigurations"; + nameFunction = lib.mkOption { + type = lib.types.functionTo lib.types.str; + description = '' + A function to convert a nixvimConfiguration's name into a package name. + + **Type** + + ``` + String -> String + ``` + ''; + default = name: "nixvim-" + name; + defaultText = lib.literalExpression ''name: "nixvim-" + name''; + example = lib.literalExpression ''name: name + "-nvim"''; + }; + }; + checks = { + enable = lib.mkEnableOption "automatically installing checks for each nixvimConfigurations"; + nameFunction = lib.mkOption { + type = lib.types.functionTo lib.types.str; + description = '' + A function to convert a nixvimConfiguration's name into a check name. + + **Type** + + ``` + String -> String + ``` + ''; + default = name: "nixvim-" + name; + defaultText = lib.literalExpression ''name: "nixvim-" + name''; + example = lib.literalExpression ''name: "nixvim-" + name + "-test"''; + }; + }; + }; + config = { + perSystem = + { config, ... }: + { + packages = lib.mkIf cfg.packages.enable ( + lib.mapAttrs' (name: configuration: { + name = cfg.packages.nameFunction name; + value = configuration.config.build.package; + }) config.nixvimConfigurations + ); + checks = lib.mkIf cfg.checks.enable ( + lib.mapAttrs' (name: configuration: { + name = cfg.checks.nameFunction name; + value = configuration.config.build.test; + }) config.nixvimConfigurations + ); + }; + }; +} diff --git a/flake/flake-modules/default.nix b/flake/flake-modules/default.nix index 736b482b..2f996ffa 100644 --- a/flake/flake-modules/default.nix +++ b/flake/flake-modules/default.nix @@ -4,6 +4,7 @@ let defaultModules = { nixvimModules = ./nixvimModules.nix; nixvimConfigurations = ./nixvimConfigurations.nix; + auto = ./auto.nix; }; # Modules for the flakeModules output, but not the default module