|
14 | 14 | flake, |
15 | 15 | systems, |
16 | 16 | nixpkgs, |
| 17 | + # We need to treat the packages that are being defined in self differently, |
| 18 | + # since otherwise we trigger infinite recursion when perSystem is defined in |
| 19 | + # terms of the packages defined by self, and self uses perSystem to define |
| 20 | + # its packages. |
| 21 | + # We run into the infrec when trying to filter out packages based on their |
| 22 | + # meta attributes, since that actually requires evaluating the package's derivation |
| 23 | + # and can then in turn change the value of perSystem (by removing packages), |
| 24 | + # which then requires to evaluate the package again, and so on and so forth. |
| 25 | + # To break this cycle, we define perSystem in terms of the filesystem hierarchy, |
| 26 | + # and not based on self.packages, and we don't apply any filtering based on |
| 27 | + # meta attributes yet. |
| 28 | + # The actual self.packages, can then be the filtered set of packages. |
| 29 | + unfilteredPackages, |
17 | 30 | }: |
18 | 31 | let |
19 | | - |
20 | 32 | # Memoize the args per system |
21 | 33 | systemArgs = lib.genAttrs systems ( |
22 | 34 | system: |
23 | 35 | let |
24 | 36 | # Resolve the packages for each input. |
25 | 37 | perSystem = lib.mapAttrs ( |
26 | | - _: flake: flake.legacyPackages.${system} or { } // flake.packages.${system} or { } |
| 38 | + name: flake: |
| 39 | + # For self, we need to treat packages differently, see above |
| 40 | + if name == "self" then |
| 41 | + flake.legacyPackages.${system} or { } // unfilteredPackages.${system} |
| 42 | + else |
| 43 | + flake.legacyPackages.${system} or { } // flake.packages.${system} or { } |
27 | 44 | ) inputs; |
28 | 45 |
|
29 | 46 | # Handle nixpkgs specially. |
|
158 | 175 | flake |
159 | 176 | nixpkgs |
160 | 177 | systems |
| 178 | + unfilteredPackages |
161 | 179 | ; |
162 | 180 | }) |
163 | 181 | eachSystem |
|
336 | 354 | perSystemModule |
337 | 355 | path |
338 | 356 | ] ++ mkHomeUsersModule hostName home-manager.nixosModules.default; |
339 | | - specialArgs = specialArgs // { inherit hostName; }; |
| 357 | + specialArgs = specialArgs // { |
| 358 | + inherit hostName; |
| 359 | + }; |
340 | 360 | }; |
341 | 361 | }; |
342 | 362 |
|
|
354 | 374 | perSystemModule |
355 | 375 | path |
356 | 376 | ] ++ mkHomeUsersModule hostName home-manager.darwinModules.default; |
357 | | - specialArgs = specialArgs // { inherit hostName; }; |
| 377 | + specialArgs = specialArgs // { |
| 378 | + inherit hostName; |
| 379 | + }; |
358 | 380 | }; |
359 | 381 | }; |
360 | 382 |
|
|
372 | 394 | perSystemSMModule |
373 | 395 | path |
374 | 396 | ]; |
375 | | - extraSpecialArgs = specialArgs // { inherit hostName; }; |
| 397 | + extraSpecialArgs = specialArgs // { |
| 398 | + inherit hostName; |
| 399 | + }; |
376 | 400 | }; |
377 | 401 | }; |
378 | 402 |
|
|
454 | 478 | ) |
455 | 479 | ) |
456 | 480 | ); |
| 481 | + |
| 482 | + # See the comment in mkEachSystem |
| 483 | + unfilteredPackages = |
| 484 | + lib.traceIf (builtins.pathExists (src + "/pkgs")) "blueprint: the /pkgs folder is now /packages" |
| 485 | + ( |
| 486 | + let |
| 487 | + entries = |
| 488 | + (optionalPathAttrs (src + "/packages") (path: importDir path lib.id)) |
| 489 | + // (optionalPathAttrs (src + "/package.nix") (path: { |
| 490 | + default = { |
| 491 | + inherit path; |
| 492 | + }; |
| 493 | + })) |
| 494 | + // (optionalPathAttrs (src + "/formatter.nix") (path: { |
| 495 | + formatter = { |
| 496 | + inherit path; |
| 497 | + }; |
| 498 | + })); |
| 499 | + in |
| 500 | + eachSystem ( |
| 501 | + { newScope, system, ... }: |
| 502 | + lib.mapAttrs (pname: { path, ... }: newScope { inherit pname; } path { }) entries |
| 503 | + ) |
| 504 | + ); |
457 | 505 | in |
458 | 506 | # FIXME: maybe there are two layers to this. The blueprint, and then the mapping to flake outputs. |
459 | 507 | { |
|
571 | 619 | defaultNix |
572 | 620 | ]; |
573 | 621 |
|
574 | | - packages = |
575 | | - lib.traceIf (builtins.pathExists (src + "/pkgs")) "blueprint: the /pkgs folder is now /packages" |
576 | | - ( |
577 | | - let |
578 | | - entries = |
579 | | - (optionalPathAttrs (src + "/packages") (path: importDir path lib.id)) |
580 | | - // (optionalPathAttrs (src + "/package.nix") (path: { |
581 | | - default = { |
582 | | - inherit path; |
583 | | - }; |
584 | | - })) |
585 | | - // (optionalPathAttrs (src + "/formatter.nix") (path: { |
586 | | - formatter = { |
587 | | - inherit path; |
588 | | - }; |
589 | | - })); |
590 | | - in |
591 | | - eachSystem ( |
592 | | - { newScope, system, ... }: filterPlatforms system (lib.mapAttrs (pname: { path, ... }: newScope { inherit pname; } path { }) entries) |
593 | | - ) |
594 | | - ); |
| 622 | + # See the comment in mkEachSystem |
| 623 | + packages = lib.mapAttrs filterPlatforms unfilteredPackages; |
595 | 624 |
|
596 | 625 | # Defining homeConfigurations under legacyPackages allows the home-manager CLI |
597 | 626 | # to automatically detect the right output for the current system without |
|
0 commit comments