on e94de40 help sign in
haskell.nix/snapshots.nix
76 lines 2.8 kB history raw
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
9{ lib, mkPkgSet, stackage, excludeBootPackages, ghc-boot-packages }:
11with lib;
13let
14 mkSnapshot = name: pkg-def: (let pkgSet = mkPkgSet {
15 pkg-def = excludeBootPackages null pkg-def;
16 # ghc-boot-packages are needed for the reinstallable ghc library and
17 # are constructed from the patched ghc source.
18 pkg-def-extras = (pkg-def-extras name)
19 ++ [(hackage: ghc-boot-packages.${(pkg-def hackage).compiler.nix-name})];
20 modules = [
21 { reinstallableLibGhc = true; } # Allow ghc library to be installed for packages that need it
22 { packages.alex.package.setup-depends = [pkgSet.config.hsPkgs.Cabal]; }
23 { packages.happy.package.setup-depends = [pkgSet.config.hsPkgs.Cabal]; }
24 ] ++ optional (ltsInRange "1" "15" name) {
25 packages.Cabal.patches = [ ./overlays/patches/Cabal/fix-data-dir.patch ];
26 };
27 }; in pkgSet).config.hsPkgs;
29 # Tests whether snapshot name is an LTS within
30 # the half-open version interval [start, end).
31 ltsInRange = start: end: name: let
32 components = splitString "-" name;
33 version = concatStringsSep "-" (drop 1 components);
34 in
35 assert length components >= 2;
36 head components == "lts"
37 && versionAtLeast version start
38 && versionOlder version end;
40 # A function to get pkg-def-extras with build fixes for certain
41 # snapshots.
42 pkg-def-extras = let
43 fixes = {
44 # Work around a mismatch between stackage metadata and the
45 # libraries shipped with GHC.
46 # https://github.com/commercialhaskell/stackage/issues/4466
47 fix-ghc-transformers = {
48 predicate = ltsInRange "12" "14"; # [12, 14) : 14.1 has correct versions
49 extra = hackage: {
50 packages = {
51 "transformers" = (((hackage.transformers)."0.5.6.2").revisions).default;
52 "process" = (((hackage.process)."1.6.5.0").revisions).default;
53 };
54 };
55 };
57 # Add hsc2hs to the snapshot. This is a build tool for many
58 # packages. Stackage does not include it in the snapshots
59 # because it is expected that hsc2hs comes with ghc.
60 fix-hsc2hs = {
61 predicate = ltsInRange "1" "14"; # [1, 14) : 14.1 includes hsc2hs
62 extra = hackage: {
63 packages = {
64 "hsc2hs" = (((hackage.hsc2hs)."0.68.4").revisions).default;
65 };
66 };
67 };
68 };
70 applyFix = name: fix: optional ((fix.predicate or (const true)) name) fix.extra;
72 in
73 name: concatLists (mapAttrsToList (_: applyFix name) fixes);
75in
76 mapAttrs mkSnapshot stackage