|
1 | 1 | # Add `hsPkgs.${pkg-name}` based on the available targets in the plan.
|
2 | 2 | {pkgs, lib, config, ...}:
|
3 | 3 | let
|
4 |
| - redirect = redirectName: packageTargets: |
| 4 | + redirect = existing: redirectName: packageTargets: |
5 | 5 | let
|
6 | 6 | componentsByName = builtins.listToAttrs (map (x: { name = x.component-name; value = x.available; }) packageTargets);
|
7 | 7 | lookupComponent = collectionName: name: available:
|
|
14 | 14 | else if builtins.isString (builtins.head available)
|
15 | 15 | then throw "${builtins.head available} looking for ${attrPath}"
|
16 | 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}; |
| 17 | + then existing.${(builtins.head available).id}.components.library |
| 18 | + else existing.${(builtins.head available).id}.components.${collectionName}.${name}; |
19 | 19 | componentsWithPrefix = collectionName: prefix:
|
20 | 20 | lib.listToAttrs (lib.concatLists (lib.mapAttrsToList (n: available:
|
21 | 21 | lib.optional (lib.hasPrefix "${prefix}:" n && (builtins.length available != 1 || !builtins.elem (builtins.head available) ["TargetNotBuildable" "TargetNotLocal"])) (
|
|
24 | 24 | value = lookupComponent collectionName name available;
|
25 | 25 | in { inherit name value; }
|
26 | 26 | )) componentsByName));
|
27 |
| - defaultTargetPackage = config.hsPkgs.${(builtins.head ( |
| 27 | + defaultTargetId = (builtins.head ( |
28 | 28 | # Use the package identified by the library component
|
29 | 29 | componentsByName.lib or
|
30 | 30 | # Or by the first component
|
31 | 31 | componentsByName.${builtins.head (builtins.attrNames componentsByName)}
|
32 |
| - )).id}; |
33 |
| - in rec { |
34 |
| - isRedirect = true; |
| 32 | + )).id; |
| 33 | + defaultTargetPackage = existing.${defaultTargetId}; |
| 34 | + in defaultTargetPackage // rec { |
| 35 | + isRedirect = redirectName != defaultTargetId; |
35 | 36 | identifier = rec { name = (builtins.head packageTargets).pkg-name; version = (builtins.head packageTargets).pkg-version; id = "${name}-${version}"; };
|
36 | 37 | components =
|
37 | 38 | lib.mapAttrs componentsWithPrefix pkgs.haskell-nix.haskellLib.componentPrefix
|
38 | 39 | // lib.optionalAttrs (componentsByName ? lib) {
|
39 | 40 | library = lookupComponent "" "" componentsByName.lib;
|
40 | 41 | };
|
41 |
| - checks = pkgs.recurseIntoAttrs (builtins.mapAttrs |
42 |
| - (_: d: pkgs.haskell-nix.haskellLib.check d) |
43 |
| - (lib.filterAttrs (_: d: d.config.doCheck) components.tests)); |
44 |
| - inherit (defaultTargetPackage) buildType setup; |
| 42 | + checks = pkgs.recurseIntoAttrs ( |
| 43 | + lib.filterAttrs (_: x: x != {}) ( |
| 44 | + builtins.mapAttrs |
| 45 | + (_: d: pkgs.haskell-nix.haskellLib.check d) |
| 46 | + (lib.filterAttrs (_: d: d.config.doCheck) components.tests))); |
45 | 47 | };
|
46 | 48 | in {
|
47 |
| - hsPkgs = |
48 |
| - # Redirects with just the package name |
49 |
| - builtins.removeAttrs (builtins.mapAttrs (packageName: packageTargets: |
50 |
| - let |
51 |
| - byVersion = builtins.groupBy (x: x.pkg-version) packageTargets; |
52 |
| - versions = builtins.attrNames byVersion; |
53 |
| - in if builtins.length versions != 1 |
54 |
| - then let |
55 |
| - err = throw "Multiple versions for ${packageName} ${builtins.toJSON versions}"; |
56 |
| - in { |
57 |
| - isRedirect = true; |
58 |
| - identifier = { name = packageName; version = err; }; |
59 |
| - components = err; |
60 |
| - checks = err; |
61 |
| - } |
62 |
| - else redirect packageName packageTargets) (builtins.groupBy (x: x.pkg-name) config.plan-json.targets)) config.preExistingPkgs |
| 49 | + options.hsPkgs = lib.mkOption { |
| 50 | + type = lib.types.unspecified; |
| 51 | + apply = existing: existing // |
| 52 | + # Redirects with just the package name |
| 53 | + builtins.removeAttrs (builtins.mapAttrs (packageName: packageTargets: |
| 54 | + let |
| 55 | + byVersion = builtins.groupBy (x: x.pkg-version) packageTargets; |
| 56 | + versions = builtins.attrNames byVersion; |
| 57 | + in if builtins.length versions != 1 |
| 58 | + then let |
| 59 | + err = throw "Multiple versions for ${packageName} ${builtins.toJSON versions}"; |
| 60 | + in { |
| 61 | + isRedirect = true; |
| 62 | + identifier = { name = packageName; version = err; }; |
| 63 | + components = err; |
| 64 | + checks = err; |
| 65 | + } |
| 66 | + else redirect existing packageName packageTargets) (builtins.groupBy (x: x.pkg-name) config.plan-json.targets)) config.preExistingPkgs |
63 | 67 |
|
64 |
| - # Redirect for `${name}-${version}` |
65 |
| - // builtins.mapAttrs (packageNameAndVersion: packageTargets: redirect packageNameAndVersion packageTargets) |
66 |
| - (builtins.groupBy (x: "${x.pkg-name}-${x.pkg-version}") config.plan-json.targets); |
| 68 | + # Redirect for `${name}-${version}` |
| 69 | + // builtins.mapAttrs (packageNameAndVersion: packageTargets: redirect existing packageNameAndVersion packageTargets) |
| 70 | + (builtins.groupBy (x: "${x.pkg-name}-${x.pkg-version}") config.plan-json.targets); |
| 71 | + }; |
67 | 72 | }
|
0 commit comments