Skip to content

Commit dd0a035

Browse files
authored
Update getting-started.md (#2138)
1 parent cd09879 commit dd0a035

File tree

1 file changed

+9
-83
lines changed

1 file changed

+9
-83
lines changed

docs/tutorials/getting-started.md

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The first steps are to ensure you have [Nix](https://nixos.org/download.html) in
66

77
Then you have the choice to set-up your project using [the experimental Flake feature](#create-a-project-using-flakes) or [Niv](#create-a-project-using-niv), which are 2 ways to pin `nixpkgs` with Nix.
88

9-
If you have an existing Haskell project that you want to build with `haskell.nix`. you might [prefer to use `hix`](#getting-started-with-hix).
9+
If you have an existing Haskell project that you want to build with `haskell.nix`, you might [prefer to use `hix`](#getting-started-with-hix). `hix` is a more easy and user-friendly way to use `haskell.nix`, using it reduce considerably the size of the Nix expression you will have to maintain in your project codebase.
1010

1111
## Setting up the binary cache
1212

@@ -46,7 +46,7 @@ This can be tricky to get setup properly. If you're still having trouble getting
4646

4747
## Create a project using Flakes
4848

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 Uncyclo](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).
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 Uncyclo](https://nixos.wiki/wiki/Flakes) for more instructions.
5050

5151
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
5252
regular `nix` tools. This template is defined in the [NixOS/templates repository](https://github.com/NixOS/templates/tree/master/haskell.nix).
@@ -72,59 +72,14 @@ To build and run a component:
7272
nix run .#hello:exe:hello
7373
```
7474

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:
95-
```nix
96-
let sources = {
97-
haskellNix = builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz";
98-
};
99-
```
100-
101-
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.
106-
```nix
107-
let sources = {
108-
haskellNix = builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/f1a94a4c82a2ab999a67c3b84269da78d89f0075.tar.gz";
109-
};
110-
```
111-
112-
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-
11475
## Scaffolding
11576

11677
The following code could be capy-pasted and will work with `stack.yaml` and `cabal.project` based projects.
11778

118-
For a Flakes-based project, use a `flake.nix`:
119-
```nix
79+
Edit your `flake.nix` as:```nix
12080
{{#include getting-started-flakes/flake.nix}}
12181
```
12282
123-
For a legacy (Nix) Nix project rather, use a `default.nix`:
124-
```nix
125-
{{#include getting-started/default.nix}}
126-
```
127-
12883
> **Note:** Git dependencies
12984
>
13085
> If you have git dependencies in your project, you'll need to [calculate sha256 hashes for them](./source-repository-hashes.md).
@@ -136,32 +91,14 @@ Top-level attributes are Haskell packages (incl. dependencies) part of your proj
13691
This section will show side by side the commands using Flakes experimental `new-command` API and legacy Nix commands.
13792
13893
To build the library component of a package in the project run:
139-
140-
* With flakes experimental commands:
141-
```shell
142-
nix build .#your-package-name:lib:your-package-name
143-
```
144-
* With Nix legacy commands:
145-
```shell
146-
nix-build -A your-package-name.components.library
147-
```
94+
```shell
95+
nix build .#your-package-name:lib:your-package-name
96+
```
14897

14998
There are also other components such as `exes`, `tests`, `benchmarks` and `all`.
15099
To build an executable:
151-
152-
* With flakes experimental commands:
153-
```shell
154-
nix build .#your-package-name:exe:your-exe-name
155-
```
156-
* With Nix legacy commands:
157-
```shell
158-
nix-build -A your-package-name.components.exes.your-exe-name
159-
```
160-
161-
Cross compilation is builtins into Flakes, but to cross-compile with legacy Nix commands, use the `projectCross` attribute:
162-
```
163-
nix-build -A projectCross.ghcjs.hsPkgs.your-package-name.components.exes.your-exe-name
164-
nix-build -A projectCross.mingwW64.hsPkgs.your-package-name.components.exes.your-exe-name
100+
```shell
101+
nix build .#your-package-name:exe:your-exe-name
165102
```
166103

167104
Flakes provide a `devShell` attribute that allow you to spawn a developer shell, here with `cabal`, `hlint` and `haskell-language-server`:
@@ -171,17 +108,6 @@ cabal repl your-package-name:lib:your-package-name
171108
cabal build your-package-name
172109
```
173110

174-
Nix legacy commands needs you to add first a `shell.nix`:
175-
```nix
176-
{{#include getting-started/shell.nix}}
177-
```
178-
Then you can run:
179-
```shell
180-
nix-shell
181-
cabal new-repl your-package-name:library:your-package-name
182-
cabal new-build your-package-name
183-
```
184-
185111
To open a shell for use with `stack` see [the following issue](https://github.com/input-output-hk/haskell.nix/issues/689#issuecomment-643832619).
186112

187113
## Getting started with Hix
@@ -253,4 +179,4 @@ hix-build -A hsPkgs.hello.components.exes.hello
253179

254180
Read through [project](../reference/library.md#project) function reference to see how the API works.
255181

256-
There are a number of things to explore further in the tutorials section.
182+
There are a number of things to explore further in the tutorials section.

0 commit comments

Comments
 (0)