You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/getting-started.md
+82-8Lines changed: 82 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ This can be tricky to get setup properly. If you're still having trouble getting
46
46
47
47
## Create a project using Flakes
48
48
49
-
This section assumes you choose to uses the experimental flakes features, and so that you have added `experimental-features = [ "nix-command" "flakes" ];` in your Nix configuration. You can look at [the Wiki](https://nixos.wiki/wiki/Flakes) for more instructions.
49
+
This section assumes you choose to uses the experimental flakes features, and so that you have added `experimental-features = [ "nix-command" "flakes" ];` in your Nix configuration. You can look at [the Wiki](https://nixos.wiki/wiki/Flakes) for more instructions. If you don't want to set up a Flakes project, [skip to the Niv section](#create-a-project-using-niv).
50
50
51
51
The following `nix flake init` command creates a template `hello` package containing a `flake.nix` and `nix/hix.nix` file. The project can be used with
52
52
regular `nix` tools. This template is defined in the [NixOS/templates repository](https://github.com/NixOS/templates/tree/master/haskell.nix).
@@ -72,14 +72,59 @@ To build and run a component:
72
72
nix run .#hello:exe:hello
73
73
```
74
74
75
+
## Create a project using Niv
76
+
77
+
[Niv](https://github.com/nmattia/niv) is a command line tool for keeping track of Nix project dependencies. You don't need it if you [set up your project with Flakes](#create-a-project-using-flakes), and so you can skip this section.
78
+
79
+
This guide assumes that the `sources.haskellNix` will be set to point a pinned copy of the `haskell.nix` github repo. One easy way to do this is to use Niv. If you prefer not to use Niv another option is described in the in the following "[Using `haskell.nix` without Niv](#using-1-without-Niv)" section of this document.
80
+
81
+
After installing niv you can initialize niv and pin the latest `haskell.nix` commit by running the following in the root directory of the project:
82
+
```shell
83
+
niv init
84
+
niv add input-output-hk/haskell.nix -n haskellNix
85
+
```
86
+
87
+
Then when you want to update to the latest version of `haskellNix` use:
88
+
```shell
89
+
niv update haskellNix
90
+
```
91
+
92
+
### Using `haskell.nix` without Niv
93
+
94
+
If you would prefer not to use niv you can replace `sources = import ./nix/sources.nix {};` in the examples with:
The `fetchTarball` call above will always get the latest version, and is similar to an auto-updating Nix channel.
102
+
103
+
However, in your own project, you may wish to pin `haskell.nix` (as you would pin Nixpkgs). This will make your builds reproducible, more predictable, and faster (because the fixed version is cached).
104
+
105
+
Straightforward way of doing this is to change the branch name to a revision.
There are other possible schemes for pinning. See [Bumping Hackage and Stackage snapshots](./hackage-stackage.md) and [Nix tutorial on reproducibility using pinning](https://nix.dev/tutorials/towards-reproducibility-pinning-nixpkgs.html).
113
+
75
114
## Scaffolding
76
115
77
116
The following code could be capy-pasted and will work with `stack.yaml` and `cabal.project` based projects.
78
117
79
-
Edit your `flake.nix` as:```nix
118
+
For a Flakes-based project, use a `flake.nix`:
119
+
```nix
80
120
{{#include getting-started-flakes/flake.nix}}
81
121
```
82
122
123
+
For a legacy (Nix) Nix project rather, use a `default.nix`:
124
+
```nix
125
+
{{#include getting-started/default.nix}}
126
+
```
127
+
83
128
> **Note:** Git dependencies
84
129
>
85
130
> If you have git dependencies in your project, you'll need to [calculate sha256 hashes for them](./source-repository-hashes.md).
@@ -91,14 +136,32 @@ Top-level attributes are Haskell packages (incl. dependencies) part of your proj
91
136
This section will show side by side the commands using Flakes experimental `new-command` API and legacy Nix commands.
92
137
93
138
To build the library component of a package in the project run:
0 commit comments