about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--default.nix81
-rw-r--r--nix/readTree/README.md3
-rw-r--r--nix/readTree/default.nix20
3 files changed, 47 insertions, 57 deletions
diff --git a/default.nix b/default.nix
index c5db0d1e321a..a73e46877ab1 100644
--- a/default.nix
+++ b/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))
-)
+})
diff --git a/nix/readTree/README.md b/nix/readTree/README.md
index c93cf2bfdd61..138abbe30583 100644
--- a/nix/readTree/README.md
+++ b/nix/readTree/README.md
@@ -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
diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix
index 1f0de59e1ecc..4d5385921ee2 100644
--- a/nix/readTree/default.nix
+++ b/nix/readTree/default.nix
@@ -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 = [];
+  };
 }