on iko/ghcjs-patch-master help sign in
Adds `hackage-package`. (#205)

* Adds `stackage-lts-set` and `hackage-package`. This allows us to build a full stackage-lts-set, or a package from hackage. ``` nix build '(with import ./. {}; (hackage-package { name = "lens"; version = "4.17.1"; })).components.library' ``` would build the lens library. ``` nix build '(with import ./. {}; (stackage-lts-set "lts-13.28")).lens.components.library' ``` would build the lens library component from the lts-13.28 stackage set. * Drop lts-stackage-set * Adds some docs

commitebb22334d5f23b8ddaddcfc0952530d78d819ef5 authorMoritz Angermann <moritz.angermann@gmail.com> dateMon 15 Jul 2019, 20:47 (7 years ago) parent057db9b
3 files changed+73−11
default.nix+25 docs/user-guide.md+41−5 lib/call-cabal-project-to-nix.nix+7−6
default.nix+25
@@ -211,6 +211,31 @@ let
211211 source-pins = self.callPackage ./lib/make-source-pins.nix {
212212 sources = [ hackageSrc stackageSrc pkgs.path ];
213213 };
214+
215+ # Build a specific package (name, version) against a given index-stage
216+ # from hackage. This is useful if you want to build an executable from
217+ # a given package.
218+ # NB: If no explicit index-state is provided the most recent one from
219+ # the index-state-hashes is used. This guarantees reproducability wrt
220+ # to the haskell.nix revision. If reproducability beyond haskell.nix
221+ # is required, a specific index-state should be provided!
222+ hackage-package =
223+ { name
224+ , version
225+ , index-state ? builtins.trace "Using latest index state!" pkgs.lib.last (builtins.attrNames (import indexStateHashesPath))
226+ }:
227+ let tarball = pkgs.fetchurl {
228+ url = "mirror://hackage/${name}-${version}.tar.gz";
229+ inherit (hackage.${name}.${version}) sha256; };
230+ in let src = buildPackages.pkgs.runCommand "${name}-${version}-src" { } ''
231+ tmp=$(mktemp -d)
232+ cd $tmp
233+ tar xzf ${tarball}
234+ mv "${name}-${version}" $out
235+ '';
236+ in let plan-pkgs = import (callCabalProjectToNix { inherit src; index-state = builtins.trace "Using index-state: ${index-state}" index-state; });
237+ in let pkg-set = mkCabalProjectPkgSet { inherit plan-pkgs; };
238+ in pkg-set.config.hsPkgs.${name};
214239 });
215240
216241in
docs/user-guide.md+41−5
@@ -1,12 +1,48 @@
11# User Guide
22
3−So you want to use [Haskell.nix][] with your stack or cabal project. The
4−general approach will be to pick the right tool from `nix-tools` and
5−produce a `pkgs.nix` expression. Getting a copy of the `nix-tools`
6−(and potentially the [Haskell.nix][] source), will then equip us to
7−produce derivations that we can `nix build`.
3+[Haskell.nix][] can be use for two different use cases:
4+
5+1. to build a specific package from hackage or a [stackage][] lts or nightly set.
6+
7+ To build a package, say [lens][], from a stackage snapshot, say [lts-13.28][],
8+ you could run
9+ ```bash
10+ nix build '(with import ./. {}; snapshots."lts-13.28").lens.components.library'
11+ ```
12+ which would build the [lens][] library component from the lens package as fixed
13+ by the [lts-13.28][] stackage snapshot.
14+
15+ To build any package from hackage, say [lens][], in version, say 4.17.1, you
16+ could run
17+ ```bash
18+ nix build '(with import ./. {}; (hackage-package { name = "lens"; version = "4.17.1"; })).components.library'
19+ ```
20+ which would build the [lens][] library component from the [lens-4.17.1][] package
21+ from hackage. The dependencies would be solved against the most recent
22+ [hackage-index-state][] that comes via the [hackage.nix][] pin with your
23+ [haskell.nix][] checkout. A specific one can be specified as well:
24+ ```bash
25+ nix build '(with import ./. {}; (hackage-package { name = "lens"; version = "4.17.1"; index-state = "2019-07-14T00:00:00Z"; })).components.library'
26+ ```
27+ which would use the hackage index as of `2019-07-14T00:00:00Z` to produce a build plan
28+ for the [lens-4.17.1][] package.
29+
30+
31+2. to build a stack or cabal project.
32+
33+ So you want to use [Haskell.nix][] with your stack or cabal project. The
34+ general approach will be to pick the right tool from `nix-tools` and
35+ produce a `pkgs.nix` expression. Getting a copy of the `nix-tools`
36+ (and potentially the [Haskell.nix][] source), will then equip us to
37+ produce derivations that we can `nix build`.
838
939[haskell.nix]: https://github.com/input-output-hk/haskell.nix
40+[stackage]: https://stackage.org
41+[lts-13.28]: https://www.stackage.org/lts-13.28
42+[lens]: https://hackage.haskell.org/package/lens
43+[lens-4.17.1]: https://hackage.haskell.org/package/lens-4.17.1
44+[hackage.nix]: https://github.com/input-output-hk/hackage.nix
45+[hackage-index-state]: https://github.com/input-output-hk/hackage.nix/blob/master/index-state-hashes.nix
1046
1147## Installing `nix-tools`
1248
lib/call-cabal-project-to-nix.nix+7−6
@@ -10,19 +10,20 @@ assert (if (builtins.compareVersions cabal-install.version "2.4.0.0") < 0
1010 then throw "cabal-install (current version: ${cabal-install.version}) needs to be at least 2.4 for plan-to-nix to work without cabal-to-nix"
1111 else true);
1212let
13− cabalFiles =
14− pkgs.lib.cleanSourceWith {
15− inherit src;
13+ maybeCleanedSource =
14+ if pkgs.lib.canCleanSource src
15+ then pkgs.lib.cleanSourceWith {
16+ src = builtins.trace "src = ${src};" src;
1617 filter = path: type:
1718 type == "directory" ||
18− pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ];
19− };
19+ pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ]; }
20+ else src;
2021 plan = runCommand "plan-to-nix-pkgs" {
2122 nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ];
2223 } ''
2324 tmp=$(mktemp -d)
2425 cd $tmp
25− cp -r ${cabalFiles}/* .
26+ cp -r ${maybeCleanedSource}/* .
2627 chmod +w -R .
2728 # warning: this may not generate the proper cabal file.
2829 # hpack allows globbing, and turns that into module lists