|
8 | 8 | configPath, |
9 | 9 | }: |
10 | 10 | let |
11 | | - # trace = builtins.trace |
| 11 | + # trace = builtins.trace; |
12 | 12 | trace = (e1: e2: e2); |
13 | 13 |
|
| 14 | + # https://discourse.nixos.org/t/modify-an-attrset-in-nix/29919/5 |
| 15 | + removeAttrByPath = |
| 16 | + attrPath: set: |
| 17 | + pkgs.lib.updateManyAttrsByPath [ |
| 18 | + { |
| 19 | + path = pkgs.lib.init attrPath; |
| 20 | + update = old: pkgs.lib.filterAttrs (n: v: n != (pkgs.lib.last attrPath)) old; |
| 21 | + } |
| 22 | + ] set; |
| 23 | + removeAttrsByPaths = |
| 24 | + set: attrPathStrings: |
| 25 | + builtins.foldl' (acc: elem: removeAttrByPath elem acc) set ( |
| 26 | + map (s: pkgs.lib.splitString "." s) attrPathStrings |
| 27 | + ); |
| 28 | + |
14 | 29 | rawAttrs = trace "rawAttrs = ${(builtins.toJSON (builtins.fromJSON (builtins.readFile attrsPath)))}" ( |
15 | 30 | builtins.fromJSON (builtins.readFile attrsPath) |
16 | 31 | ); |
@@ -116,12 +131,10 @@ let |
116 | 131 | # Information on all attributes that are in a `by-name` directory. |
117 | 132 | byNameAttrsForDir = |
118 | 133 | byNameDir: |
119 | | - pkgs.lib.mergeAttrsList ( |
120 | | - # pkgs.lib.foldl pkgs.lib.recursiveUpdate { } ( |
| 134 | + builtins.foldl' pkgs.lib.recursiveUpdate { } ( |
121 | 135 | map ( |
122 | 136 | package: |
123 | 137 | let |
124 | | - # attrPath = trace "eval.nix:106: name = ${name}" (pkgs.lib.splitString "." name); |
125 | 138 | attrPath = pkgs.lib.splitString "." package.attr_path; |
126 | 139 | result = pkgs.lib.setAttrByPath attrPath { |
127 | 140 | ByName = |
|
216 | 229 | newName: newValue: markNonByNameAttribute (attrPath ++ [ newName ]) newValue |
217 | 230 | ) value; |
218 | 231 | in |
219 | | - (trace "recursing into name = ${builtins.toJSON pname}" ( |
| 232 | + (trace "recursing into name = ${builtins.toJSON pname}, which has attributes ${builtins.toJSON (builtins.attrNames recursiveResult)}" ( |
220 | 233 | builtins.seq (trace "result of recursing into ${builtins.toJSON pname}: ${builtins.toJSON recursiveResult}" recursiveResult) ( |
221 | 234 | trace "done recursing into ${builtins.toJSON pname}" recursiveResult |
222 | 235 | ) |
|
241 | 254 | # We need this to enforce placement in a `by-name` directory for new packages. |
242 | 255 |
|
243 | 256 | # Second-newest |
| 257 | + # nonByNameAttrs = ( |
| 258 | + # builtins.mapAttrs markNonByNameAttribute ( |
| 259 | + # builtins.removeAttrs pkgs ( |
| 260 | + # allAttrPaths ++ [ "lib" ] # Need to exclude lib to avoid infinite recursion |
| 261 | + # ) |
| 262 | + # ) |
| 263 | + # ); |
| 264 | + |
244 | 265 | nonByNameAttrs = ( |
245 | 266 | builtins.mapAttrs markNonByNameAttribute ( |
246 | | - builtins.removeAttrs pkgs ( |
| 267 | + removeAttrsByPaths pkgs ( |
247 | 268 | allAttrPaths ++ [ "lib" ] # Need to exclude lib to avoid infinite recursion |
248 | 269 | ) |
249 | 270 | ) |
|
269 | 290 | # } |
270 | 291 | # ) (builtins.removeAttrs pkgs (attrs ++ [ "lib" ])); # Need to exclude lib to avoid infinite recursion |
271 | 292 |
|
| 293 | + customMergeAttrs = |
| 294 | + byName: nonByName: |
| 295 | + let |
| 296 | + inherit (builtins) isAttrs; |
| 297 | + byNameNames = builtins.trace "byNameNames is ${builtins.toJSON (builtins.attrNames byName)}" ( |
| 298 | + builtins.attrNames byName |
| 299 | + ); |
| 300 | + nonByNameNames = builtins.trace "nonByNameNames is ${builtins.toJSON (builtins.attrNames nonByName)}" ( |
| 301 | + builtins.attrNames nonByName |
| 302 | + ); |
| 303 | + onlyByName = pkgs.lib.subtractLists nonByNameNames byNameNames; |
| 304 | + onlyNonByName = pkgs.lib.subtractLists byNameNames nonByNameNames; |
| 305 | + inBothLists = pkgs.lib.intersectLists byNameNames nonByNameNames; |
| 306 | + in |
| 307 | + builtins.listToAttrs ( |
| 308 | + (map (x: { |
| 309 | + name = x; |
| 310 | + value = byName.${x}; |
| 311 | + }) onlyByName) |
| 312 | + ++ (map (x: { |
| 313 | + name = x; |
| 314 | + value = nonByName.${x}; |
| 315 | + }) onlyNonByName) |
| 316 | + ++ (map ( |
| 317 | + x: |
| 318 | + builtins.trace |
| 319 | + "x = ${x}; byName.${x} = ${builtins.toJSON byName.${x}}; nonByName.${x} = ${builtins.toJSON nonByName.${x}}" |
| 320 | + ( |
| 321 | + if |
| 322 | + !(isAttrs byName.${x}) # And nonByName.${x} is or is not an attrset, we don't care. |
| 323 | + then |
| 324 | + { |
| 325 | + name = x; |
| 326 | + value = nonByName.${x}; |
| 327 | + } |
| 328 | + else if !(isAttrs nonByName.${x}) then |
| 329 | + throw "Shouldn't happen??? " |
| 330 | + else if byName.${x} ? "ByName" && nonByName.${x} ? "NonByName" then |
| 331 | + { |
| 332 | + name = x; |
| 333 | + value = { |
| 334 | + ByName = nonByName.${x}.NonByName; |
| 335 | + }; |
| 336 | + } |
| 337 | + else if |
| 338 | + (builtins.removeAttrs byName.${x} [ |
| 339 | + "NonByName" |
| 340 | + "ByName" |
| 341 | + ]) != { } |
| 342 | + && nonByName.${x} ? "NonByName" |
| 343 | + then |
| 344 | + { |
| 345 | + name = x; |
| 346 | + value = byName.${x}; |
| 347 | + } |
| 348 | + else |
| 349 | + { |
| 350 | + name = x; |
| 351 | + value = customMergeAttrs byName.${x} nonByName.${x}; |
| 352 | + } |
| 353 | + ) |
| 354 | + ) inBothLists) |
| 355 | + ); |
| 356 | + |
272 | 357 | # All attributes |
273 | | - attributes = byNameAttrs // nonByNameAttrs; |
| 358 | + # attributes = pkgs.lib.recursiveUpdateUntil (attrPath: left: right: |
| 359 | + # trace "eval.nix:293: attrPath ${builtins.toJSON attrPath}; left attrNames are ${if builtins.isAttrs left then (builtins.toJSON (builtins.attrNames left)) else "not an attrset"}; right attrNames are ${if builtins.isAttrs right then builtins.toJSON (builtins.attrNames right) else "not an attrset"}" |
| 360 | + # ((builtins.removeAttrs left ["NonByName" "ByName"]) != { } && right ? "NonByName") |
| 361 | + # # || |
| 362 | + # # ((left ? "ByName" || left ? "NonByName") && (right ? "ByName" || right ? "NonByName")) |
| 363 | + # ) byNameAttrs nonByNameAttrs; |
| 364 | + |
| 365 | + attributes = customMergeAttrs byNameAttrs nonByNameAttrs; |
| 366 | + |
274 | 367 | result = |
275 | 368 | pkgs.lib.mapAttrsToListRecursiveCond |
276 | 369 | (attrPath: attrValue: !((attrValue ? "NonByName") || (attrValue ? "ByName"))) |
|
0 commit comments