on 38afdfd help sign in
61 lines 1.7 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.patches = [ ./one.patch ];
31 # packages.cbors.flags.optimize-gmp = false;
32 ];
33 };
35 # Cabal projects use this:
36 pkgSet = haskell.mkCabalProjectPkgSet {
37 plan-pkgs = my-pkgs;
38 pkg-def-extras = [];
39 modules = [];
40 };
42in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
43```
45With this setup you can then start building the components of
46interest:
48```bash
49nix build -f default.nix $pkg.components.library
50```
52to build the library for `$pkg` or
54```bash
55nix build -f default.nix $pkg.components.exes.$exe
56```
58to build a specific executable. The same holds for test suites and benchmarks.
60- [Generating a `pkgs.nix` for a Stack project](./stack-projects.md)
61- [Generating a `pkgs.nix` for a Cabal project](./cabal-projects.md)