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: README.md
+32-24Lines changed: 32 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,37 +4,45 @@ This is an example Haskell project using Nix to setup a development environment.
4
4
5
5
This uses Nix and Cabal without Stack. This is because when using Nix, you don't need Stack, as Nix provides harmonious snapshots of Haskell packages. However Stack users can still develop on this project, they just have to generate an appropriate `stack.yaml` from the Cabal file.
6
6
7
-
The first step is that we have to acquire `cabal2nix`, which we use to generate a `cabal.nix` file from the `package.yaml`. Note that the usage of `package.yaml` means we are using the [hpack format](https://github.com/sol/hpack). This format is transformed to a cabal file via the `hpack` command.
7
+
The first step is that we have to acquire `cabal2nix`, which we use to generate a `default.nix` file from the `package.yaml`. Note that the usage of `package.yaml` means we are using the [hpack format](https://github.com/sol/hpack). This format is transformed to a cabal file via the `hpack` command.
8
8
9
9
```sh
10
10
nix-shell -p cabal2nix
11
11
# using --hpack ensures that we always use package.yaml
12
-
cabal2nix --hpack .>./cabal.nix
12
+
cabal2nix --hpack .>./default.nix
13
13
```
14
14
15
15
The above command is also executed at the beginning of the `shellHook`.
16
16
17
-
This `cabal.nix` will be imported by the `default.nix` to be used as the core derivation. Unlike other `*2nix` tools, this still retains package sharing, because the generated `cabal.nix` expects the current package's dependencies to be passed down from a higher level package set.
18
-
19
17
If this is the first time you've ran `cabal`, then run `cabal update` to get the latest package list in `~/.cabal`.
@@ -53,25 +61,25 @@ The `cabal-install` package installs the `cabal` command. This command and assoc
53
61
54
62
To use `cabal`, you need to generate the cabal file from the `package.yaml`. You can do this by running `hpack`. However this is also executed as part of the `shellHook`.
55
63
56
-
At this point, you need to run `cabal configure`. This will create a `dist` directory that will contain any build artifacts. This is also executed as part of the `shellHook`.
64
+
At this point, you need to run `cabal v2-configure`. This will create a `dist` directory that will contain any build artifacts. This is also executed as part of the `shellHook`.
57
65
58
66
It's important to read the guide for Cabal as this is information relevant to the Haskell ecosystem: https://www.haskell.org/cabal/users-guide/developing-packages.html
59
67
60
68
The most important commands are:
61
69
62
70
```sh
63
71
# this will launch GHCI for a given target
64
-
cabal repl
72
+
cabal v2-repl
65
73
# this will build the executable and library and put them into ./dist
66
-
cabal build
74
+
cabal v2-build
67
75
# this will run the executable (you can pass the name of the executable)
68
-
cabal run
76
+
cabal v2-run
69
77
# this will run the tests
70
-
cabal test
78
+
cabal v2-test
71
79
# deletes ./dist
72
-
cabal clean
80
+
cabal v2-clean
73
81
# this will install the executable into the ~/.cabal/bin
74
-
cabal install
82
+
cabal v2-install
75
83
```
76
84
77
85
Once you have finished developing, you can build the package using:
@@ -100,15 +108,15 @@ Remember that Haskell package versions conventionally use `Major.Major.Minor.Pat
100
108
101
109
## Using GHCi (or `cabal repl` or `stack ghci`)
102
110
103
-
The `cabal repl` only works against the build targets specified in the `package.yaml`. You have to specify the target name:
111
+
The `cabal v2-repl` only works against the build targets specified in the `package.yaml`. You have to specify the target name:
104
112
105
113
```sh
106
114
# targets the library
107
-
cabal repl haskell-demo
115
+
cabal v2-repl haskell-demo
108
116
# targets the executable (which depends on the library)
109
-
cabal repl haskell-demo-exe
117
+
cabal v2-repl haskell-demo-exe
110
118
# targets the tests (which depends on the library)
111
-
cabal repl haskell-demo-test
119
+
cabal v2-repl haskell-demo-test
112
120
```
113
121
114
122
However you need to understand how modules work in GHCi to use the REPL well. The documentation here explains the necessary commands: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html#what-s-really-in-scope-at-the-prompt
0 commit comments