Skip to content

Commit 1db526a

Browse files
committed
Merge remote-tracking branch 'origin/master' into static-nix-tools
2 parents 176d661 + 14e1938 commit 1db526a

File tree

3 files changed

+60
-46
lines changed

3 files changed

+60
-46
lines changed

flake.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/default.nix

+16-7
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,24 @@ in {
160160
let packageToComponents = _name: package:
161161
# look for the components with this group if there are any
162162
let components = package.components.${group} or {};
163-
# set recurseForDerivations unless it's a derivation itself (e.g. the "library" component) or an empty set
164-
in if lib.isDerivation components || components == {}
165-
then components
166-
else recurseIntoAttrs components;
163+
in {
164+
inherit (package.identifier) name;
165+
# set recurseForDerivations unless it's a derivation itself (e.g. the "library" component) or an empty set
166+
components =
167+
if lib.isDerivation components || components == {}
168+
then components
169+
else recurseIntoAttrs components;
170+
};
167171
packageFilter = _name: package: (package.isHaskell or false) && packageSel package;
168172
filteredPkgs = lib.filterAttrs packageFilter haskellPackages;
169173
# at this point we can filter out packages that don't have any of the given kind of component
170-
packagesByComponent = lib.filterAttrs (_: components: components != {}) (lib.mapAttrs packageToComponents filteredPkgs);
171-
in recurseIntoAttrs packagesByComponent;
174+
packagesByComponent = lib.mapAttrsToList packageToComponents filteredPkgs;
175+
packagesGroupedByName = builtins.groupBy (x: x.name) packagesByComponent;
176+
combined =
177+
lib.filterAttrs (_: components: components != {}) (
178+
builtins.mapAttrs (_name: packages:
179+
builtins.foldl' (a: b: a // b) {} (map (x: x.components) packages)) packagesGroupedByName);
180+
in recurseIntoAttrs combined;
172181

173182
# Equivalent to collectComponents with (_: true) as selection function.
174183
# Useful for pre-filtered package-set.
@@ -184,7 +193,7 @@ in {
184193
# This can be used to collect all the test runs in your project, so that can be run in CI.
185194
collectChecks = packageSel: haskellPackages:
186195
let packageFilter = _name: package: (package.isHaskell or false) && packageSel package;
187-
in recurseIntoAttrs (lib.mapAttrs (_: p: p.checks) (lib.filterAttrs packageFilter haskellPackages));
196+
in recurseIntoAttrs (lib.filterAttrs (_: x: x != {} && x != recurseIntoAttrs {}) (lib.mapAttrs (_: p: p.checks) (lib.filterAttrs packageFilter haskellPackages)));
188197

189198
# Equivalent to collectChecks with (_: true) as selection function.
190199
# Useful for pre-filtered package-set.

modules/install-plan/redirect.nix

+35-30
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Add `hsPkgs.${pkg-name}` based on the available targets in the plan.
22
{pkgs, lib, config, ...}:
33
let
4-
redirect = redirectName: packageTargets:
4+
redirect = existing: redirectName: packageTargets:
55
let
66
componentsByName = builtins.listToAttrs (map (x: { name = x.component-name; value = x.available; }) packageTargets);
77
lookupComponent = collectionName: name: available:
@@ -14,8 +14,8 @@ let
1414
else if builtins.isString (builtins.head available)
1515
then throw "${builtins.head available} looking for ${attrPath}"
1616
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};
1919
componentsWithPrefix = collectionName: prefix:
2020
lib.listToAttrs (lib.concatLists (lib.mapAttrsToList (n: available:
2121
lib.optional (lib.hasPrefix "${prefix}:" n && (builtins.length available != 1 || !builtins.elem (builtins.head available) ["TargetNotBuildable" "TargetNotLocal"])) (
@@ -24,44 +24,49 @@ let
2424
value = lookupComponent collectionName name available;
2525
in { inherit name value; }
2626
)) componentsByName));
27-
defaultTargetPackage = config.hsPkgs.${(builtins.head (
27+
defaultTargetId = (builtins.head (
2828
# Use the package identified by the library component
2929
componentsByName.lib or
3030
# Or by the first component
3131
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;
3536
identifier = rec { name = (builtins.head packageTargets).pkg-name; version = (builtins.head packageTargets).pkg-version; id = "${name}-${version}"; };
3637
components =
3738
lib.mapAttrs componentsWithPrefix pkgs.haskell-nix.haskellLib.componentPrefix
3839
// lib.optionalAttrs (componentsByName ? lib) {
3940
library = lookupComponent "" "" componentsByName.lib;
4041
};
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)));
4547
};
4648
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
6367

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+
};
6772
}

0 commit comments

Comments
 (0)