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 d1dc0b7
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 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
{
config,
pkgs,
...
}: let
cr = cell.__cr ++ [(baseNameOf src)];
file = "${self.outPath}#${lib.concatStringsSep "/" cr}";

i = args // {inherit cell inputs;};
defaultWith = import (haumea + /src/loaders/__defaultWith.nix) {inherit lib;};
loader = defaultWith (scopedImport i) i;
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;
args = {inherit cell inputs;};
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;
inputs = args;
})
# Mimic haumea for a regular file
else lib.setDefaultModuleLocation file (loader src);
else lib.setDefaultModuleLocation file (loader args src);

findLoad = {
inputs,
Expand Down

0 comments on commit d1dc0b7

Please sign in to comment.