@@ -35,6 +35,33 @@ nix.binaryCaches = [
36This can be tricky to get setup properly. If you're still having trouble getting cache hits, consult the corresponding [troubleshooting section](../../troubleshooting#why-am-i-building-ghc).
36This can be tricky to get setup properly. If you're still having trouble getting cache hits, consult the corresponding [troubleshooting section](../../troubleshooting#why-am-i-building-ghc).
40+[Niv](https://github.com/nmattia/niv) is a command line tool for keeping tack of Nix project dependencies.
42+This guide assumes that the `sources.haskellNix` will be set to point
43+a pinned copy of the haskell.nix github repo. One easy way to do this
44+is to use Niv. If you prefer not to use Niv another option is described
45+in the in the "Using haskell.nix without niv" section of this document.
47+If you want to use Nix Flakes to pin your dependencies then you should
48+consider following the [Getting started with flakes](./getting-started-flakes.md)
49+document instead of this one.
51+After installing niv you can initialize niv and pin the latest haskell.nix
52+commit by running the following in the root directory of the project:
56+niv add input-output-hk/haskell.nix -n haskellNix
59+Then when you want to update to the latest version of haskellNix use:
38## Scaffolding
65## Scaffolding
40The following work with `stack.yaml` and `cabal.project` based
67The following work with `stack.yaml` and `cabal.project` based
@@ -43,21 +70,28 @@ projects.
43Add `default.nix`:
70Add `default.nix`:
74+ # Read in the Niv sources
75+ sources = import ./nix/sources.nix {};
76+ # If ./nix/sources.nix file is not found run:
78+ # niv add input-output-hk/haskell.nix -n haskellNix
46−{ # Fetch the latest haskell.nix and import its default.nix
80+ # Fetch the haskell.nix commit we have pinned with Niv
47− haskellNix ? import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz") {}
81+ haskellNix = import sources.haskellNix {};
48−
82+ # If haskellNix is not found run:
83+ # niv add input-output-hk/haskell.nix -n haskellNix
85+ # Import nixpkgs and pass the haskell.nix provided nixpkgsArgs
49−# haskell.nix provides access to the nixpkgs pins which are used by our CI,
87+ # haskell.nix provides access to the nixpkgs pins which are used by our CI,
50−# hence you will be more likely to get cache hits when using these.
88+ # hence you will be more likely to get cache hits when using these.
51−# But you can also just use your own, e.g. '<nixpkgs>'.
89+ # But you can also just use your own, e.g. '<nixpkgs>'.
52−, nixpkgsSrc ? haskellNix.sources.nixpkgs-2009
90+ haskellNix.sources.nixpkgs-2009
54−# haskell.nix provides some arguments to be passed to nixpkgs, including some
91+ # These arguments passed to nixpkgs, include some patches and also
55−# patches and also the haskell.nix functionality itself as an overlay.
92+ # the haskell.nix functionality itself as an overlay.
56−, nixpkgsArgs ? haskellNix.nixpkgsArgs
93+ haskellNix.nixpkgsArgs;
58−# import nixpkgs with overlays
59−, pkgs ? import nixpkgsSrc nixpkgsArgs
60−}: pkgs.haskell-nix.project {
94+in pkgs.haskell-nix.project {
61 # 'cleanGit' cleans a source directory based on the files known by git
95 # 'cleanGit' cleans a source directory based on the files known by git
62 src = pkgs.haskell-nix.haskellLib.cleanGit {
96 src = pkgs.haskell-nix.haskellLib.cleanGit {
63 name = "haskell-nix-project";
97 name = "haskell-nix-project";
@@ -96,20 +130,40 @@ nix-build -A projectCross.ghcjs.hsPkgs.your-package-name.components.exes.your-ex
96nix-build -A projectCross.mingwW64.hsPkgs.your-package-name.components.exes.your-exe-name
130nix-build -A projectCross.mingwW64.hsPkgs.your-package-name.components.exes.your-exe-name
99−To open a shell for use with `cabal` run:
133+To open a shell for use with `cabal`, `hlint` and `haskell-language-server` add `shell.nix`:
136+(import ./default.nix).shellFor {
140+ haskell-language-server = "latest";
102−nix-shell -A shellFor
148+nix-shell
103cabal new-repl your-package-name:library:your-package-name
149cabal new-repl your-package-name:library:your-package-name
104cabal new-build your-package-name
150cabal new-build your-package-name
107To open a shell for use with `stack` see [the following issue](https://github.com/input-output-hk/haskell.nix/issues/689#issuecomment-643832619).
153To open a shell for use with `stack` see [the following issue](https://github.com/input-output-hk/haskell.nix/issues/689#issuecomment-643832619).
109−### Pinning the [haskell.nix][] version
155+## Using haskell.nix without Niv
111−For simplicity's sake we will use `fetchTarball` for the examples in
157+If you would prefer not to use niv you can replace
158+`sources = import ./nix/sources.nix {};` in the examples with:
162+ haskellNix = builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz";
112−this documentation. This will always get the latest version, and is
166+The `fetchTarball` call above will always get the latest version, and is
113similar to an auto-updating Nix channel.
167similar to an auto-updating Nix channel.
115However, in your own project, you may wish to pin [haskell.nix][] (as
169However, in your own project, you may wish to pin [haskell.nix][] (as
@@ -119,10 +173,9 @@ predictable, and faster (because the fixed version is cached).
119Straightforward way of doing this is to change the branch name to a revision.
173Straightforward way of doing this is to change the branch name to a revision.
122−{ # Fetch a specific haskell.nix and import its default.nix
176+let sources = {
123− haskellNix ? import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/f1a94a4c82a2ab999a67c3b84269da78d89f0075.tar.gz") {}
177+ haskellNix = import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/f1a94a4c82a2ab999a67c3b84269da78d89f0075.tar.gz") {};
128There are other possible schemes for pinning. See
181There are other possible schemes for pinning. See