Allow applying custom functions during evaluation

This commit is contained in:
Manuel Thalmann 2024-07-20 00:36:19 +02:00
parent 5700e2e69e
commit 77aaa5fe71
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
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