Skip to content

Commit 37a1b7a

Browse files
rvlangerman
authored andcommitted
Add snapshots attribute (#151)
* Add a snapshots attribute These contain package sets for all of the Stackage snapshots. Relates to #22 * tests: Add stackage snapshots test * Add a stackage fix for "No attribute: hsc2hs" * Add comment to snapshots.nix and fix version comparison function
1 parent f930cf7 commit 37a1b7a

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ let
109109
modules = [ ghcHackagePatches.${compiler.nix-name} ] ++ modules;
110110
};
111111

112+
# Package sets for all stackage snapshots.
113+
snapshots = self.callPackage ./snapshots.nix {};
114+
# Pick a recent LTS snapshot to be our "default" package set.
115+
haskellPackages = self.snapshots."lts-13.18";
116+
112117
# Programs for generating Nix expressions from Cabal and Stack
113118
# files. We need to make sure we build this from the buildPackages,
114119
# we never want to actually cross compile nix-tools on it's own.

snapshots.nix

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ in {
1616
with-packages = haskell.callPackage ./with-packages { inherit util; };
1717
builder-haddock = haskell.callPackage ./builder-haddock {};
1818
stack-simple = haskell.callPackage ./stack-simple {};
19+
snapshots = haskell.callPackage ./snapshots {};
1920
callStackToNix = haskell.callPackage ./callStackToNix {};
20-
2121
callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
2222

2323
# Run unit tests with: nix-instantiate --eval --strict -A unit

test/snapshots/default.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{ stdenv, haskellPackages }:
2+
3+
with stdenv.lib;
4+
5+
stdenv.mkDerivation {
6+
name = "shell-for-test";
7+
8+
buildCommand = ''
9+
########################################################################
10+
# test snapshot ghcWithHoogle
11+
12+
printf "checking that the latest LTS snapshot has the lens package...\n" >& 2
13+
test -d ${haskellPackages.lens.components.library}
14+
15+
touch $out
16+
'';
17+
18+
meta.platforms = platforms.all;
19+
}

0 commit comments

Comments
 (0)