diff --git a/examples/callFlake.nix b/examples/callFlake.nix index 77f3d27..0615acd 100644 --- a/examples/callFlake.nix +++ b/examples/callFlake.nix @@ -9,26 +9,17 @@ let in { a = - ((((flake.pops.default.setInitInputs ./__nixpkgsFlake).setSystem "x86_64-linux") + (((flake.pops.default.setInitInputs ./__nixpkgsFlake).setSystem "x86_64-linux") .addInputsExtender ( POP.lib.extendPop flake.pops.inputsExtender ( self: super: { inputs.nixlib = inputs.nixlib; - inputs.b = throw "should not be evaluated"; + # inputs.b = throw "should not be evaluated"; inputs.custom = self.inputs.nixlib; } ) ) - ).addInputsOverrideExtender - ( - POP.lib.extendPop flake.pops.inputsExtender ( - self: super: { overrideInputs.std = "s"; } - ) - ) ); - - b = self.a.addInputsExtender ( - POP.lib.extendPop flake.pops.inputsExtender (self: super: { inputs.b = "2"; }) - ); + b = self.a.addInputsExtender { inputs.b = "2"; }; } diff --git a/src/flake/pops.nix b/src/flake/pops.nix index a0bdfc6..da59303 100644 --- a/src/flake/pops.nix +++ b/src/flake/pops.nix @@ -152,7 +152,7 @@ in # defun # ( # with types; [ - # (list inputsExtenderPop) + # (either (list inputsExtenderPop) (list inputsExtender)) # flakePop # ] # ) @@ -164,14 +164,14 @@ in ); addInputsExtender = - # defun - # ( - # with types; [ - # (either inputsExtenderPop (attrs any)) - # flakePop - # ] - # ) - (inputsExtender: self.addInputsExtenders [ inputsExtender ]); + defun + ( + with types; [ + (either inputsExtender inputsExtenderPop) + flakePop + ] + ) + (inputsExtender: self.addInputsExtenders [ inputsExtender ]); addExporters = defun diff --git a/src/flake/structAttrs.nix b/src/flake/structAttrs.nix index 0ea8f35..8b061fd 100644 --- a/src/flake/structAttrs.nix +++ b/src/flake/structAttrs.nix @@ -23,16 +23,22 @@ let inputsExtenderPop = structAttrs.pop // { initInputs = attrs any; + initFlake = attrs any; + sysInputs = attrs any; inputs = attrs any; setInitInputs = function; }; + inputsExtender = { + inputs = attrs any; + }; + flakePop = structAttrs.exporterPop // structAttrs.inputsExtenderPop // { exporters = list types.exporterPop; - inputsExtenders = list types.inputsExtenderPop; + system = string; exports = attrs any; diff --git a/src/flake/types.nix b/src/flake/types.nix index c665f9f..4374154 100644 --- a/src/flake/types.nix +++ b/src/flake/types.nix @@ -1,7 +1,12 @@ -{ yants, root }: +{ yants, super }: with (yants "flops"); { - pop = openStruct root.flake.structAttrs.pop; - exporterPop = openStruct root.flake.structAttrs.exporterPop; - inputsExtenderPop = openStruct root.flake.structAttrs.inputsExtenderPop; - flakePop = openStruct root.flake.structAttrs.flakePop; + pop = openStruct super.structAttrs.pop; + exporterPop = openStruct super.structAttrs.exporterPop; + + inputsExtenderPop = + openStruct "inputsExtenderPop" + super.structAttrs.inputsExtenderPop; + inputsExtender = struct "inputsExtender" super.structAttrs.inputsExtender; + + flakePop = openStruct super.structAttrs.flakePop; } diff --git a/src/haumea/nixosModules.nix b/src/haumea/nixosModules.nix index 99a53a7..4ea0388 100644 --- a/src/haumea/nixosModules.nix +++ b/src/haumea/nixosModules.nix @@ -24,6 +24,7 @@ let (mapAttrs (name: _: inputs.${name})) f ]; + callModuleLazily = inputs: path: let @@ -31,6 +32,7 @@ let f = toFunction (importer path); in lazyArgsPerParameter f inputs; + removeFileSuffix = l.removeSuffix ".nix"; removeDefault = l.removeSuffix "/default"; relModulePathWithoutDefault = relModulePathWithoutDefault' removeDefault; @@ -43,6 +45,17 @@ let ) )); + isTopLevel = + path: + if + l.length (l.splitString "/" (l.last (l.splitString cfg.src (toString path)))) + == 2 + then + true + else + false + ; + base = { extender ? [ ], @@ -57,119 +70,115 @@ let ( let module = - { - config ? { }, - options ? { }, - ... - }@args: - let - mkModulePath = - attrs': l.setAttrByPath (relModulePathWithoutDefault path) attrs'; - test = config._module.args.pkgs or { }; - baseModuleArgs = - ( - inputs - // args - // ( - { + if (isTopLevel path) && cfg.type == "nixosProfilesOmnibus" then + callModuleLazily inputs path + else + { + config ? { }, + options ? { }, + ... + }@args: + let + mkModulePath = + attrs': l.setAttrByPath (relModulePathWithoutDefault path) attrs'; + test = config._module.args.pkgs or { }; + baseModuleArgs = + ( + inputs + // args + // ({ cfg = l.attrByPath (relModulePathWithoutDefault path) { } config; opt = l.attrByPath (relModulePathWithoutDefault path) { } options; inherit mkModulePath; moduleArgs = config._module.args // config._module.specialArgs; # override the self for the module self = inputs.self { }; - } - // - l.optionalAttrs - (l.elem cfg.type [ - "nixosModules" - "nixosProfiles" - ]) - { pkgs = config._module.args.pkgs; } - ) - ); + pkgs = config._module.args.pkgs; + }) + ); - moduleArgs = baseModuleArgs // { - loadSubmodule = path: (mkExtenders (callModuleLazily baseModuleArgs path) path); - }; + moduleArgs = baseModuleArgs // { + loadSubmodule = path: (mkExtender (callModuleLazily baseModuleArgs path) path); + }; - callArgsLazily = - attrs: extraArgs: - if (l.isFunction attrs) then - lazyArgsPerParameter attrs (moduleArgs // extraArgs) - else - attrs - ; + callArgsLazily = + attrs: extraArgs: + if (l.isFunction attrs) then + lazyArgsPerParameter attrs (moduleArgs // extraArgs) + else + attrs + ; - s3 = callModuleLazily moduleArgs path; - # => { config = { }; imports = [... ]; _file } - s3final = - let - s3Module = mkExtenders (winnow path s3 mkModulePath) path; - s3Profile = mkExtenders s3 path; - in - if isModule then s3Module else s3Profile; - - mkExtenders = - module: path: - let - removedOptionModule = removeAttrs module [ "options" ]; - filteredList = - l.filter - ( - item: - item.path == ( - if isModule then relModulePathWithoutDefault path else relModulePath path + mkExtender = + module: path: + let + removedOptionModule = removeAttrs module [ "options" ]; + filteredList = + l.filter + ( + item: + item.path == ( + if isModule then relModulePathWithoutDefault path else relModulePath path + ) ) - ) - extender; + extender; + + foundItem = + if (builtins.length filteredList) > 0 then + (builtins.head filteredList) + else + [ ] + ; - foundItem = - if (builtins.length filteredList) > 0 then - (builtins.head filteredList) - else - [ ] - ; + loadExtendModuleFromValue = + if foundItem != [ ] then + (callArgsLazily foundItem.value { + selfModule = module; + # add the options back in + # dmerge self' {} + selfModule' = x: module // (x removedOptionModule); + # add dmerge support + inherit dmerge; + }) + else + module + ; + in + loadExtendModuleFromValue; - loadExtendModuleFromValue = - if foundItem != [ ] then - (callArgsLazily foundItem.value { - selfModule = module; - # add the options back in - # dmerge self' {} - selfModule' = x: module // (x removedOptionModule); - # add dmerge support - inherit dmerge; - }) - else - module - ; - in - loadExtendModuleFromValue; + winnow = + path: module: fun: + ({ + config = + if module ? config then + module.config + else + fun ( + removeAttrs module [ + "options" + "imports" + ] + ) + ; + imports = module.imports or [ ]; + }) + // { + _file = path; + options = fun module.options or { }; + } + ; - winnow = - path: module: fun: - ({ - config = - if module ? config then - module.config - else - fun ( - removeAttrs module [ - "options" - "imports" - ] - ) - ; - imports = module.imports or [ ]; - }) - // { - _file = path; - options = fun module.options or { }; - } - ; - in - s3final; + callDefaultModule = callModuleLazily moduleArgs path; + # => { config = { }; imports = [... ]; _file } + finalModule = + let + extendedModule = mkExtender (winnow path callDefaultModule mkModulePath) path; + extendedProfile = mkExtender callDefaultModule path; + in + if isModule then extendedModule else extendedProfile; + in + finalModule + ; in module ) @@ -189,5 +198,3 @@ in default = base { }; __extender = extender: base { inherit extender; }; } -// l.optionalAttrs (cfg.type == "nixosModules") { nixosModules = base { }; } -// l.optionalAttrs (cfg.type == "nixosProfiles") { nixosProfiles = base { }; } diff --git a/src/haumea/pops.nix b/src/haumea/pops.nix index 9ac1f8c..0ed9d6a 100644 --- a/src/haumea/pops.nix +++ b/src/haumea/pops.nix @@ -226,6 +226,7 @@ let "nixosModules" "nixosProfiles" "evalModules" + "nixosProfilesOmnibus" ]) then nixosModules { inherit cfg; } diff --git a/src/haumea/structAttrs.nix b/src/haumea/structAttrs.nix index 25b0c6b..0fb2b3a 100644 --- a/src/haumea/structAttrs.nix +++ b/src/haumea/structAttrs.nix @@ -70,6 +70,7 @@ let "default" "nixosProfiles" "evalModules" + "nixosProfilesOmnibus" ] "type"; };