Skip to content

Commit

Permalink
refactor(haumea.nixosModules): add nixosModuleImporter allows users c…
Browse files Browse the repository at this point in the history
…an use custom loader
  • Loading branch information
GTrunSec committed Apr 22, 2024
1 parent 247a308 commit 4067970
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/haumea/importModule.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let
l = lib // builtins;
inherit (builtins) mapAttrs;
inherit (lib) functionArgs pipe toFunction;
# inherit (lib.modules) applyModuleArgsIfFunction;

isModule = l.elem cfg.type [
"nixosModules"
Expand All @@ -24,8 +25,6 @@ let
f
];

importModule = importer;

removeFileSuffix = l.removeSuffix ".nix";
removeDefault = l.removeSuffix "/default";
relModulePathWithoutDefault = relModulePathWithoutDefault' removeDefault;
Expand Down Expand Up @@ -55,7 +54,7 @@ in
let
module =
if (isTopLevel path) && cfg.type == "nixosProfilesOmnibus" then
importModule inputs path
importer inputs path
else
{
config ? { },
Expand All @@ -81,7 +80,7 @@ in
);

moduleArgs = baseModuleArgs // {
loadSubmodule = path: (mkExtender (importModule baseModuleArgs path) path);
loadSubmodule = path: (mkExtender (importer baseModuleArgs path) path);
};

mkExtender =
Expand All @@ -105,7 +104,7 @@ in
if (l.isFunction v) then
lazyArgsPerParameter v (moduleArgs // extraArgs)
else if (l.isPath v) then
importModule (moduleArgs // extraArgs) v
importer (moduleArgs // extraArgs) v
else
v;

Expand Down Expand Up @@ -144,7 +143,7 @@ in
options = fun module.options or { };
};

callDefaultModule = importModule moduleArgs path;
callDefaultModule = importer moduleArgs path;
# => { config = { }; imports = [... ]; _file }
finalModule =
let
Expand Down
2 changes: 1 addition & 1 deletion src/haumea/nixosModules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let
loader =
with haumea.lib;
(lib.optionals (initLoad.loader != haumea.lib.loaders.default) [
(matchers.nix (super.importModule cfg extender haumea.lib.loaders.scoped))
(matchers.nix (super.importModule cfg extender cfg.nixosModuleImporter))
])
++ (lib.optionals (lib.isList cfg.loader)) cfg.loader;
transformer =
Expand Down
5 changes: 4 additions & 1 deletion src/haumea/pops.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ let

loadExtender = pop {
defaults = {
initLoad = {
initLoad = rec {
src = ./.;
loader = haumea.lib.loaders.default;
inputs = { };
inputsTransformer = [ ];
transformer = [ ];
type = "default";
nixosModuleImporter = haumea.lib.loaders.scoped;
};
load = { };
};
Expand Down Expand Up @@ -65,6 +66,7 @@ let
transformer
type
inputsTransformer
nixosModuleImporter
;
src =
if l.isString load.src then l.unsafeDiscardStringContext load.src else load.src;
Expand Down Expand Up @@ -209,6 +211,7 @@ let
l.removeAttrs cfg [
"type"
"inputsTransformer"
"nixosModuleImporter"
]
);
};
Expand Down
1 change: 1 addition & 0 deletions src/haumea/structAttrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ let
"evalModules"
"nixosProfilesOmnibus"
] "type";
nixosModuleImporter = function;
};

haumeaLoadExtender = {
Expand Down

0 comments on commit 4067970

Please sign in to comment.