67 lines
1.6 KiB
Markdown
67 lines
1.6 KiB
Markdown
# Haskell Shell with shellFor
|
|
|
|
This note covers `06-haskell-shellfor/`, which builds a local Haskell package and constructs the dev shell with `shellFor` instead of `mkShell`.
|
|
|
|
---
|
|
|
|
## 1. What `shellFor` Changes
|
|
|
|
`mkShell` is a generic shell constructor. You list tools manually.
|
|
|
|
`shellFor` is specific to Haskell package sets. It starts from one or more Haskell packages and builds a development environment around their dependencies.
|
|
|
|
That means the shell tracks the package definition more closely. When the package's Haskell dependencies change, the shell changes with it.
|
|
|
|
---
|
|
|
|
## 2. Why the Package Set Override Exists
|
|
|
|
The example adds the local package to the Haskell package set first:
|
|
|
|
```nix
|
|
haskellPackages = pkgs.haskellPackages.override {
|
|
overrides = final: _: {
|
|
mini-shellfor = final.callCabal2nix "mini-shellfor" ./. { };
|
|
};
|
|
};
|
|
```
|
|
|
|
`shellFor` expects packages from the package set it is working with. Defining `mini-shellfor` inside that set makes it available both as a normal package output and as a package that `shellFor` can reference.
|
|
|
|
---
|
|
|
|
## 3. The Dev Shell
|
|
|
|
The shell itself is small:
|
|
|
|
```nix
|
|
devShells.${system}.default = haskellPackages.shellFor {
|
|
packages = hp: [ hp.mini-shellfor ];
|
|
|
|
nativeBuildInputs = [
|
|
pkgs.cabal-install
|
|
pkgs.haskell-language-server
|
|
];
|
|
};
|
|
```
|
|
|
|
`packages = hp: [ hp.mini-shellfor ];` tells `shellFor` which Haskell package should drive the environment. `nativeBuildInputs` adds the interactive tools you still want on top.
|
|
|
|
---
|
|
|
|
## 4. Commands to Try
|
|
|
|
```bash
|
|
cd 06-haskell-shellfor
|
|
|
|
nix develop
|
|
cabal run
|
|
cabal test
|
|
|
|
nix build
|
|
./result/bin/mini-shellfor
|
|
|
|
nix run
|
|
nix flake check
|
|
```
|