From 5fa9f49b5852acc9bc4bfe94252fee285aa150ea Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 20 Jul 2024 00:36:19 +0200 Subject: [PATCH] Allow applying custom functions during evaluation --- lib/eval-module.nix | 16 ++++++++++++++++ scripts/Common/Scripts/eval-module.fish | 9 +++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 lib/eval-module.nix diff --git a/lib/eval-module.nix b/lib/eval-module.nix new file mode 100644 index 00000000..61c9abd1 --- /dev/null +++ b/lib/eval-module.nix @@ -0,0 +1,16 @@ +let + inherit (nixpkgs) lib; + nixpkgs = import { 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 diff --git a/scripts/Common/Scripts/eval-module.fish b/scripts/Common/Scripts/eval-module.fish index 534747c9..1d4a4fe4 100644 --- a/scripts/Common/Scripts/eval-module.fish +++ b/scripts/Common/Scripts/eval-module.fish @@ -6,6 +6,11 @@ function evalModule --argument-names modulePath property set -a argv --raw end - set -l nixPkgs 'import { 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