@@ -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