diff options
author | Vincent Ambo <tazjin@google.com> | 2019-12-10T14·46+0000 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-12-10T14·46+0000 |
commit | 050b3aabaf39fc8b1c949de1cdbd4353c9dfaf15 (patch) | |
tree | a86f94e1f76f15a00cb8cb6774324df3a30a830d | |
parent | c93130c8c3595c2d2563b0e22a3928eee80da7bd (diff) |
fix(read-tree): Only add marker to imported attribute sets r/121
Sometimes things that get imported are (intentionally) not attribute sets, e.g. for build functions. Those should not be merged with the marker because, well, that's not possible.
-rw-r--r-- | read-tree.nix | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/read-tree.nix b/read-tree.nix index a4c0e354ce72..2cdeb42aaafc 100644 --- a/read-tree.nix +++ b/read-tree.nix @@ -10,15 +10,20 @@ let listToAttrs map match + isAttrs readDir; argsWithPath = parts: args // { locatedAt = parts; }; - # The marker is added to everything that was imported directly by + # The marker is added to every set that was imported directly by # readTree. - marker = { __readTree = true; }; + importWithMark = path: parts: + let imported = import path (argsWithPath parts); + in if (isAttrs imported) + then imported // { __readTree = true; } + else imported; nixFileName = file: let res = match "(.*)\.nix" file; @@ -27,7 +32,7 @@ let readTree = path: parts: let dir = readDir path; - self = (import path (argsWithPath parts)) // marker; + self = importWithMark path parts; joinChild = c: path + ("/" + c); # Import non-empty subdirectories @@ -41,7 +46,7 @@ let nixFiles = filter (f: f != null) (map nixFileName (attrNames dir)); nixChildren = map (c: let p = joinChild (c + ".nix"); in { name = c; - value = (import p (argsWithPath (parts ++ [ c ]))) // marker; + value = importWithMark p (parts ++ [ c ]); }) nixFiles; in if dir ? "default.nix" then self // (listToAttrs children) |