Allow applying custom functions during evaluation

This commit is contained in:
Manuel Thalmann 2024-07-20 00:36:19 +02:00
parent 2848e5b52c
commit 5fa9f49b58
2 changed files with 23 additions and 2 deletions

16
lib/eval-module.nix Normal file
View 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

View file

@ -6,6 +6,11 @@ function evalModule --argument-names modulePath property
set -a argv --raw set -a argv --raw
end end
set -l nixPkgs 'import <nixpkgs> { config = {}; overlay = []; }' FILE=(realpath "$modulePath") \
nix eval --file "$modulePath" --apply "_: (($nixPkgs).lib.evalModules { modules = [ _ ]; }).config.$property" $argv PROPERTY="$property" \
nix eval \
--file "$(status dirname)/../../../lib/eval-module.nix" \
$argv
end end
evalModule $argv