on e94de40 help sign in
haskell.nix/docs/iohk-nix.md
113 lines 3.2 kB history raw
1# IOHK's nix tooling
3## [iohk-nix](https://github.com/input-output-hk/iohk-nix)
5iohk-nix is IOHK's shared nix library. It provides some templates to
6make working with haskell.nix trivial but is non-essential to use
7haskell.nix infrastructure.
9lib.nix
10```nix
11let
12 # iohk-nix can be overridden for debugging purposes by setting
13 # NIX_PATH=iohk_nix=/path/to/iohk-nix
14 iohkNix = import (
15 let try = builtins.tryEval <iohk_nix>;
16 in if try.success
17 then builtins.trace "using host <iohk_nix>" try.value
18 else
19 let
20 spec = builtins.fromJSON (builtins.readFile ./iohk-nix.json);
21 in builtins.fetchTarball {
22 url = "${spec.url}/archive/${spec.rev}.tar.gz";
23 inherit (spec) sha256;
24 }) {};
26 pkgs = iohkNix.pkgs;
27 lib = pkgs.lib;
28in lib // { inherit iohkNix pkgs; inherit (iohkNix) nix-tools; }
29```
31iohk-nix.json
32```json
34 "url": "https://github.com/input-output-hk/iohk-nix",
35 "rev": "c92f0119ef5814b0ed1f445c2fdcf8894e326294",
36 "sha256": "05r90x6x3yp1nb66rkc4n0i8q15c634rrdsr2zvb118s3sdcmmrm",
37 "fetchSubmodules": false
39```
41nix/pkgs.nix
42```
43{ pkgs ? import <nixpkgs> {}
44, iohk-extras ? {}
45, iohk-module ? {}
46, haskell
47, hackage
48, stackage
49, ...
50}:
51let
52 # our packages
53 stack-pkgs = import ./.stack-pkgs.nix;
55 # Build the packageset with module support.
56 # We can essentially override anything in the modules
57 # section.
58 #
59 # packages.cbors.patches = [ ./one.patch ];
60 # packages.cbors.flags.optimize-gmp = false;
61 #
62 compiler = (stack-pkgs.extras hackage).compiler.nix-name;
63 pkgSet = haskell.mkNewPkgSet {
64 inherit pkgs;
65 pkg-def = stackage.${stack-pkgs.resolver};
66 # These extras allow extension or restriction of the set of
67 # packages we are interested in. By using the stack-pkgs.extras
68 # we restrict our package set to the ones provided in stack.yaml.
69 pkg-def-extras = [
70 stack-pkgs.extras
71 iohk-extras.${compiler}
72 ];
73 # package customizations
74 modules = [
75 # This module will ensure that we get the necessary
76 # patches ontop of GHC packages that for which the
77 # ones that GHC ships are not identical to the ones
78 # we find on hackage. These patches will make sure
79 # they are identical by augmenting the packages on
80 # hackage to match those that ship with ghc.
81 haskell.ghcHackagePatches.${compiler}
83 # the iohk-module will supply us with the necessary
84 # cross compilation plumbing to make Template Haskell
85 # work when cross compiling. For now we need to
86 # list the packages that require template haskell
87 # explicity here.
88 iohk-module
89 ];
90 };
91in
92 pkgSet.config.hsPkgs // { _config = pkgSet.config; }
93```
96default.nix
97```
98let
99 localLib = import ./lib.nix;
100in
101# This file needs to export a function that takes
102# the arguments it is passed and forwards them to
103# the default-nix template from iohk-nix. This is
104# important so that the release.nix file can properly
105# parameterize this file when targetting different
106# hosts.
107{ ... }@args:
108# We will instantiate the defaul-nix template with the
109# nix/pkgs.nix file...
110localLib.nix-tools.default-nix ./nix/pkgs.nix args
111# ... and add a few custom packages as well.
112// { }
113```