on use-host-arch help sign in
haskell.nix/snapshots.nix
75 lines 2.7 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 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.Cabal.patches = [ ./overlays/patches/Cabal/fix-data-dir.patch ]; }
23 { packages.alex.package.setup-depends = [pkgSet.config.hsPkgs.Cabal]; }
24 { packages.happy.package.setup-depends = [pkgSet.config.hsPkgs.Cabal]; }
25 ];
26 }; in pkgSet).config.hsPkgs;
28 # Tests whether snapshot name is an LTS within
29 # the half-open version interval [start, end).
30 ltsInRange = start: end: name: let
31 components = splitString "-" name;
32 version = concatStringsSep "-" (drop 1 components);
33 in
34 assert length components >= 2;
35 head components == "lts"
36 && versionAtLeast version start
37 && versionOlder version end;
39 # A function to get pkg-def-extras with build fixes for certain
40 # snapshots.
41 pkg-def-extras = let
42 fixes = {
43 # Work around a mismatch between stackage metadata and the
44 # libraries shipped with GHC.
45 # https://github.com/commercialhaskell/stackage/issues/4466
46 fix-ghc-transformers = {
47 predicate = ltsInRange "12" "14"; # [12, 14) : 14.1 has correct versions
48 extra = hackage: {
49 packages = {
50 "transformers" = (((hackage.transformers)."0.5.6.2").revisions).default;
51 "process" = (((hackage.process)."1.6.5.0").revisions).default;
52 };
53 };
54 };
56 # Add hsc2hs to the snapshot. This is a build tool for many
57 # packages. Stackage does not include it in the snapshots
58 # because it is expected that hsc2hs comes with ghc.
59 fix-hsc2hs = {
60 predicate = ltsInRange "1" "14"; # [1, 14) : 14.1 includes hsc2hs
61 extra = hackage: {
62 packages = {
63 "hsc2hs" = (((hackage.hsc2hs)."0.68.4").revisions).default;
64 };
65 };
66 };
67 };
69 applyFix = name: fix: optional ((fix.predicate or (const true)) name) fix.extra;
71 in
72 name: concatLists (mapAttrsToList (_: applyFix name) fixes);
74in
75 mapAttrs mkSnapshot stackage