|
1 | 1 | # Add `hsPkgs.${pkg-name}` based on the available targets in the plan.
|
2 |
| -{pkgs, lib, config, ...}: { |
3 |
| - hsPkgs = builtins.removeAttrs (builtins.mapAttrs (packageName: packageTargets: |
| 2 | +{pkgs, lib, config, ...}: |
| 3 | +let |
| 4 | + redirect = redirectName: packageTargets: |
| 5 | + let |
| 6 | + componentsByName = builtins.listToAttrs (map (x: { name = x.component-name; value = x.available; }) packageTargets); |
| 7 | + lookupComponent = collectionName: name: available: |
| 8 | + let attrPath = |
| 9 | + if collectionName == "" |
| 10 | + then "${redirectName}.components.library" |
| 11 | + else "${redirectName}.components.${collectionName}.${name}"; |
| 12 | + in if builtins.length available != 1 |
| 13 | + then throw "Multiple avaialble targets for ${attrPath}" |
| 14 | + else if builtins.isString (builtins.head available) |
| 15 | + then throw "${builtins.head available} looking for ${attrPath}" |
| 16 | + else if collectionName == "" |
| 17 | + then config.hsPkgs.${(builtins.head available).id}.components.library |
| 18 | + else config.hsPkgs.${(builtins.head available).id}.components.${collectionName}.${name}; |
| 19 | + componentsWithPrefix = collectionName: prefix: |
| 20 | + lib.listToAttrs (lib.concatLists (lib.mapAttrsToList (n: available: |
| 21 | + lib.optional (lib.hasPrefix "${prefix}:" n && (builtins.length available != 1 || !builtins.elem (builtins.head available) ["TargetNotBuildable" "TargetNotLocal"])) ( |
| 22 | + let |
| 23 | + name = lib.removePrefix "${prefix}:" n; |
| 24 | + value = lookupComponent collectionName name available; |
| 25 | + in { inherit name value; } |
| 26 | + )) componentsByName)); |
| 27 | + in rec { |
| 28 | + isRedirect = true; |
| 29 | + identifier = rec { name = (builtins.head packageTargets).pkg-name; version = (builtins.head packageTargets).pkg-version; id = "${name}-${version}"; }; |
| 30 | + components = |
| 31 | + lib.mapAttrs componentsWithPrefix pkgs.haskell-nix.haskellLib.componentPrefix |
| 32 | + // lib.optionalAttrs (componentsByName ? lib) { |
| 33 | + library = lookupComponent "" "" componentsByName.lib; |
| 34 | + }; |
| 35 | + checks = pkgs.recurseIntoAttrs (builtins.mapAttrs |
| 36 | + (_: d: pkgs.haskell-nix.haskellLib.check d) |
| 37 | + (lib.filterAttrs (_: d: d.config.doCheck) components.tests)); |
| 38 | + }; |
| 39 | +in { |
| 40 | + hsPkgs = |
| 41 | + # Redirects with just the package name |
| 42 | + builtins.removeAttrs (builtins.mapAttrs (packageName: packageTargets: |
4 | 43 | let
|
5 | 44 | byVersion = builtins.groupBy (x: x.pkg-version) packageTargets;
|
6 | 45 | versions = builtins.attrNames byVersion;
|
|
13 | 52 | components = err;
|
14 | 53 | checks = err;
|
15 | 54 | }
|
16 |
| - else let |
17 |
| - componentsByName = builtins.listToAttrs (map (x: { name = x.component-name; value = x.available; }) packageTargets); |
18 |
| - lookupComponent = collectionName: name: available: |
19 |
| - let attrPath = |
20 |
| - if collectionName == "" |
21 |
| - then "${packageName}.components.library" |
22 |
| - else "${packageName}.components.${collectionName}.${name}"; |
23 |
| - in if builtins.length available != 1 |
24 |
| - then throw "Multiple avaialble targets for ${attrPath}" |
25 |
| - else if builtins.isString (builtins.head available) |
26 |
| - then throw "${builtins.head available} looking for ${attrPath}" |
27 |
| - else if collectionName == "" |
28 |
| - then config.hsPkgs.${(builtins.head available).id}.components.library |
29 |
| - else config.hsPkgs.${(builtins.head available).id}.components.${collectionName}.${name}; |
30 |
| - componentsWithPrefix = collectionName: prefix: |
31 |
| - lib.listToAttrs (lib.concatLists (lib.mapAttrsToList (n: available: |
32 |
| - lib.optional (lib.hasPrefix "${prefix}:" n && (builtins.length available != 1 || !builtins.elem (builtins.head available) ["TargetNotBuildable" "TargetNotLocal"])) ( |
33 |
| - let |
34 |
| - name = lib.removePrefix "${prefix}:" n; |
35 |
| - value = lookupComponent collectionName name available; |
36 |
| - in { inherit name value; } |
37 |
| - )) componentsByName)); |
38 |
| - in rec { |
39 |
| - isRedirect = true; |
40 |
| - identifier = rec { name = packageName; version = builtins.head versions; id = "${name}-${version}"; }; |
41 |
| - components = |
42 |
| - lib.mapAttrs componentsWithPrefix pkgs.haskell-nix.haskellLib.componentPrefix |
43 |
| - // lib.optionalAttrs (componentsByName ? lib) { |
44 |
| - library = lookupComponent "" "" componentsByName.lib; |
45 |
| - }; |
46 |
| - checks = pkgs.recurseIntoAttrs (builtins.mapAttrs |
47 |
| - (_: d: pkgs.haskell-nix.haskellLib.check d) |
48 |
| - (lib.filterAttrs (_: d: d.config.doCheck) components.tests)); |
49 |
| - }) |
50 |
| - (builtins.groupBy (x: x.pkg-name) config.plan-json.targets)) config.preExistingPkgs; |
| 55 | + else redirect packageName packageTargets) (builtins.groupBy (x: x.pkg-name) config.plan-json.targets)) config.preExistingPkgs |
| 56 | + |
| 57 | + # Redirect for `${name}-${version}` |
| 58 | + // builtins.mapAttrs (packageNameAndVersion: packageTargets: redirect packageNameAndVersion packageTargets) |
| 59 | + (builtins.groupBy (x: "${x.pkg-name}-${x.pkg-version}") config.plan-json.targets); |
51 | 60 | }
|
0 commit comments