Skip to content

Commit 0b10d7a

Browse files
committed
Include hsPkgs."${name}-${version}"
1 parent 4b6ad33 commit 0b10d7a

File tree

2 files changed

+48
-39
lines changed

2 files changed

+48
-39
lines changed

lib/load-cabal-plan.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let
2222
lookupDependency = hsPkgs: d:
2323
pkgs.lib.optional (by-id.${d}.type != "pre-existing") (
2424
if by-id.${d}.component-name or "lib" == "lib"
25-
then hsPkgs.${d} or hsPkgs.${by-id.${d}.pkg-name}
25+
then hsPkgs.${d} or hsPkgs."${by-id.${d}.pkg-name}-${by-id.${d}.pkg-version}" or hsPkgs.${by-id.${d}.pkg-name}
2626
else hsPkgs.${d}.components.sublibs.${pkgs.lib.removePrefix "lib:" by-id.${d}.component-name});
2727
# Lookup an executable dependency in `hsPkgs.pkgsBuildBuild`
2828
lookupExeDependency = hsPkgs: d:
@@ -157,4 +157,4 @@ in {
157157
(import ../modules/install-plan/planned.nix { inherit getComponents; })
158158
(import ../modules/install-plan/redirect.nix)
159159
];
160-
}
160+
}

modules/install-plan/redirect.nix

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
11
# 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:
443
let
544
byVersion = builtins.groupBy (x: x.pkg-version) packageTargets;
645
versions = builtins.attrNames byVersion;
@@ -13,39 +52,9 @@
1352
components = err;
1453
checks = err;
1554
}
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);
5160
}

0 commit comments

Comments
 (0)