@@ -0,0 +1,65 @@
1+# This provides a package set for each snapshot in Stackage.
2+#
3+# It allows you to use a bare snapshot without having to invoke
4+# mkStackPkgSet with a stack.yaml project.
5+#
6+# A particular package in a snapshot would be accessed with:
7+# snapshots."lts-13.18".conduit
8+
9+{ lib, mkPkgSet, stackage }:
10+
11+with lib;
12+
13+let
14+ mkSnapshot = name: pkg-def: (mkPkgSet {
15+ inherit pkg-def;
16+ pkg-def-extras = pkg-def-extras name;
17+ }).config.hsPkgs;
18+
19+ # Tests whether snapshot name is an LTS within
20+ # the half-open version interval [start, end).
21+ ltsInRange = start: end: name: let
22+ components = splitString "-" name;
23+ version = concatStringsSep "-" (drop 1 components);
24+ in
25+ assert length components >= 2;
26+ head components == "lts"
27+ && versionAtLeast version start
28+ && versionOlder version end;
29+
30+ # A function to get pkg-def-extras with build fixes for certain
31+ # snapshots.
32+ pkg-def-extras = let
33+ fixes = {
34+ # Work around a mismatch between stackage metadata and the
35+ # libraries shipped with GHC.
36+ # https://github.com/commercialhaskell/stackage/issues/4466
37+ fix-ghc-transformers = {
38+ predicate = ltsInRange "12" "14";
39+ extra = hackage: {
40+ packages = {
41+ "transformers" = (((hackage.transformers)."0.5.6.2").revisions).default;
42+ "process" = (((hackage.process)."1.6.5.0").revisions).default;
43+ };
44+ };
45+ };
46+
47+ # Add hsc2hs to the snapshot. This is a build tool for many
48+ # packages. Stackage does not include it in the snapshots
49+ # because it is expected that hsc2hs comes with ghc.
50+ fix-hsc2hs = {
51+ extra = hackage: {
52+ packages = {
53+ "hsc2hs" = (((hackage.hsc2hs)."0.68.4").revisions).default;
54+ };
55+ };
56+ };
57+ };
58+
59+ applyFix = name: fix: optional ((fix.predicate or (const true)) name) fix.extra;
60+
61+ in
62+ name: concatLists (mapAttrsToList (_: applyFix name) fixes);
63+
64+in
65+ mapAttrs mkSnapshot stackage