feat(readTree): Use tree location as the value of __readTree

Change-Id: I6a087279b5d819db475f2179cb77c0f55cbd0ac6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1860
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: lukegb <lukegb@tvl.fyi>
This commit is contained in:
Vincent Ambo 2020-08-27 01:50:33 +01:00 committed by tazjin
parent 9b4986c5ed
commit 29613e7494

View file

@ -6,6 +6,7 @@ let
inherit (builtins) inherit (builtins)
attrNames attrNames
baseNameOf baseNameOf
concatStringsSep
filter filter
hasAttr hasAttr
head head
@ -31,12 +32,17 @@ let
value = children.${name}; value = children.${name};
}) names); }) names);
# Create a mark containing the location of this attribute.
marker = parts: {
__readTree = parts;
};
# The marker is added to every set that was imported directly by # The marker is added to every set that was imported directly by
# readTree. # readTree.
importWithMark = path: parts: importWithMark = path: parts:
let imported = import path (argsWithPath parts); let imported = import path (argsWithPath parts);
in if (isAttrs imported) in if (isAttrs imported)
then imported // { __readTree = true; } then imported // (marker parts)
else imported; else imported;
nixFileName = file: nixFileName = file:
@ -70,5 +76,5 @@ let
}) nixFiles; }) nixFiles;
in if dir ? "default.nix" in if dir ? "default.nix"
then (if isAttrs self then self // (listToAttrs children) else self) then (if isAttrs self then self // (listToAttrs children) else self)
else (listToAttrs (nixChildren ++ children) // { __readTree = true; }); else (listToAttrs (nixChildren ++ children) // (marker parts));
in readTree initPath [ (baseNameOf initPath) ] in readTree initPath [ (baseNameOf initPath) ]