Skip to content

Commit

Permalink
feat: use a custom loader for haumea
Browse files Browse the repository at this point in the history
This patch replaces the scoped loader used in `load` with a custom
version that can resolve module arguments as well.
  • Loading branch information
korrat committed Mar 15, 2024
1 parent a976da4 commit dfa2fe1
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,51 @@
src,
}:
# modules/profiles are always functions
args @ {pkgs, ...}: let
args @ {
config,
pkgs,
...
}: let
cr = cell.__cr ++ [(baseNameOf src)];
file = "${self.outPath}#${lib.concatStringsSep "/" cr}";

defaultWith = let
inherit
(lib)
functionArgs
pipe
toFunction
;
in (importer: inputs: path: let
f = toFunction (importer path);
in
pipe f [
functionArgs
(let
context = name: ''while evaluating the argument `${name}' in "${file}":'';
in
builtins.mapAttrs (
name: _:
builtins.addErrorContext (context name)
(inputs.${name} or config._module.args.${name})
))
f
]);
loader = inputs: defaultWith (scopedImport inputs) inputs;
i = args // {inherit cell inputs;};
defaultWith = import (haumea + /src/loaders/__defaultWith.nix) {inherit lib;};
loader = defaultWith (scopedImport i) i;
in
if lib.pathIsDirectory src
then
lib.setDefaultModuleLocation file (haumea.lib.load {
inherit src;
loader = haumea.lib.loaders.scoped;
inherit loader src;
transformer = with haumea.lib.transformers; [
liftDefault
(hoistLists "_imports" "imports")
];
inputs = i;
})
# Mimic haumea for a regular file
else lib.setDefaultModuleLocation file (loader src);
else lib.setDefaultModuleLocation file (loader i src);

findLoad = {
inputs,
Expand Down

0 comments on commit dfa2fe1

Please sign in to comment.