diff --git a/lib.nix b/lib.nix index 5f84901..f2b229e 100644 --- a/lib.nix +++ b/lib.nix @@ -3,6 +3,7 @@ let inherit (lib) mkOption types + functionTo ; flake-modules-core-lib = { @@ -26,6 +27,20 @@ let modules = [ { inherit options; } ]; }; }; + + mkPerSystemType = + module: + types.functionTo (types.submoduleWith { + modules = [ module ]; + shorthandOnlyDefinesConfig = false; + }); + + mkPerSystemModule = + module: + mkOption { + type = flake-modules-core-lib.mkPerSystemType module; + }; + }; in diff --git a/modules/perSystem.nix b/modules/perSystem.nix index e70f5f6..b5e2cab 100644 --- a/modules/perSystem.nix +++ b/modules/perSystem.nix @@ -1,4 +1,4 @@ -{ config, lib, self, ... }: +{ config, lib, flake-modules-core-lib, self, ... }: let inherit (lib) genAttrs @@ -6,6 +6,9 @@ let mkOption types ; + inherit (flake-modules-core-lib) + mkPerSystemType + ; rootConfig = config; @@ -23,18 +26,13 @@ in }; perSystem = mkOption { - description = "A function from system to flake-like attributes omitting the attribute."; - type = types.functionTo (types.submoduleWith { - modules = [ - ({ config, system, ... }: { - _file = ./perSystem.nix; - config = { - _module.args.inputs' = mapAttrs (k: rootConfig.perInput system) self.inputs; - _module.args.self' = rootConfig.perInput system self; - }; - }) - ]; - shorthandOnlyDefinesConfig = false; + description = "A function from system to flake-like attributes omitting the <system> attribute."; + type = mkPerSystemType ({ config, system, ... }: { + _file = ./perSystem.nix; + config = { + _module.args.inputs' = mapAttrs (k: rootConfig.perInput system) self.inputs; + _module.args.self' = rootConfig.perInput system self; + }; }); };