on 147cf21 help sign in
75 lines 2.5 kB history raw
1# How to create Nix builds for your own private Haskell packages
3The general structure will be the same, independent of the use of
4Stack or Cabal.
6Let us assume for now that we have already generated a `pkgs.nix`
7expression. The following file then produces a package set:
9```nix
10# default.nix
11let
12 # Import the Haskell.nix library,
13 haskell = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
15 # Import the file you will create in the stack-to-nix or cabal-to-nix step.
16 my-pkgs = import ./pkgs.nix;
18 # Stack projects use this:
19 pkgSet = haskell.mkStackPkgSet {
20 stack-pkgs = my-pkgs;
21 pkg-def-extras = [
22 # these extras will provide additional packages
23 # ontop of the package set. E.g. extra-deps
24 # for stack packages. or local packages for
25 # cabal.projects
26 ];
27 modules = [
28 # specific package overrides would go here
29 # example:
30 # packages.cbors.package.ghcOptions = "-Werror";
31 # packages.cbors.patches = [ ./one.patch ];
32 # packages.cbors.flags.optimize-gmp = false;
33 # It may be better to set flags in stack.yaml instead (overrides will
34 # be included for them automatically by `stack-to-nix`).
35 ];
36 };
38 # Cabal projects use this:
39 pkgSet = haskell.mkCabalProjectPkgSet {
40 plan-pkgs = my-pkgs;
41 pkg-def-extras = [];
42 modules = [
43 # specific package overrides would go here
44 # example:
45 # packages.cbors.package.ghcOptions = "-Werror";
46 # packages.cbors.patches = [ ./one.patch ];
47 # To override a flag you will need to use mkOverride to make
48 # it clear that you wish to replace the value found in the
49 # `plan.json` file (all the flags values are included there
50 # by `cabal`).
51 # packages.cbors.flags.optimize-gmp = stdenv.lib.mkOverride 10 false;
52 # It may be better to set flags in `cabal.project` instead.
53 ];
54 };
56in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
57```
59With this setup you can then start building the components of
60interest:
62```bash
63nix build -f default.nix $pkg.components.library
64```
66to build the library for `$pkg` or
68```bash
69nix build -f default.nix $pkg.components.exes.$exe
70```
72to build a specific executable. The same holds for test suites and benchmarks.
74- [Generating a `pkgs.nix` for a Stack project](./stack-projects.md)
75- [Generating a `pkgs.nix` for a Cabal project](./cabal-projects.md)