From abba4b52c890774d8c82cc565e4739d16abf8947 Mon Sep 17 00:00:00 2001 From: guangtao Date: Thu, 7 Dec 2023 22:56:31 -0800 Subject: [PATCH] refactor(pops/haumea): enhace loadExtendedModule --- src/haumea/nixosModules.nix | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/haumea/nixosModules.nix b/src/haumea/nixosModules.nix index 4ea0388..3951640 100644 --- a/src/haumea/nixosModules.nix +++ b/src/haumea/nixosModules.nix @@ -33,6 +33,13 @@ let in lazyArgsPerParameter f inputs; + callModuleLazily' = + inputs: path: importer: + let + f = toFunction (importer path); + in + lazyArgsPerParameter f inputs; + removeFileSuffix = l.removeSuffix ".nix"; removeDefault = l.removeSuffix "/default"; relModulePathWithoutDefault = relModulePathWithoutDefault' removeDefault; @@ -101,14 +108,6 @@ let loadSubmodule = path: (mkExtender (callModuleLazily baseModuleArgs path) path); }; - callArgsLazily = - attrs: extraArgs: - if (l.isFunction attrs) then - lazyArgsPerParameter attrs (moduleArgs // extraArgs) - else - attrs - ; - mkExtender = module: path: let @@ -130,9 +129,19 @@ let [ ] ; + callValueModuleLazily = + v: extraArgs: + if (l.isFunction v) then + lazyArgsPerParameter v (moduleArgs // extraArgs) + else if (l.isPath v) then + callModuleLazily' (moduleArgs // extraArgs) v import + else + v + ; + loadExtendModuleFromValue = if foundItem != [ ] then - (callArgsLazily foundItem.value { + (callValueModuleLazily foundItem.value { selfModule = module; # add the options back in # dmerge self' {}