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
81
default.nix
81
default.nix
|
@ -1,53 +1,21 @@
|
|||
# This file sets up the top-level package set by traversing the package tree
|
||||
# (see read-tree.nix for details) and constructing a matching attribute set
|
||||
# (see //nix/readTree for details) and constructing a matching attribute set
|
||||
# tree.
|
||||
#
|
||||
# This makes packages accessible via the Nixery instance that is configured to
|
||||
# use this repository as its nixpkgs source.
|
||||
|
||||
{ nixpkgsBisectPath ? null, ... }@args:
|
||||
|
||||
with builtins;
|
||||
|
||||
let
|
||||
inherit (builtins)
|
||||
attrValues
|
||||
concatMap
|
||||
filter
|
||||
;
|
||||
|
||||
# This definition of fix is identical to <nixpkgs>.lib.fix, but the global
|
||||
# package set is not available here.
|
||||
fix = f: let x = f x; in x;
|
||||
|
||||
# Global configuration that all packages are called with.
|
||||
config = depot: {
|
||||
inherit depot;
|
||||
|
||||
# Expose lib attribute to packages.
|
||||
inherit (depot.third_party.nixpkgs) lib;
|
||||
|
||||
# Pass third_party as 'pkgs' (for compatibility with external
|
||||
# imports for certain subdirectories)
|
||||
pkgs = depot.third_party.nixpkgs;
|
||||
|
||||
# Pass arguments passed to the entire depot through, for packages
|
||||
# that would like to add functionality based on this.
|
||||
#
|
||||
# Note that it is intended for exceptional circumstance, such as
|
||||
# debugging by bisecting nixpkgs.
|
||||
externalArgs = args;
|
||||
};
|
||||
|
||||
readTree' = import ./nix/readTree {};
|
||||
|
||||
localPkgs = readTree: {
|
||||
fun = readTree ./fun;
|
||||
lisp = readTree ./lisp;
|
||||
net = readTree ./net;
|
||||
nix = readTree ./nix;
|
||||
ops = readTree ./ops;
|
||||
third_party = readTree ./third_party;
|
||||
tools = readTree ./tools;
|
||||
tvix = readTree ./tvix;
|
||||
users = readTree ./users;
|
||||
web = readTree ./web;
|
||||
};
|
||||
|
||||
# To determine build targets, we walk through the depot tree and
|
||||
# fetch attributes that were imported by readTree and are buildable.
|
||||
#
|
||||
|
@ -78,19 +46,30 @@ let
|
|||
})
|
||||
(node.meta.targets or []))
|
||||
else [];
|
||||
in fix(self: {
|
||||
__readTree = [];
|
||||
config = config self;
|
||||
|
||||
# Expose readTree for downstream repo consumers.
|
||||
readTree = {
|
||||
__functor = x: (readTree' x.config);
|
||||
config = self.config;
|
||||
};
|
||||
|
||||
# Make the path to the depot available for things that might need it
|
||||
# (e.g. NixOS module inclusions)
|
||||
depotPath = ./.;
|
||||
in fix(self: (readTree' {
|
||||
# TODO(tazjin): Settle on one way of using depotPath
|
||||
inherit depotPath;
|
||||
depot = self;
|
||||
|
||||
# Pass third_party as 'pkgs' (for compatibility with external
|
||||
# imports for certain subdirectories)
|
||||
pkgs = self.third_party.nixpkgs;
|
||||
|
||||
# Expose lib attribute to packages.
|
||||
lib = self.third_party.nixpkgs.lib;
|
||||
|
||||
# Pass arguments passed to the entire depot through, for packages
|
||||
# that would like to add functionality based on this.
|
||||
#
|
||||
# Note that it is intended for exceptional circumstance, such as
|
||||
# debugging by bisecting nixpkgs.
|
||||
externalArgs = args;
|
||||
} ./.) // {
|
||||
inherit depotPath;
|
||||
|
||||
# List of all buildable targets, for CI purposes.
|
||||
#
|
||||
|
@ -111,8 +90,4 @@ in fix(self: {
|
|||
name = "depot-gcroot";
|
||||
paths = self.ci.targets;
|
||||
};
|
||||
}
|
||||
|
||||
# Add local packages as structured by readTree
|
||||
// (localPkgs (readTree' self.config))
|
||||
)
|
||||
})
|
||||
|
|
|
@ -60,6 +60,9 @@ with some exceptions:
|
|||
* If a folder contains a `default.nix` it is loaded and, if it evaluates to a
|
||||
set, *merged* with the children. If it evaluates to anything else the children
|
||||
are *not traversed*.
|
||||
* The `default.nix` of the top-level folder on which readTree is
|
||||
called is **not** read to avoid infinite recursion (as, presumably,
|
||||
this file is where readTree itself is called).
|
||||
|
||||
Traversal is lazy, `readTree` will only build up the tree as requested. This
|
||||
currently has the downside that directories with no importable files end up in
|
||||
|
|
|
@ -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…
Reference in a new issue