Skip to content

Commit 4ebd797

Browse files
Update the component builder
1 parent 2496961 commit 4ebd797

File tree

3 files changed

+304
-154
lines changed

3 files changed

+304
-154
lines changed

nix/default.nix

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,49 @@
1616

1717
haskellLib = import ./lib.nix { inherit lib haskellLib; };
1818

19-
plan =
20-
let p = planFunc hackageConfigs;
21-
in p // {
22-
packages = lib.mapAttrs
23-
(_: pkg: self:
24-
lib.recursiveUpdate (pkg.revision self) { flags = pkg.flags or {}; }
25-
) p.packages;
26-
};
2719
hackageConfigs =
20+
lib.flip lib.mapAttrs hackage
21+
(pname: lib.mapAttrs
22+
(vnum: version: version // {
23+
revisions =
24+
let
25+
rev2Config = rev: {
26+
inherit (version) sha256;
27+
inherit (rev) outPath;
28+
revision = rev.revNum;
29+
revisionSha256 = rev.sha256;
30+
};
31+
f = rev: acc: acc // {
32+
# If there's a collision (e.g. a revision was
33+
# reverted), pick the one with the smaller
34+
# revNum. They're identical, but if the smaller one is
35+
# r0 then we don't have to download a cabal file.
36+
${rev.sha256} = if lib.hasAttr rev.sha256 acc && acc.${rev.sha256}.revNum < rev.revNum
37+
then acc.${rev.sha256}
38+
else rev;
39+
};
40+
contentAddressedRevs = lib.foldr f {} (builtins.attrValues version.revisions);
41+
in lib.mapAttrs (_: rev2Config) (version.revisions // contentAddressedRevs);
42+
}));
43+
plan =
2844
let
2945
args = {
3046
inherit hsPkgs compiler system pkgconfPkgs;
3147
pkgs = adjustedPkgs;
3248
};
33-
handleVer = vdata:
34-
let
35-
revs = builtins.removeAttrs vdata ["sha256"];
36-
rev2HashedConfig = name: rev: { name = rev.cabalSha256; value = revConfigs.${name}; };
37-
revConfigs = lib.mapAttrs (_: rev2config vdata.sha256) revs;
38-
in revConfigs // lib.mapAttrs' rev2HashedConfig revs;
39-
rev2config = sha256: rev: self: import rev (args // { inherit (self) flags; }) // {
40-
inherit sha256;
41-
inherit (rev) cabalFile;
42-
};
43-
in lib.mapAttrs (_: lib.mapAttrs (_: handleVer)) hackage;
49+
p = planFunc hackageConfigs;
50+
in p // {
51+
packages = lib.mapAttrs
52+
(pname: { revision, flags ? {} }: self:
53+
# Set the flags with the rhs of the recursiveUpdate, but
54+
# pass the final choice in flags using open recursion.
55+
lib.recursiveUpdate (import revision (args // { inherit (self) flags; })) {
56+
inherit flags;
57+
inherit (revision) sha256 revision revisionSha256;
58+
}
59+
)
60+
p.packages;
61+
};
4462

4563
new-builder = weakCallPackage pkgs ./new-builder.nix {
4664
inherit haskellLib ghc weakCallPackage;

nix/new-builder.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
, name ? "${package.identifier.name}-${package.identifier.version}"
88
, sha256 ? null
99
, src ? fetchurl { url = "mirror://hackage/${name}.tar.gz"; inherit sha256; }
10-
, cabalFile ? null
10+
, revision ? null
11+
, revisionSha256 ? null
1112
}@config:
1213

1314
let
15+
cabalFile = null;
1416
defaultSetupSrc = builtins.toFile "Setup.hs" ''
1517
import Distribution.Simple
1618
main = defaultMain

0 commit comments

Comments
 (0)