on edd1d21 help sign in
84 lines 2.8 kB history raw
1# How to replace IFDs with intermediate nix files
3We believe that imports from derivations (IFDs) provide tremendous
4value in nix and the aversion towards them stems mostly from
5poor tooling and ci support for them. We do not believe
6that poor tooling or ci support should cripple nix capability
7of abstraction. Hence haskell.nix makes excessive use of
8IFDs.
10We do note however that there are users who prefer to
11have IFD-free expressions. For this group of users we
12detail how to expand the IFD dependent high level functions
13into their IFD free building blocks.
15The general structure will be the same, independent of the use of
16Stack or Cabal.
18Let us assume for now that we have already generated a `pkgs.nix`
19expression (see the links bellow). The following file then produces a package set:
21```nix
22# default.nix
23let
24 # Import the Haskell.nix library,
25 pkgs = import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs;
27 # Import the file you will create in the stack-to-nix or cabal-to-nix step.
28 my-pkgs = import ./pkgs.nix;
30 # Stack projects use this:
31 pkgSet = pkgs.haskell-nix.mkStackPkgSet {
32 stack-pkgs = my-pkgs;
33 pkg-def-extras = [
34 # these extras will provide additional packages
35 # ontop of the package set. E.g. extra-deps
36 # for stack packages. or local packages for
37 # cabal.projects
38 ];
39 modules = [
40 # specific package overrides would go here
41 # example:
42 # packages.cbors.package.ghcOptions = "-Werror";
43 # packages.cbors.patches = [ ./one.patch ];
44 # packages.cbors.flags.optimize-gmp = false;
45 # It may be better to set flags in stack.yaml instead
46 # (`stack-to-nix` will include them as defaults).
47 ];
48 };
50 # Cabal projects use this:
51 pkgSet = pkgs.haskell-nix.mkCabalProjectPkgSet {
52 plan-pkgs = my-pkgs;
53 pkg-def-extras = [];
54 modules = [
55 # specific package overrides would go here
56 # example:
57 # packages.cbors.package.ghcOptions = "-Werror";
58 # packages.cbors.patches = [ ./one.patch ];
59 # packages.cbors.flags.optimize-gmp = false;
60 # It may be better to set flags in `cabal.project` instead
61 # (`plan-to-nix` will include them as defaults).
62 ];
63 };
65in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
66```
68With this setup you can then start building the components of
69interest:
71```bash
72nix build -f default.nix $pkg.components.library
73```
75to build the library for `$pkg` or
77```bash
78nix build -f default.nix $pkg.components.exes.$exe
79```
81to build a specific executable. The same holds for test suites and benchmarks.
83- [Generating a `pkgs.nix` for a Stack project](./stack-projects.md)
84- [Generating a `pkgs.nix` for a Cabal project](./cabal-projects.md)