Skip to content

Commit ad934f1

Browse files
authored
Cleanup nix files (#1827)
Drop the classic nix in favor of flakes
1 parent a6cbb9c commit ad934f1

File tree

13 files changed

+101
-269
lines changed

13 files changed

+101
-269
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ stack test # Run all the tests
1818
Or `nix`:
1919

2020
```shell
21-
nix-shell nix/shell.nix # Enter a new development shell with Cabal and Stack
21+
nix develop # Enter a new development shell with Cabal and Stack
2222

23-
# Alternatively, another version of GHC can be used. See nix/README.md for more info.
24-
nix-shell nix/shell.nix --argstr compiler ghc901
23+
# Alternatively, another version of GHC can be used.
24+
# See `flake.nix` for all available shells.
25+
nix develop '#ghc96'
2526
```
2627

2728
To build the docs, see `doc/README.md`.

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ You can see the visualised results at https://www.techempower.com/benchmarks/#se
6666

6767
## Nix
6868

69-
A developer shell.nix file is provided in the `nix` directory
69+
A developer `flake.nix` file is provided in the root directory.
7070

71-
See [nix/README.md](nix/README.md)
71+
Default shell will provide you with tools and dependencies needed to build servant packages.
72+
73+
```sh
74+
$ nix develop
75+
```
76+
77+
For the tutorial and the cookbook you can use `tutorial` shell.
78+
79+
```sh
80+
$ nix develop '#tutorial'
81+
```
82+
83+
You can also choose a different GHC version.
84+
85+
```sh
86+
$ nix develop '#ghc96'
87+
```

default.nix

Lines changed: 0 additions & 38 deletions
This file was deleted.

doc/tutorial/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ nix
3838
--------
3939

4040
`Nix <https://nixos.org/nix/>`_ users should feel free to take a look at
41-
the `nix/shell.nix` file in the repository and use it to provision a suitable
41+
the `flake.nix` file in the repository and use it to provision a suitable
4242
environment to build and run the examples.
4343

4444
Note for Ubuntu users

flake.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,94 @@
22
description = "Servant development environment";
33

44
inputs = {
5-
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin";
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-25.05-darwin";
66
flake-utils.url = "github:numtide/flake-utils";
77
};
88

9-
outputs = { self, nixpkgs, flake-utils }:
10-
flake-utils.lib.eachDefaultSystem (system:
9+
outputs =
10+
{
11+
self,
12+
nixpkgs,
13+
flake-utils,
14+
}:
15+
flake-utils.lib.eachDefaultSystem (
16+
system:
1117
let
1218
pkgs = import nixpkgs { inherit system; };
1319

14-
mkDevShell = { compiler ? "ghc92", tutorial ? false }:
20+
# We use fourmolu compiled with GHC 9.12
21+
# as getting it to compile with lower GHC versions
22+
# is complicated and this works out of the box.
23+
haskellFormatter = pkgs.haskell.packages.ghc912.fourmolu_0_18_0_0;
24+
haskellLinter = pkgs.hlint;
25+
26+
nixFormatter = pkgs.nixfmt-rfc-style;
27+
28+
mkDevShell =
29+
{
30+
compiler ? "ghc92",
31+
tutorial ? false,
32+
}:
1533
let
16-
ghc = pkgs.haskell.packages.${compiler}.ghcWithPackages (_: []);
17-
docstuffs = pkgs.python3.withPackages (ps: with ps; [ recommonmark sphinx sphinx_rtd_theme ]);
34+
ghc = pkgs.haskell.packages.${compiler}.ghcWithPackages (ghcPkg: [
35+
# Some dependencies don't like being built with
36+
# as part of a project, so we pull them from nix.
37+
ghcPkg.zlib
38+
ghcPkg.lzma
39+
]);
40+
docstuffs = pkgs.python3.withPackages (
41+
ps: with ps; [
42+
recommonmark
43+
sphinx
44+
sphinx_rtd_theme
45+
]
46+
);
1847
in
1948
pkgs.mkShell {
20-
buildInputs = with pkgs; [
21-
ghc
22-
zlib
23-
python3
24-
wget
25-
cabal-install
26-
postgresql
27-
openssl
28-
stack
29-
haskellPackages.hspec-discover
30-
] ++ (if tutorial then [docstuffs postgresql] else []);
31-
32-
shellHook = ''
33-
eval $(grep export ${ghc}/bin/ghc)
34-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"${pkgs.zlib}/lib";
35-
'';
49+
buildInputs =
50+
with pkgs;
51+
[
52+
ghc
53+
python3
54+
wget
55+
cabal-install
56+
postgresql
57+
openssl
58+
stack
59+
haskellPackages.hspec-discover
60+
haskellFormatter
61+
haskellLinter
62+
nixFormatter
63+
]
64+
++ (
65+
if tutorial then
66+
[
67+
docstuffs
68+
postgresql
69+
]
70+
else
71+
[ ]
72+
);
3673
};
74+
75+
mkCiShell = tools: pkgs.mkShell { buildInputs = tools; };
3776
in
3877
{
3978
devShells = {
40-
default = mkDevShell {};
79+
default = mkDevShell { };
4180
tutorial = mkDevShell { tutorial = true; };
81+
82+
# Development shells for different GHC versions.
83+
ghc92 = mkDevShell { compiler = "ghc92"; };
84+
ghc94 = mkDevShell { compiler = "ghc94"; };
85+
ghc96 = mkDevShell { compiler = "ghc96"; };
86+
ghc98 = mkDevShell { compiler = "ghc98"; };
87+
ghc910 = mkDevShell { compiler = "ghc910"; };
88+
ghc912 = mkDevShell { compiler = "ghc912"; };
89+
90+
# Single-tool shells for CI checks.
91+
haskellFormatter = mkCiShell [ haskellFormatter ];
92+
haskellLinter = mkCiShell [ haskellLinter ];
4293
};
4394
}
4495
);

ghcjs.nix

Lines changed: 0 additions & 30 deletions
This file was deleted.

nix/README.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

nix/nixpkgs.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

nix/nixpkgs.nix

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)