Allow applying custom functions during evaluation
This commit is contained in:
parent
2848e5b52c
commit
5fa9f49b58
16
lib/eval-module.nix
Normal file
16
lib/eval-module.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
let
|
||||
inherit (nixpkgs) lib;
|
||||
nixpkgs = import <nixpkgs> { config = {}; overlay = []; };
|
||||
file = (builtins.getEnv "FILE");
|
||||
property = (builtins.getEnv "PROPERTY");
|
||||
processor = if (builtins.stringLength property > 0)
|
||||
then
|
||||
(_: lib.attrsets.getAttrFromPath (lib.strings.splitString "." property) _)
|
||||
else
|
||||
(_: _);
|
||||
in
|
||||
processor (lib.evalModules {
|
||||
modules = [
|
||||
(import file)
|
||||
];
|
||||
}).config
|
|
@ -6,6 +6,11 @@ function evalModule --argument-names modulePath property
|
|||
set -a argv --raw
|
||||
end
|
||||
|
||||
set -l nixPkgs 'import <nixpkgs> { config = {}; overlay = []; }'
|
||||
nix eval --file "$modulePath" --apply "_: (($nixPkgs).lib.evalModules { modules = [ _ ]; }).config.$property" $argv
|
||||
FILE=(realpath "$modulePath") \
|
||||
PROPERTY="$property" \
|
||||
nix eval \
|
||||
--file "$(status dirname)/../../../lib/eval-module.nix" \
|
||||
$argv
|
||||
end
|
||||
|
||||
evalModule $argv
|
||||
|
|
Loading…
Reference in a new issue