-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
264 lines (243 loc) · 8.72 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
{
description = "Yet another … yet another recursion scheme library for Haskell";
nixConfig = {
## https://github.com/NixOS/rfcs/blob/master/rfcs/0045-deprecate-url-syntax.md
extra-experimental-features = ["no-url-literals"];
extra-substituters = ["https://cache.garnix.io"];
extra-trusted-public-keys = [
"cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="
];
## Isolate the build.
sandbox = "relaxed";
use-registries = false;
};
### This is a complicated flake. Here’s the rundown:
###
### overlays.default – includes all of the packages from cabal.project
### packages = {
### default = points to `packages.${defaultGhcVersion}`
### <ghcVersion>-<cabal-package> = an individual package compiled for one
### GHC version
### <ghcVersion>-all = all of the packages in cabal.project compiled for one
### GHC version
### };
### devShells = {
### default = points to `devShells.${defaultGhcVersion}`
### <ghcVersion> = a shell providing all of the dependencies for all
### packages in cabal.project compiled for one GHC version
### };
### checks.format = verify that code matches Ormolu expectations
outputs = {
flake-utils,
flaky,
flaky-haskell,
nixpkgs,
self,
systems,
}: let
pname = "yaya";
supportedSystems = import systems;
cabalPackages = pkgs: hpkgs:
flaky-haskell.lib.cabalProject2nix
./cabal.project
pkgs
hpkgs
(old: {
configureFlags = old.configureFlags ++ ["--ghc-options=-Werror"];
});
in
{
schemas = {
inherit
(flaky.schemas)
overlays
homeConfigurations
packages
devShells
projectConfigurations
checks
formatter
;
};
# see these issues and discussions:
# - NixOS/nixpkgs#16394
# - NixOS/nixpkgs#25887
# - NixOS/nixpkgs#26561
# - https://discourse.nixos.org/t/nix-haskell-development-2020/6170
overlays = {
default = final: prev:
flaky-haskell.lib.overlayHaskellPackages
(map self.lib.nixifyGhcVersion
(self.lib.supportedGhcVersions final.system))
(final: prev:
nixpkgs.lib.composeManyExtensions [
## TODO: I think this overlay is only needed by formatters,
## devShells, etc., so it shouldn’t be included in the
## standard overlay.
(flaky.overlays.haskellDependencies final prev)
(self.overlays.haskell final prev)
(self.overlays.haskellDependencies final prev)
])
final
prev;
haskell = flaky-haskell.lib.haskellOverlay cabalPackages;
## NB: Dependencies that are overridden because they are broken in
## Nixpkgs should be pushed upstream to Flaky. This is for
## dependencies that we override for reasons local to the project.
haskellDependencies = final: prev: hfinal: hprev: {};
};
homeConfigurations =
builtins.listToAttrs
(builtins.map
(flaky.lib.homeConfigurations.example self [
({pkgs, ...}: {
home.packages = [
(pkgs.haskellPackages.ghcWithPackages (hpkgs: [
hpkgs.${pname}
hpkgs."${pname}-containers"
hpkgs."${pname}-hedgehog"
hpkgs."${pname}-quickcheck"
hpkgs."${pname}-unsafe"
]))
];
})
])
supportedSystems);
lib = {
nixifyGhcVersion = version:
"ghc" + nixpkgs.lib.replaceStrings ["."] [""] version;
## TODO: Extract this automatically from `pkgs.haskellPackages`.
defaultGhcVersion = "9.6.5";
## Test the oldest revision possible for each minor release. If it’s not
## available in nixpkgs, test the oldest available, then try an older
## one via GitHub workflow. Additionally, check any revisions that have
## explicit conditionalization. And check whatever version `pkgs.ghc`
## maps to in the nixpkgs we depend on.
testedGhcVersions = system: [
self.lib.defaultGhcVersion
"8.10.7"
"9.0.2"
"9.2.5"
"9.4.5"
"9.6.3"
"9.8.1"
"9.10.1"
# "ghcHEAD" # doctest doesn’t work on current HEAD
];
## The versions that are older than those supported by Nix that we
## prefer to test against.
nonNixTestedGhcVersions = [
# `(->)` isn’t a type constructor before GHC 8.6.
"8.6.1"
"8.8.1"
"8.10.1"
"9.0.1"
"9.2.1"
"9.4.1"
"9.6.1"
## since `cabal-plan-bounds` doesn’t work under Nix
"9.8.1"
"9.10.1"
];
## However, provide packages in the default overlay for _every_
## supported version.
supportedGhcVersions = system:
self.lib.testedGhcVersions system
++ [
"9.2.6"
"9.2.7"
"9.2.8"
"9.4.6"
"9.4.7"
"9.4.8"
"9.6.4"
"9.6.5"
"9.8.2"
];
## These are versions that we don’t build against, but that we want the
## Haskell packages to support anyway. Mostly, this is for local
## packages where `--perfer-oldest` and `--allow-newer` have no effect,
## so reasonable bounds need to be managed manually.
##
## These also currently need to be restricted so that they work for all
## packages that have them as dependencies. E.g., most packages require
## `yaya ^>= 0.5.0`, but `yaya-unsafe` requires `yaya ^>= 0.5.1`, so
## this must specify `yaya-0.5.1.0`, not `yaya-0.5.0.0`.
extraDependencyVersions = [
"yaya-0.5.1.0"
"yaya-0.6.0.0"
"yaya-hedgehog-0.2.1.0"
"yaya-hedgehog-0.3.0.0"
## This is the version used by Nix, so we can’t have
## `cabal-plan-bounds` throw it out.
"th-abstraction-0.5.0.0"
];
githubSystems = [
"macos-13" # x86_64-darwin
"macos-14" # aarch64-darwin
"ubuntu-24.04" # x86_64-linux
"windows-2022"
];
};
}
// flake-utils.lib.eachSystem supportedSystems
(system: let
pkgs = nixpkgs.legacyPackages.${system}.appendOverlays [
flaky.overlays.dependencies
## NB: This uses `self.overlays.default` because packages need to be
## able to find other packages in this flake as dependencies.
self.overlays.default
];
in {
packages =
{
default =
self.packages.${system}."${self.lib.nixifyGhcVersion self.lib.defaultGhcVersion}_all";
}
// flaky-haskell.lib.mkPackages
pkgs
(map self.lib.nixifyGhcVersion (self.lib.supportedGhcVersions system))
cabalPackages;
devShells =
{
default =
self.devShells.${system}.${self.lib.nixifyGhcVersion self.lib.defaultGhcVersion};
}
// flaky-haskell.lib.mkDevShells
pkgs
(map self.lib.nixifyGhcVersion (self.lib.supportedGhcVersions system))
cabalPackages
(hpkgs:
[self.projectConfigurations.${system}.packages.path]
## NB: Haskell Language Server no longer supports GHC <9.2, and 9.4
## has an issue with it on i686-linux.
## TODO: Remove the restriction on GHC 9.10 once
## https://github.com/NixOS/nixpkgs/commit/e87381d634cb1ddd2bd7e121c44fbc926a8c026a
## finds its way into 24.05.
++ nixpkgs.lib.optional
(
(
if system == "i686-linux"
then nixpkgs.lib.versionAtLeast hpkgs.ghc.version "9.4"
else nixpkgs.lib.versionAtLeast hpkgs.ghc.version "9.2"
)
&& nixpkgs.lib.versionOlder hpkgs.ghc.version "9.10"
)
hpkgs.haskell-language-server);
projectConfigurations =
flaky.lib.projectConfigurations.haskell {inherit pkgs self;};
checks = self.projectConfigurations.${system}.checks;
formatter = self.projectConfigurations.${system}.formatter;
});
inputs = {
## Flaky should generally be the source of truth for its inputs.
flaky.url = "github:sellout/flaky";
flake-utils.follows = "flaky/flake-utils";
nixpkgs.follows = "flaky/nixpkgs";
systems.follows = "flaky/systems";
flaky-haskell = {
inputs.flaky.follows = "flaky";
url = "github:sellout/flaky-haskell";
};
};
}