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`.
9## Installing `nix-tools`
11To build the latest `nix-tools` and store the result at `./nt`, run:
14nix build -f https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz nix-tools --out-link nt
17If you would like to then install `nix-tools` into your profile, run:
25The general structure will be the same for haskell.nix, independent of
26the use of stack or cabal. Let us assume for now that we have
27generated a `pkgs.nix` expression in `nix`.
29- [Generating a `pkgs.nix` for a stack project](/user-guide-stack)
30- [Generating a `pkgs.nix` for a cabal project](/user-guide-cabal)
34We will start with defining a helper function in our `default.nix`
35that will allow us to override the source imports with `-I
36haskell=/path/to/haskell.nix` in case we need it.
39{ pkgs ? import <nixpkgs> {}
42 overrideWith = override: default:
44 try = builtins.tryEval (builtins.findFile builtins.nixPath override);
45 in if try.success then
46 builtins.trace "using search host <${override}>" try.value
52Next we will use this to import `haskell.nix`.
54**NOTE**: update the `rev` and `sha256` values to the recent ones as
55 found on GitHub. Especially `haskell.hackage` and `haskell.stackage`
56 will evolve with package release on hackage and stackage releases
61 haskellLib = pkgs.fetchFromGitHub {
62 owner = "input-output-hk";
64 rev = "5180ae9d78756509c81b98b8e6d974e350b15752";
65 sha256 = "0fbnnvymdp2qb09wlqy6ga8wsyhglx607cjdfg510s1gs756v9yx";
66 name = "haskell-lib-source";
68 haskell = import (overrideWith "haskell" haskellLib) { inherit pkgs; };
72Finally we string this together and produce a package set:
76 # Import the file you will create in the stack-to-nix or cabal-to-nix step.
77 my-pkgs = import ./nix/pkgs.nix;
79 # Stack projects use the mkStackPkgSet helper function
80 pkgSet = haskell.mkStackPkgSet {
82 pkg-def-overlays = [];
86 # Cabal projects use mkPkgSet
87 pkgSet = haskell.mkPkgSet {
88 pkg-def = my-pkgs.pkg-def;
90 # these extras will provide additional packages
91 # ontop of the package set. E.g. extra-deps
92 # for stack packages. or local packages for
97 # specific package overrides would go here
99 # packages.cbors.patches = [ ./one.patch ];
100 # packages.cbors.flags.optimize-gmp = false;
104in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
107With this setup you can then start building the components of
111nix build -f default.nix $pkg.components.library
114to build the library for `$pkg` or
117nix build -f default.nix $pkg.components.exes.$exe
120to 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