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
This commit is contained in:
Rodney Lorrimar 2019-05-27 18:05:42 +10:00 committed by Moritz Angermann
parent f930cf772b
commit 37a1b7ac2b
4 changed files with 90 additions and 1 deletions

View File

@ -109,6 +109,11 @@ let
modules = [ ghcHackagePatches.${compiler.nix-name} ] ++ modules;
};
# Package sets for all stackage snapshots.
snapshots = self.callPackage ./snapshots.nix {};
# Pick a recent LTS snapshot to be our "default" package set.
haskellPackages = self.snapshots."lts-13.18";
# Programs for generating Nix expressions from Cabal and Stack
# files. We need to make sure we build this from the buildPackages,
# we never want to actually cross compile nix-tools on it's own.

65
snapshots.nix Normal file
View File

@ -0,0 +1,65 @@
# This provides a package set for each snapshot in Stackage.
#
# It allows you to use a bare snapshot without having to invoke
# mkStackPkgSet with a stack.yaml project.
#
# A particular package in a snapshot would be accessed with:
# snapshots."lts-13.18".conduit
{ lib, mkPkgSet, stackage }:
with lib;
let
mkSnapshot = name: pkg-def: (mkPkgSet {
inherit pkg-def;
pkg-def-extras = pkg-def-extras name;
}).config.hsPkgs;
# Tests whether snapshot name is an LTS within
# the half-open version interval [start, end).
ltsInRange = start: end: name: let
components = splitString "-" name;
version = concatStringsSep "-" (drop 1 components);
in
assert length components >= 2;
head components == "lts"
&& versionAtLeast version start
&& versionOlder version end;
# A function to get pkg-def-extras with build fixes for certain
# snapshots.
pkg-def-extras = let
fixes = {
# Work around a mismatch between stackage metadata and the
# libraries shipped with GHC.
# https://github.com/commercialhaskell/stackage/issues/4466
fix-ghc-transformers = {
predicate = ltsInRange "12" "14";
extra = hackage: {
packages = {
"transformers" = (((hackage.transformers)."0.5.6.2").revisions).default;
"process" = (((hackage.process)."1.6.5.0").revisions).default;
};
};
};
# Add hsc2hs to the snapshot. This is a build tool for many
# packages. Stackage does not include it in the snapshots
# because it is expected that hsc2hs comes with ghc.
fix-hsc2hs = {
extra = hackage: {
packages = {
"hsc2hs" = (((hackage.hsc2hs)."0.68.4").revisions).default;
};
};
};
};
applyFix = name: fix: optional ((fix.predicate or (const true)) name) fix.extra;
in
name: concatLists (mapAttrsToList (_: applyFix name) fixes);
in
mapAttrs mkSnapshot stackage

View File

@ -16,8 +16,8 @@ in {
with-packages = haskell.callPackage ./with-packages { inherit util; };
builder-haddock = haskell.callPackage ./builder-haddock {};
stack-simple = haskell.callPackage ./stack-simple {};
snapshots = haskell.callPackage ./snapshots {};
callStackToNix = haskell.callPackage ./callStackToNix {};
callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
# Run unit tests with: nix-instantiate --eval --strict -A unit

View File

@ -0,0 +1,19 @@
{ stdenv, haskellPackages }:
with stdenv.lib;
stdenv.mkDerivation {
name = "shell-for-test";
buildCommand = ''
########################################################################
# test snapshot ghcWithHoogle
printf "checking that the latest LTS snapshot has the lens package...\n" >& 2
test -d ${haskellPackages.lens.components.library}
touch $out
'';
meta.platforms = platforms.all;
}