refactor(read-tree): Keep traversing even if a default.nix is found

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.
This commit is contained in:
Vincent Ambo 2019-12-02 15:05:54 +00:00
parent 9d6792609f
commit d23716f354

View file

@ -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