on iko/ghcjs-patch-master help sign in
Provide hackage and stackage from haskell.nix

Providing hackage and stackage here simplifies usage of the new Haskell Infrastructure. With this change, the user doesn't need to specify revisions of the external repos, or update them. Basically, with hackage.nix and stackage.nix, the latest version is always best, because snapshots and package versions are added on top. So there is no need for users to choose a revision. Also add mkStackPkgSet which is a shortcut for building stack projects.

commitbd603e0b51883dae22fdb9890c1cf61707a8d212 authorRodney Lorrimar <rodney.lorrimar@iohk.io> dateTue 5 Feb 2019, 13:50 (8 years ago) parente533951
10 files changed+123−56
default.nix+62−7 hackage-src.json+7 lib/fetch-external.nix+16 lib/override-with.nix+9 stackage-src.json+7 test/builder-haddock/default.nix+2−6 test/cabal-22/default.nix+8−12 test/cabal-simple/default.nix+4−10 test/default.nix+6−14 test/with-packages/default.nix+2−7
default.nix+62−7
@@ -1,3 +1,6 @@
1+{ pkgs ? import <nixpkgs> {}
2+}:
3+
14let
25 # pkg-def's may reference boot packages, but those
36 # are not guaranteed to be available on hackage, as
@@ -13,8 +16,7 @@ let
1316 then filterAttrs (k: _: !(builtins.elem k boot-pkgs)) v
1417 else v)
1518 (pkg-def hackage);
16−in
17−hackage: let haskell = rec {
19+
1820 # ghc hackage patches.
1921 # these are patches that turn hackage packages into the same as the ones
2022 # ghc ships with the supposedly same version. See GHC Track Issue: 16199
@@ -22,10 +24,63 @@ hackage: let haskell = rec {
2224
2325 compat = import ./lib/compat.nix;
2426
25− mkPkgSet
26− = { pkgs, pkg-def, pkg-def-overlays ? [], modules ? [] }@args:
27− import ./package-set.nix (args // { inherit hackage; pkg-def = strip-pkg-def pkgs pkg-def; });
27+ # Utility function for downloading a pinned git repo, that can be
28+ # overridden with NIX_PATH.
29+ fetchExternal = import ./lib/fetch-external.nix;
30+
31+ # All packages from Hackage as Nix expressions
32+ hackage = import (fetchExternal {
33+ name = "hackage-exprs-source";
34+ specJSON = ./hackage-src.json;
35+ override = "hackage";
36+ });
37+
38+ # The set of all Stackage snapshots
39+ stackage = import (fetchExternal {
40+ name = "stackage-snapshot-source";
41+ specJSON = ./stackage-src.json;
42+ override = "stackage";
43+ });
44+
45+ packages = self: ({
46+ # Utility functions for working with the component builder.
47+ haskellLib = let hl = import ./lib { inherit (pkgs) lib; haskellLib = hl; }; in hl;
2848
29− mkNewPkgSet = args: builtins.trace "DEPRECATED: use mkPkgSet instead of mkNewPkgSet" (mkPkgSet args);
49+ # Create a Haskell package set based on a cabal build plan (plan-to-nix)
50+ # and Nix expressions representing cabal packages (cabal-to-nix).
51+ mkPkgSet =
52+ { pkg-def # Base package set. Either from stackage (via stack-to-nix) or from a cabal projects plan file (via plan-to-nix)
53+ , pkg-def-overlays ? [] # Additional packages to augment the Base package set `pkg-def` with.
54+ , modules ? []
55+ }@args:
3056
31−}; in haskell
57+ import ./package-set.nix (args // {
58+ inherit hackage pkgs;
59+ pkg-def = strip-pkg-def pkgs pkg-def;
60+ });
61+
62+ # Create a Haskell package set based on a Stack configuration.
63+ mkStackPkgSet =
64+ { stack-pkgs # Path to the output of stack-to-nix
65+ , pkg-def-overlays ? []
66+ , modules ? []
67+ }@args:
68+
69+ let
70+ # The Stackage release referenced in the stack config
71+ pkg-def = stackage.${stack-pkgs.resolver};
72+ # The compiler referenced in the stack config
73+ compiler = (stack-pkgs.overlay hackage).compiler or (pkg-def hackage).compiler;
74+ in self.mkPkgSet {
75+ inherit pkg-def;
76+ pkg-def-overlays = [ stack-pkgs.overlay ] ++ pkg-def-overlays;
77+ modules = [ ghcHackagePatches.${compiler.nix-name} ] ++ modules;
78+ };
79+
80+ # Snapshots of Hackage and Stackage, converted to Nix expressions,
81+ # regularly updated.
82+ inherit hackage stackage;
83+ });
84+
85+in
86+ pkgs.lib.makeScope pkgs.newScope packages
hackage-src.jsonnew file+7
@@ -0,0 +1,7 @@
1+{
2+ "url": "https://github.com/input-output-hk/hackage.nix",
3+ "rev": "3180384b563ec7c7b46bca86b3ace0f32d04cde8",
4+ "date": "2019-02-05T17:32:14+08:00",
5+ "sha256": "19ndkn8pivli9plwq0wnx1cj126l89yk7jw9a0dj51ic3b2qhlb2",
6+ "fetchSubmodules": false
7+}
lib/fetch-external.nixnew file+16
@@ -0,0 +1,16 @@
1+# Provides a function for fetching a GitHub repo from a JSON spec,
2+# overridable with the given entry on the NIX_PATH.
3+
4+let
5+ overrideWith = import ./override-with.nix;
6+in
7+ { name, specJSON, override }:
8+ let
9+ spec = builtins.fromJSON (builtins.readFile specJSON);
10+ in
11+ overrideWith override
12+ (builtins.fetchTarball {
13+ inherit name;
14+ url = "${spec.url}/archive/${spec.rev}.tar.gz";
15+ inherit (spec) sha256;
16+ })
lib/override-with.nixnew file+9
@@ -0,0 +1,9 @@
1+# overrideWith - Allow the user to override the given default path
2+# with a NIX_PATH entry.
3+override: default:
4+ let
5+ try = builtins.tryEval (builtins.findFile builtins.nixPath override);
6+ in if try.success then
7+ builtins.trace "using search host <${override}>" try.value
8+ else
9+ default
stackage-src.jsonnew file+7
@@ -0,0 +1,7 @@
1+{
2+ "url": "https://github.com/input-output-hk/stackage.nix",
3+ "rev": "2615a4e6b1651215ee400e62fcdcb195062a3d35",
4+ "date": "2019-02-05T17:41:44+08:00",
5+ "sha256": "08c8lb8x047hndwm1cb2zxixnjmrswfp5y18xp1v79cjqlva0qj6",
6+ "fetchSubmodules": false
7+}
test/builder-haddock/default.nix+2−6
@@ -1,13 +1,9 @@
1−{ pkgs
2−, haskell
3−, stdenv
4−}:
1+{ mkPkgSet, stdenv }:
52
63with stdenv.lib;
74
85let
9− pkgSet = haskell.mkPkgSet {
10− inherit pkgs;
6+ pkgSet = mkPkgSet {
117 # generated with:
128 # cabal new-build
139 # plan-to-nix dist-newstyle/cache/plan.json > plan.nix
test/cabal-22/default.nix+8−12
@@ -1,13 +1,9 @@
1−{ pkgs
2−, haskell
3−, stdenv
4−}:
1+{ stdenv, mkPkgSet }:
52
63with stdenv.lib;
74
85let
9− pkgSet = haskell.mkPkgSet {
10− inherit pkgs;
6+ pkgSet = mkPkgSet {
117 pkg-def = import ./plan.nix;
128 pkg-def-overlays = [
139 { project = ./project.nix; }
@@ -32,23 +28,23 @@ in
3228 "$exe"
3329
3430 printf "checking that executable is dynamically linked to system libraries... " >& 2
35− '' + pkgs.lib.optionalString pkgs.stdenv.isLinux ''
31+ '' + optionalString stdenv.isLinux ''
3632 ldd $exe | grep libpthread
37− '' + pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
33+ '' + optionalString stdenv.isDarwin ''
3834 otool -L $exe | grep "libSystem.B"
3935 '' + ''
4036 # fixme: posix-specific
4137 printf "checking that dynamic library is produced... " >& 2
42− '' + pkgs.lib.optionalString pkgs.stdenv.isLinux ''
38+ '' + optionalString stdenv.isLinux ''
4339 sofile=$(find "${packages.project.components.library}" | grep -e '\.so$')
44− '' + pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
40+ '' + optionalString stdenv.isDarwin ''
4541 sofile=$(find "${packages.project.components.library}" | grep -e '\.dylib$')
4642 '' + ''
4743 echo "$sofile"
4844 printf "checking that dynamic library is dynamically linked to prim... " >& 2
49− '' + pkgs.lib.optionalString pkgs.stdenv.isLinux ''
45+ '' + optionalString stdenv.isLinux ''
5046 ldd $sofile | grep libHSghc-prim
51− '' + pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
47+ '' + optionalString stdenv.isDarwin ''
5248 otool -L $sofile | grep libHSghc-prim
5349 '' + ''
5450 touch $out
test/cabal-simple/default.nix+4−10
@@ -1,9 +1,5 @@
11# Test a package set
2−{ pkgs
3−, haskell
4−, stdenv
5−, util
6−}:
2+{ stdenv, util, mkPkgSet }:
73
84with stdenv.lib;
95
@@ -12,8 +8,7 @@ let
128 # 1. cabal-to-nix cabal-simple.cabal > cabal-simple.nix
139 # 2. cabal new-build
1410 # 3. plan-to-nix ./dist-newstyle/cache/plan.json > plan.nix
15− pkgSet = haskell.mkPkgSet {
16− inherit pkgs;
11+ pkgSet = mkPkgSet {
1712 pkg-def = import ./plan.nix;
1813 pkg-def-overlays = [
1914 { cabal-simple = ./cabal-simple.nix;
@@ -45,9 +40,9 @@ in
4540 $exe
4641
4742 printf "checking that executable is dynamically linked to system libraries... " >& 2
48− '' + pkgs.lib.optionalString pkgs.stdenv.isLinux ''
43+ '' + optionalString stdenv.isLinux ''
4944 ldd $exe | grep libpthread
50− '' + pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
45+ '' + optionalString stdenv.isDarwin ''
5146 otool -L $exe |grep .dylib
5247 '' + ''
5348
@@ -68,6 +63,5 @@ in
6863 # Used for testing externally with nix-shell (../tests.sh).
6964 # This just adds cabal-install to the existing shells.
7065 test-shell = util.addCabalInstall packages.cabal-simple.components.all;
71−
7266 };
7367}
test/default.nix+6−14
@@ -3,29 +3,21 @@
33with pkgs;
44
55let
6− # all packages from hackage as nix expressions
7− hackage = import (fetchFromGitHub { owner = "angerman";
8− repo = "hackage.nix";
9− rev = "5223a45e08b1b0d738fdd292b39e49f39f21536f";
10− sha256 = "09r662kn2qs444fmqni9jamaxnrk9jrg6whqmxbwhfgd5vy3yynq";
11− name = "hackage-exprs-source"; });
126
137 # The new Haskell infra applied to nix representation of Hackage
14− haskell = import ../. hackage;
15−
16− haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
8+ haskell = pkgs.callPackage ../. { };
179
1810 util = callPackage ./util.nix {};
1911
2012in {
21− cabal-simple = callPackage ./cabal-simple { inherit haskell util; };
22− cabal-22 = callPackage ./cabal-22 { inherit haskell; };
23− with-packages = callPackage ./with-packages { inherit haskell util; };
24− builder-haddock = callPackage ./builder-haddock { inherit haskell; };
13+ cabal-simple = callPackage ./cabal-simple { inherit (haskell) mkPkgSet; inherit util; };
14+ cabal-22 = callPackage ./cabal-22 { inherit (haskell) mkPkgSet; };
15+ with-packages = callPackage ./with-packages { inherit (haskell) mkPkgSet; inherit util; };
16+ builder-haddock = callPackage ./builder-haddock { inherit (haskell) mkPkgSet; };
2517
2618 # Run unit tests with: nix-instantiate --eval --strict -A unit
2719 # An empty list means success.
28− unit = callPackage ./unit.nix { inherit haskellLib; };
20+ unit = callPackage ./unit.nix { inherit (haskell) haskellLib; };
2921}
3022
3123## possible test cases
test/with-packages/default.nix+2−7
@@ -1,15 +1,10 @@
1−{ pkgs
2−, haskell
3−, stdenv
4−, util
5−}:
1+{ stdenv, util, mkPkgSet }:
62
73with stdenv.lib;
84with util;
95
106let
11− pkgSet = haskell.mkPkgSet {
12− inherit pkgs;
7+ pkgSet = mkPkgSet {
138 # generated with:
149 # cabal new-build
1510 # plan-to-nix dist-newstyle/cache/plan.json > plan.nix