refactor(readTree): Initialise repo roots without recursing
Plumbs an additional internal argument through readTree that indicates whether the top-level of a tree is being read, and avoids recursing into itself in that case. This changes the externally visible behaviour of readTree (it is now expected to be called a level higher than previously). This allows us to reduce the amount of boilerplate needed to bootstrap the TVL repository (by not having to specify the individual folders that need to be read). For reasons related to an infinite recursion we could not (be bothered to) debug, the top-level `config` key (which held the attribute set passed on by readTree) has been removed. This is not needed, as it is already passed on by readTree ... Co-Authored-By: Florian Klink <flokli@flokli.de> Change-Id: Id6e39b57b2f5b3473c4b695a72dd1d01fcfb7a66 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2961 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org> Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
parent
f59ab9aba5
commit
a559135970
3 changed files with 47 additions and 57 deletions
|
|
@ -65,12 +65,15 @@ let
|
|||
let res = match "(.*)\\.nix" file;
|
||||
in if res == null then null else head res;
|
||||
|
||||
readTree = args: initPath: parts:
|
||||
readTree = { args, initPath, rootDir, parts }:
|
||||
let
|
||||
dir = readDirVisible initPath;
|
||||
self = importWithMark args initPath parts;
|
||||
joinChild = c: initPath + ("/" + c);
|
||||
|
||||
self = if rootDir
|
||||
then { __readTree = []; }
|
||||
else importWithMark args initPath parts;
|
||||
|
||||
# Import subdirectories of the current one, unless the special
|
||||
# `.skip-subtree` file exists which makes readTree ignore the
|
||||
# children.
|
||||
|
|
@ -81,7 +84,12 @@ let
|
|||
filterDir = f: dir."${f}" == "directory";
|
||||
children = if hasAttr ".skip-subtree" dir then [] else map (c: {
|
||||
name = c;
|
||||
value = readTree args (joinChild c) (parts ++ [ c ]);
|
||||
value = readTree {
|
||||
args = args;
|
||||
initPath = (joinChild c);
|
||||
rootDir = false;
|
||||
parts = (parts ++ [ c ]);
|
||||
};
|
||||
}) (filter filterDir (attrNames dir));
|
||||
|
||||
# Import Nix files
|
||||
|
|
@ -95,5 +103,9 @@ let
|
|||
else (listToAttrs (nixChildren ++ children) // (marker parts));
|
||||
|
||||
in {
|
||||
__functor = _: args: initPath: readTree args initPath [ (baseNameOf initPath) ];
|
||||
__functor = _: args: initPath: readTree {
|
||||
inherit args initPath;
|
||||
rootDir = true;
|
||||
parts = [];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue