Skip to content

Commit 3ab0c3f

Browse files
committed
misc work, display only the correct by-name directory when erroring
1 parent d294972 commit 3ab0c3f

File tree

17 files changed

+487
-426
lines changed

17 files changed

+487
-426
lines changed

by-name-config.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# In the attrsets that make up by_name_dirs:
55
# * The aliases_path field is optional.
66
# * The ID field must be short and unique.
7-
# * At most one attr_path_regex may be a wildcard.
7+
# * Exactly one attr_path_regex must be a wildcard ("[^\\.]*").
88
# * All non-wildcard attr_path_regexes must be mutually exclusive.
9-
# * At most one unversioned_attr_prefix may be the empty string.
9+
# * Exactly one unversioned_attr_prefix must be the empty string.
1010
# * All non-wildcard unversioned_attr_prefixes must be mutually exclusive.
1111
{
1212
by_name_dirs = [
@@ -29,7 +29,7 @@
2929
{
3030
id = "main";
3131
path = "pkgs/by-name";
32-
attr_path_regex = ".*";
32+
attr_path_regex = "[^\\.]*";
3333
unversioned_attr_prefix = "";
3434
all_packages_path = "/pkgs/top-level/all-packages.nix";
3535
aliases_path = "/pkgs/top-level/aliases.nix";

src/eval.nix

Lines changed: 75 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@
99
}:
1010
let
1111
# attrs = builtins.fromJSON (builtins.readFile attrsPath);
12-
rawAttrs = builtins.trace "rawAttrs = ${(builtins.toJSON (builtins.fromJSON (builtins.readFile attrsPath)))}" (builtins.fromJSON (builtins.readFile attrsPath));
12+
rawAttrs = builtins.trace "rawAttrs = ${(builtins.toJSON (builtins.fromJSON (builtins.readFile attrsPath)))}" (
13+
builtins.fromJSON (builtins.readFile attrsPath)
14+
);
1315
# an attrset where the key is the ID field from by-name-config.nix and the value is a list of attr paths.
14-
attrsByDir = builtins.trace "attrsByDir = ${(builtins.toJSON (builtins.groupBy (a: a.by_name_dir_id) rawAttrs))}" (builtins.groupBy (a: a.by_name_dir_id) rawAttrs);
15-
allAttrPaths = map (a: a.attr_path) rawAttrs;
16+
attrsByDir = builtins.trace "attrsByDir = ${
17+
(builtins.toJSON (builtins.groupBy (a: a.by_name_dir_id) rawAttrs))
18+
}" (builtins.groupBy (a: a.by_name_dir_id) rawAttrs);
19+
20+
# TODO: make this name accurate
21+
allAttrPaths = builtins.trace "allAttrPaths = ${builtins.toJSON (map (a: a.attr_path) rawAttrs)}" (
22+
map (a: a.attr_path) rawAttrs
23+
);
1624
byNameConfig = builtins.fromJSON (builtins.readFile configPath);
1725
# We need to check whether attributes are defined manually e.g. in `all-packages.nix`,
1826
# automatically by the `pkgs/by-name` overlay, or neither. The only way to do so is to override
@@ -62,7 +70,9 @@ let
6270
# We check evaluation and `callPackage` only for x86_64-linux. Not ideal, but hard to fix.
6371
system = "x86_64-linux";
6472
}
65-
// { inherit byNameConfig; }
73+
// {
74+
inherit byNameConfig;
75+
}
6676
);
6777

6878
# See AttributeInfo in ./eval.rs for the meaning of this.
@@ -82,7 +92,7 @@ let
8292
# location = builtins.unsafeGetAttrPos (builtins.trace "eval.nix:84: pname = ${pname}" pname) parent;
8393
location = builtins.unsafeGetAttrPos pname parent;
8494
attribute_variant = (
85-
if !builtins.isAttrs value then
95+
if (builtins.trace "path ${builtins.toJSON attrPath}; isAttrs: ${pkgs.lib.boolToString (builtins.isAttrs value)}; (value ? \"_callPackageVariant\") = ${pkgs.lib.boolToString (value ? "_callPackageVariant")}" (!(builtins.isAttrs value))) then
8696
{ NonAttributeSet = null; }
8797
else
8898
{
@@ -99,40 +109,48 @@ let
99109
};
100110

101111
# Information on all attributes that are in a `by-name` directory.
102-
byNameAttrsForDir = byNameDir: pkgs.lib.mergeAttrsList (
103-
map (
104-
package:
105-
let
106-
# attrPath = builtins.trace "eval.nix:106: name = ${name}" (pkgs.lib.splitString "." name);
107-
attrPath = pkgs.lib.splitString "." package.attr_path;
108-
result = pkgs.lib.setAttrByPath attrPath {
109-
ByName =
110-
if !(pkgs.lib.hasAttrByPath attrPath pkgs) then
111-
{ Missing = null; }
112-
else
113-
# Evaluation failures are not allowed, so don't try to catch them.
114-
{
115-
Existing = attrInfo package.package_name (pkgs.lib.getAttrFromPath attrPath pkgs);
116-
};
117-
};
118-
in
119-
result
120-
) attrsByDir.${byNameDir.id}
121-
);
112+
byNameAttrsForDir =
113+
byNameDir:
114+
pkgs.lib.foldl pkgs.lib.recursiveUpdate { } (
115+
map (
116+
package:
117+
let
118+
# attrPath = builtins.trace "eval.nix:106: name = ${name}" (pkgs.lib.splitString "." name);
119+
attrPath = pkgs.lib.splitString "." package.attr_path;
120+
result = pkgs.lib.setAttrByPath attrPath {
121+
ByName =
122+
if !(pkgs.lib.hasAttrByPath attrPath pkgs) then
123+
{ Missing = null; }
124+
else
125+
# Evaluation failures are not allowed, so don't try to catch them.
126+
{
127+
Existing = attrInfo package.package_name (pkgs.lib.getAttrFromPath attrPath pkgs);
128+
};
129+
};
130+
in
131+
result
132+
) attrsByDir.${byNameDir.id}
133+
);
122134

123-
byNameAttrs = pkgs.lib.mergeAttrsList (map byNameAttrsForDir (builtins.filter (dir: builtins.hasAttr dir.id attrsByDir) byNameConfig.by_name_dirs));
135+
byNameAttrs = pkgs.lib.foldl pkgs.lib.recursiveUpdate { } (
136+
map byNameAttrsForDir (
137+
builtins.filter (dir: builtins.hasAttr dir.id attrsByDir) byNameConfig.by_name_dirs
138+
)
139+
);
124140

125141
attrSetIsOrContainsDerivation =
126142
name: value:
127143
if (!((builtins.tryEval value).success) || !(builtins.isAttrs value)) then
128-
false # (builtins.trace "attrSetIsOrContainsDerivation: returning false for ${name}" false)
144+
(builtins.trace "attrSetIsOrContainsDerivation: returning false for ${name}. tryEval is ${pkgs.lib.boolToString ((builtins.tryEval value).success)}, and isAttrs is ${pkgs.lib.boolToString (builtins.isAttrs value)}" false)
129145
else
130146
(
131147
if pkgs.lib.isDerivation value then
132-
true
148+
builtins.trace "isDerivation ${name} is true" true
133149
else if
134150
(
135-
(value ? "recurseForDerivations")
151+
(builtins.trace "${name}'s recurseForDerivations exists?: ${
152+
pkgs.lib.boolToString (value ? "recurseForDerivations")
153+
}" (value ? "recurseForDerivations"))
136154
&& (builtins.isBool value.recurseForDerivations)
137155
&& (builtins.trace "evaluating value.recurseForDerivations for ${name}" (
138156
builtins.trace "it has type ${builtins.typeOf (builtins.deepSeq value.recurseForDerivations value.recurseForDerivations)}" value.recurseForDerivations
@@ -141,15 +159,16 @@ let
141159
# then (builtins.any pkgs.lib.id (pkgs.lib.mapAttrsToList attrSetIsOrContainsDerivation value))
142160
then
143161
(builtins.trace "${name} has recurseForDerivations true" (
144-
builtins.any pkgs.lib.id (
162+
let result = builtins.any pkgs.lib.id (
145163
pkgs.lib.mapAttrsToList (
146164
k: v:
147165
(builtins.trace "Seeing if ${k} is or contains a derivation" (attrSetIsOrContainsDerivation k v))
148166
) value
149-
)
167+
);
168+
in builtins.trace "`attrSetIsOrContainsDerivation ${name}` is ${pkgs.lib.boolToString result}" result
150169
))
151170
else
152-
false
171+
builtins.trace "isDerivation ${name} is false" false
153172
);
154173
# then (builtins.trace "attrSetIsOrContainsDerivation: returning true for ${name}" true)
155174
# else builtins.trace "attrSetIsOrContainsDerivation: recursing into ${name}" (let result = (builtins.any pkgs.lib.id (pkgs.lib.mapAttrsToList attrSetIsOrContainsDerivation value)); in builtins.seq result (builtins.trace "result of recursing into ${name} reached" result)));
@@ -174,7 +193,7 @@ let
174193
"_callPackageVariant"
175194
"lib"
176195
])
177-
&& !(pkgs.lib.hasPrefix "pkgs" name) # pkgsBuildBuild and friends cause infinite recursion
196+
# && !(pkgs.lib.hasPrefix "pkgs" name) # pkgsBuildBuild and friends cause infinite recursion
178197
&& (attrSetIsOrContainsDerivation (builtins.trace "151 name=${name}" name) value)
179198
)
180199
# (builtins.tryEval ((pkgs.lib.collect (x: (pkgs.lib.isDerivation x) || (x ? "passthru")) value) != [])
@@ -183,20 +202,22 @@ let
183202
then
184203
(
185204
let
186-
recursiveResult = (builtins.mapAttrs markNonByNameAttribute value);
205+
recursiveResult = builtins.mapAttrs markNonByNameAttribute value;
187206
in
188-
(builtins.trace "recursing into name = ${name}" (
189-
builtins.seq (builtins.trace "result of recursing into ${name}: ${builtins.toJSON recursiveResult}" recursiveResult) (
190-
builtins.trace "done recursing into ${name}" recursiveResult
207+
(builtins.trace "recursing into name = ${builtins.toJSON name}" (
208+
builtins.seq (builtins.trace "result of recursing into ${builtins.toJSON name}: ${builtins.toJSON recursiveResult}" recursiveResult) (
209+
builtins.trace "done recursing into ${builtins.toJSON name}" recursiveResult
191210
)
192211
))
193212
)
194213
else if result.success then
195-
{
196-
NonByName = {
197-
EvalSuccess = output;
198-
};
199-
}
214+
builtins.trace
215+
"eval.nix:207: name is ${builtins.toJSON name}, value isAttrs is ${pkgs.lib.boolToString (builtins.isAttrs value)}, value attrSetIsOrContainsDerivation is ${pkgs.lib.boolToString (attrSetIsOrContainsDerivation name value)}"
216+
{
217+
NonByName = {
218+
EvalSuccess = output;
219+
};
220+
}
200221
else
201222
{
202223
NonByName = {
@@ -206,23 +227,25 @@ let
206227

207228
# Information on all attributes that exist but are not in a `by-name` directory.
208229
# We need this to enforce placement in a `by-name` directory for new packages.
209-
# nonByNameAttrs = pkgs.lib.mapAttrsRecursiveCond (as: !(as ? "_internalCallByNamePackageFile") || !(as ? "type" && as.type == "derivation")) (
210-
# nonByNameAttrs = let x = pkgs.lib.mapAttrsRecursiveCond (as: !(builtins.trace "trying (builtins.tryEval as).success" (builtins.tryEval as).success) || !(as ? "type" && as.type == "derivation")) (
211230

231+
# Second-newest
212232
nonByNameAttrs = (
213-
builtins.mapAttrs markNonByNameAttribute (
233+
builtins.mapAttrs markNonByNameAttribute
234+
(
214235
builtins.removeAttrs pkgs (
215-
allAttrPaths
216-
++ [
217-
"lib" # Need to exclude lib to avoid infinite recursion
218-
# "buildPackages"
219-
# "targetPackages"
220-
# "__splicedPackages"
221-
]
236+
allAttrPaths ++ [ "lib" ] # Need to exclude lib to avoid infinite recursion
222237
)
223238
)
224239
);
225240

241+
# This one is the newest. Doesn't work in the case where eval fails tho.
242+
# nonByNameAttrs = pkgs.lib.mapAttrsRecursiveCond (
243+
# as:
244+
# ((builtins.tryEval (builtins.deepSeq as null)).success)
245+
# && !((as ? "type") && (as.type == "derivation"))
246+
# ) markNonByNameAttribute (builtins.removeAttrs pkgs (allAttrPaths ++ [ "lib" ])); # Need to exclude lib to avoid infinite recursion
247+
248+
# Original???
226249
# nonByNameAttrs = pkgs.lib.mapAttrsRecursiveCond (as: !(as ? "type" && as.type == "derivation")) (
227250
# name: value:
228251
# let

0 commit comments

Comments
 (0)