Skip to content

Commit e554458

Browse files
committed
Fetch the revised cabal files as part of elaborating hackage.nix
Fixes #1857.
1 parent a970f7b commit e554458

File tree

1 file changed

+51
-20
lines changed

1 file changed

+51
-20
lines changed

modules/hackage.nix

+51-20
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,70 @@ let
2727
# { r0 = { nix = import ../hackage/...;
2828
# sha256 = $packageVersionSha256;
2929
# revision = $revNum;
30-
# revisionSha256 = $revisionSha256; };
30+
# revisionSha256 = $revisionSha256;
31+
# package-description-override = ... optional revised cabal file from hackage ...; };
3132
# default = revisions.r0;
3233
# $revisionSha256 = revisions.r0; };
3334
# };
3435
# };
3536
# };
3637
# }
3738

39+
rev2Config =
40+
{ pname, vnum, sha256 }:
41+
rev:
42+
{ system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }@modArgs:
43+
let
44+
package-description-override =
45+
# we don't need to fetch cabal file revision zero because that's the one included in the source distribution
46+
if rev.revNum == 0 then null
47+
else
48+
builtins.readFile (pkgs.fetchurl (
49+
{
50+
name = "${pname}-${vnum}-r${toString rev.revNum}.cabal";
51+
url = "https://hackage.haskell.org/package/${pname}-${vnum}/revision/${toString rev.revNum}.cabal";
52+
sha256 = rev.sha256;
53+
}));
54+
in
55+
{
56+
inherit sha256;
57+
inherit package-description-override;
58+
revision = rev.revNum;
59+
revisionSha256 = rev.sha256;
60+
} // (x: (rev.nix or (import rev)) x) modArgs;
61+
62+
makeContentAddressed = revisions:
63+
let
64+
f = revName: acc:
65+
let rev = revisions.${revName};
66+
in
67+
acc // {
68+
# The original revsion attribute
69+
${revName} = rev;
70+
# The revision keyed by its sha256
71+
# Note: if there's a collision (e.g. a revision was reverted), pick
72+
# the one with the smaller revNum. They're identical, but if the
73+
# smaller one is r0 then we don't have to download a cabal file.
74+
${rev.sha256} =
75+
if lib.hasAttr rev.sha256 acc && acc.${rev.sha256}.revNum < rev.revNum
76+
then acc.${rev.sha256}
77+
else rev;
78+
};
79+
in
80+
lib.foldr f { } (builtins.attrNames revisions);
81+
3882
hackageConfigs =
3983
lib.flip lib.mapAttrs config.hackage.db
4084
(pname: lib.mapAttrs
4185
(vnum: version: version // {
4286
revisions =
43-
let
44-
rev2Config = rev: { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }@modArgs: {
45-
inherit (version) sha256;
46-
revision = rev.revNum;
47-
revisionSha256 = rev.sha256;
48-
} // (x: (rev.nix or (import rev)) x) modArgs;
49-
f = rev: acc: acc // {
50-
# If there's a collision (e.g. a revision was
51-
# reverted), pick the one with the smaller
52-
# revNum. They're identical, but if the smaller one is
53-
# r0 then we don't have to download a cabal file.
54-
${rev.sha256} = if lib.hasAttr rev.sha256 acc && acc.${rev.sha256}.revNum < rev.revNum
55-
then acc.${rev.sha256}
56-
else rev;
57-
};
58-
contentAddressedRevs = lib.foldr f {} (builtins.attrValues version.revisions);
59-
in lib.mapAttrs (_: rev2Config) (version.revisions // contentAddressedRevs);
87+
lib.mapAttrs
88+
(_: rev2Config { inherit pname vnum; inherit (version) sha256; })
89+
(makeContentAddressed version.revisions);
6090
}));
6191

62-
in {
92+
in
93+
{
6394
options.ghc.package = lib.mkOption {
6495
type = lib.types.package;
6596
# obtain the compiler from the haskell packages.
@@ -85,5 +116,5 @@ in {
85116
# be built by GHC's build system. However it may show up in stackage
86117
# snapshots. As such we just null it out.
87118
config.hackage.configs = hackageConfigs
88-
// { rts."1.0".revisions.default = null; };
119+
// { rts."1.0".revisions.default = null; };
89120
}

0 commit comments

Comments
 (0)