diff options
author | Vincent Ambo <tazjin@google.com> | 2019-12-02T15·05+0000 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-12-02T15·05+0000 |
commit | d23716f3543c35a0b672a5b508f7e3afc39c0aa0 (patch) | |
tree | 1a8672d3e4347b51f33046474ef023a996346c7f /read-tree.nix | |
parent | 9d6792609f0de0c3c9209f300756024f8c3524da (diff) |
refactor(read-tree): Keep traversing even if a default.nix is found r/97
This makes it possible for people to drop a default.nix into folders along the way that add additional things into the attribute set at that level. These default.nix files are imported and merged with the rest of the traversal from that point on. In theory nothing stops a user from putting a derivation into one of them, but the effects of merging that derivation's underlying attribute set with random other things from the traversal are undefined. This feature is being introduced for a slight revamp of the thirdParty layout.
Diffstat (limited to 'read-tree.nix')
-rw-r--r-- | read-tree.nix | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/read-tree.nix b/read-tree.nix index d742c69ea411..6f900a0667db 100644 --- a/read-tree.nix +++ b/read-tree.nix @@ -31,7 +31,7 @@ let in if res == null then null else head res; filterNixFiles = dir: - let files = filter (e: isFile e.value) dir; + let files = filter (e: isFile e.value && e.name != "default.nix") dir; nixFiles = map (f: { # Name and value are intentionally flipped to get the # correct attribute set structure back out @@ -70,9 +70,10 @@ let in listToAttrs (imported ++ dirs); importOr = path: dir: f: - if dir ? "default.nix" - then import path (argsWithPath args (pathParts path)) - else f path (attrsToList dir); + let contents = f path (attrsToList dir); + in if dir ? "default.nix" + then import path (argsWithPath args (pathParts path)) // contents + else contents; readTree = path: importOr path (readDir path) traverse; in readTree initPath |