Skip to content

Commit 02b3ef8

Browse files
committed
Update shellFor documentation
Fixes #2401
1 parent 4b2a8d5 commit 02b3ef8

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed

changelog.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
This file contains a summary of changes to Haskell.nix and `nix-tools`
22
that will impact users.
33

4+
## Jul 3, 2025
5+
6+
Some time ago the behavior of `shellFor` changed so that the arguments
7+
are now checked against `modules/shell.nix`. This was done as part of a fix
8+
for bugs in the way `shellFor` arguments and project `shell` arguments
9+
interacted (both are now `modules` and the normal module merge rules apply).
10+
11+
This means it is no longer possible to pass arbitrarily named arguments
12+
to `shellFor` in order to set environment variables.
13+
14+
Instead of:
15+
16+
```
17+
p.shellFor {
18+
FOO = "bar";
19+
}
20+
```
21+
22+
Use:
23+
24+
```
25+
p.shellFor {
26+
shellHook = ''
27+
export FOO="bar"
28+
'';
29+
}
30+
```
31+
32+
or
33+
34+
```
35+
(p.shellFor {}).overrideAttrs {
36+
FOO = "bar";
37+
}
38+
```
39+
440
## Jan 29, 2025
541

642
Removed GHC <9.6 from CI.

docs/reference/library.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,18 +428,62 @@ shellFor =
428428
{ packages, withHoogle ? true, exactDeps ? false, ...}: ...
429429
```
430430

431-
432431
| Argument | Type | Description |
433432
|----------------|------|---------------------|
433+
| `name` | String | Name of the derivation |
434434
| `packages` | Function | Package selection function. It takes a list of [Haskell packages](#haskell-package) and returns a subset of these packages. |
435435
| `components` | Function | Similar to `packages`, by default all the components of the selected packages are selected. |
436436
| `additional` | Function | Similar to `packages`, but the selected packages are built and included in `ghc-pkg list` (not just their dependencies). |
437437
| `withHoogle` | Boolean | Whether to build a Hoogle documentation index and provide the `hoogle` command. |
438438
| `exactDeps` | Boolean | Prevents the Cabal solver from choosing any package dependency other than what are in the package set. |
439+
| `allToolDeps` | Boolean | Indicates if the shell should include all the tool dependencies of the haskell packages in the project. |
439440
| `tools` | Function | AttrSet of tools to make available e.g. `{ cabal = "3.2.0.0"; }` or `{ cabal = { version = "3.2.0.0"; }; }`. If an AttrSet is provided for a tool, the additional arguments will be passed to the function creating the derivation for that tool. So you can provide an `index-state` or a `materialized` argument like that `{ cabal = { version = "3.2.0.0"; index-state = "2020-10-30T00:00:00Z"; materialized = ./cabal.materialized; }; }` for example. You can specify and materialize the version of hoogle used to construct the hoogle index by including something like `{ hoogle = { version = "5.0.17.15"; index-state = "2020-05-31T00:00:00Z"; materialized = ./hoogle.materialized; }`. Uses a default version of hoogle if omitted. |
440-
| `inputsFrom` | List | List of other shells to include in this one. The `buildInputs` and `nativeBuildInputs` of each will be included using [mkShell](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell).
441+
| `packageSetupDeps` | Boolean | Set this to `false` to exclude custom-setup dependencies.
442+
| `enableDWARF` | Boolean | Include debug info |
441443
| `crossPlatforms` | Function | Platform selection function for cross compilation targets to support eg. `ps: with ps; [ghcjs mingwW64]` (see nixpkgs lib.systems.examples for list of platform names). |
442-
| `{ ... }` | Attrset | All the other arguments are passed to [`mkDerivation`](https://nixos.org/nixpkgs/manual/#sec-using-stdenv). |
444+
| `inputsFrom` | List | List of other shells to include in this one. The `buildInputs` and `nativeBuildInputs` of each will be included using [mkShell](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell).
445+
| `shellHook` | String | Bash statements that are executed when the shell starts. |
446+
| `buildInputs` | | Passed to [`mkDerivation`](https://nixos.org/nixpkgs/manual/#sec-using-stdenv) (via [mkShell](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell)). |
447+
| `nativeBuildInputs` | | Passed to [`mkDerivation`](https://nixos.org/nixpkgs/manual/#sec-using-stdenv) (via [mkShell](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell)). |
448+
| `passthru` | | Passed to [`mkDerivation`](https://nixos.org/nixpkgs/manual/#sec-using-stdenv) (via [mkShell](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell)). |
449+
450+
The arguments are checked using the module `modules/shell.nix`.
451+
452+
To set environment variables in the shell use:
453+
454+
```
455+
shellHook = ''
456+
export FOO="bar"
457+
'';
458+
```
459+
460+
or
461+
462+
```
463+
(p.shellFor {}).overrideAttrs {
464+
FOO = "bar";
465+
}
466+
```
467+
468+
The `shellFor` argments can also be passed to to the project `shell`
469+
argument. For instance:
470+
471+
```
472+
(pkgs.haskell-nix.project {
473+
...
474+
shell.tools.cabal = {}
475+
).shellFor {}
476+
```
477+
478+
Is the same as:
479+
480+
```
481+
(pkgs.haskell-nix.project {
482+
...
483+
).shellFor {
484+
tools.cabal = {}
485+
}
486+
```
443487

444488
**Return value**: a derivation
445489

modules/shell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
default = !config.exactDeps;
3535
description = ''
3636
Indicates if the shell should include all the tool dependencies
37-
of in the haskell packages in the project. Defaulted to `false` in
37+
of the haskell packages in the project. Defaulted to `false` in
3838
stack projects (to avoid trying to build the tools used by
3939
every `stackage` package).
4040
'';

0 commit comments

Comments
 (0)