3So you want to use `haskell.nix` with your stack or cabal project. The
4general approach will be to pick the right tool from `nix-tools` and
5produce a `pkgs.nix` expressions. Getting a copy of the haskell.nix,
6hackage.nix (and potentially stackage.nix) source will then equip us
7to produce derivations that we can `nix build`.
11The general structure will be the same for haskell.nix, independent of
12the use of stack or cabal. Let us assume for now that we have
13generated a `pkgs.nix` expression in `nix`.
15- [Generating a `pkgs.nix` for a stack project](/user-guide-stack)
16- [Generating a `pkgs.nix` for a cabal project](/user-guide-cabal)
20We will start with defining a helper function in our `default.nix`
21that will allow us to override the source imports with `-I
22haskell=/path/to/haskell.nix` in case we need it.
25{ pkgs ? import <nixpkgs> {}
28 overrideWith = override: default:
30 try = builtins.tryEval (builtins.findFile builtins.nixPath override);
31 in if try.success then
32 builtins.trace "using search host <${override}>" try.value
38Next we will use this to import `haskell.nix`, `hackage.nix` and
39`stackage.nix` (if we use a stack project).
41**NOTE**: update the `rev` and `sha256` values to the recent ones as
42 found on GitHub. Especially `hackage.nix` and `stackage.nix` will
43 evolve with package release on hackage and stackage releases
48 # all packages from hackage as nix expressions
49 hackage = import (overrideWith "hackage"
50 (pkgs.fetchFromGitHub { owner = "input-output-hk";
52 rev = "3180384b563ec7c7b46bca86b3ace0f32d04cde8";
53 sha256 = "19ndkn8pivli9plwq0wnx1cj126l89yk7jw9a0dj51ic3b2qhlb2";
54 name = "hackage-exprs-source"; }))
56 # a different haskell infrastructure
57 haskell = import (overrideWith "haskell"
58 (pkgs.fetchFromGitHub { owner = "input-output-hk";
60 rev = "73f733ba8bbd11443dda713d1a2d4b7c50a5d408";
61 sha256 = "1p2srrxw2lac5krrg35waa251by98r2miwyg6zac9glpg2vmq3ip";
62 name = "haskell-lib-source"; }))
65 # the set of all stackage snapshots
66 stackage = import (overrideWith "stackage"
67 (pkgs.fetchFromGitHub { owner = "input-output-hk";
68 repo = "stackage.nix";
69 rev = "2615a4e6b1651215ee400e62fcdcb195062a3d35";
70 sha256 = "08c8lb8x047hndwm1cb2zxixnjmrswfp5y18xp1v79cjqlva0qj6";
71 name = "stackage-snapshot-source"; }))
76Finally we string this together and produce a package set:
80 # Import the file you will create in the stack-to-nix or cabal-to-nix step.
81 my-pkgs = import ./nix/pkgs.nix { inherit stackage; };
83 pkgSet = haskell.mkPkgSet {
85 pkg-def = my-pkgs.pkg-def;
87 # this overlay will provide additional packages
88 # ontop of the package set. E.g. extra-deps
89 # for stack packages. or local packages for
94 # specific package overrides would go here
96 # packages.cbors.patches = [ ./one.patch ];
97 # packages.cbors.flags.optimize-gmp = false;
101in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
104With this setup you can then start building the components of
108nix build -f default.nix $pkg.components.library
111to build the library for `$pkg` or
114nix build -f default.nix $pkg.components.exes.$exe
117to build a specific executable. The same holds for test suites and benchmarks.
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list