-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
357 lines (339 loc) · 13.3 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
{
nixConfig.substituters = [
"https://cache.nixos.org"
"https://stackage-infrastructure.cachix.org"
];
nixConfig.trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"stackage-infrastructure.cachix.org-1:R3E1FYE8IKCNbUWCvVhsnlLJ4FC6onEQLhQX2kY0ufQ="
];
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-2311.url = "github:nixos/nixpkgs/nixos-23.11";
# LTS 15.6 (GHC 8.8.3)
nixpkgs-2009.url = "github:nixos/nixpkgs/nixos-20.09";
sops-nix.url = "github:Mic92/sops-nix";
disko.url = "github:nix-community/disko";
haskell-certification.url = "github:serokell/haskell-certification";
};
outputs = inputs@{ self, ... }: {
nixosModules.hf-cert-1 = {
imports = [
./hf-cert-1
inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops
inputs.haskell-certification.nixosModules.default
];
};
nixosModules.stackage-builder = { ... }: {
imports = [
# Change this to a flake-defined nixosModule as well?
./stackage-builder/configuration.nix
self.nixosModules.hackage-metadata-refresh
self.nixosModules.hackage-mirror
self.nixosModules.stackage-server
self.nixosModules.casa-server
self.nixosModules.stackage-curator
inputs.sops-nix.nixosModules.sops
{
security.acme.acceptTerms = true;
# FIXME we need a centralized address for this.
security.acme.defaults.email = "[email protected]";
}
{ services.fail2ban.enable = true; }
# This could be a *lot* bigger, but it probably makes more sense to
# forward it to a central log server (even though we don't have one
# yet). I don't know how well journald actually handles huge logs
{ services.journald.extraConfig = "SystemMaxSize=48GB"; }
{ nix.settings.substituters = [
"https://cache.nixos.org"
"https://stackage-infrastructure.cachix.org"
];
nix.settings.trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"stackage-infrastructure.cachix.org-1:R3E1FYE8IKCNbUWCvVhsnlLJ4FC6onEQLhQX2kY0ufQ="
];
}
];
};
devShell.x86_64-linux = inputs.nixpkgs.legacyPackages.x86_64-linux.mkShell {
buildInputs = [ inputs.sops-nix.packages.x86_64-linux.default ];
};
##
## STACKAGE CURATOR
##
nixosModules.stackage-curator = ./stackage-builder/nixos-modules/stackage-curator.nix;
##
## HACKAGE METADATA REFRESH
##
# This overlay is only used to define the all-cabal-tool package. It's only
# exposed because it can be.
overlays.all-cabal-tool =
let
myPackage = "all-cabal-tool";
hsOverlay = pkgs: self: super: {
${myPackage} = pkgs.haskell.lib.buildStackProject {
name = myPackage;
src = pkgs.fetchFromGitHub {
owner = "commercialhaskell";
repo = myPackage;
rev = "189c8fc25859c59808974a5a4b6d1cf7526bda1a";
hash = "sha256-cRMZH/Mjh03GerjYG4kH2d1Y7zt3j3KEnBdnJs9Ss3s=";
};
ghc = pkgs.haskell.compiler.ghc963;
buildInputs = [ pkgs.zlib ];
patches = [ ./stackage-builder/all-cabal-tool_lts-22.4.patch ];
};
};
in final: prev: {
myHaskellPackages = prev.haskellPackages.override {
overrides = hsOverlay final;
};
};
packages.x86_64-linux.all-cabal-tool =
let
myPkgs = import inputs.nixpkgs-2311 {
system = "x86_64-linux"; overlays = [ self.overlays.all-cabal-tool ];
};
in myPkgs.myHaskellPackages.all-cabal-tool;
# This module wraps all-cabal-tool into a systemd service.
nixosModules.hackage-metadata-refresh = { lib, config, pkgs, ... }:
let
name = "hackage-metadata-refresh";
mkRuntimeSecrets = keys:
lib.attrsets.genAttrs
(map (k: "${name}/runtime/${k}") keys)
(_: { owner = name; });
in {
programs.ssh.knownHostsFiles = [ ./github_host_keys ];
users.groups.${name} = {
gid = 1003;
};
users.users.${name} = {
uid = 1003;
isNormalUser = true;
group = name;
home = "/home/${name}";
createHome = true;
};
sops.secrets = {
"${name}/ssh_key" = {
owner = name;
path = "/home/${name}/.ssh/id_rsa";
};
} // mkRuntimeSecrets
[ "aws_access"
"aws_secret"
"s3_bucket"
];
systemd.services.${name} = {
description = "Refresh hackage metadata";
wantedBy = [ "multi-user.target" ];
wants = [ "network.target" ];
after = [ "network.target" ];
serviceConfig = {
User = name;
LoadCredential = "creds:/run/secrets/${name}/runtime";
# sop.secrets provides ~/.gnupg/secring.gpg, but with wrong
# permissions. Fix before starting the unit.
ExecStartPre = [
"+${pkgs.coreutils}/bin/chmod 700 /home/${name}/.gnupg"
"+${pkgs.coreutils}/bin/chown ${name}:${name} /home/${name}/.gnupg"
];
};
script = ''
${self.packages.x86_64-linux.all-cabal-tool}/bin/all-cabal-tool \
--username all-cabal-tool \
--email [email protected] \
--gpg-sign D6CF60FD \
--s3-bucket "$(< "$CREDENTIALS_DIRECTORY/creds_s3_bucket")" \
--aws-access-key "$(< "$CREDENTIALS_DIRECTORY/creds_aws_access")" \
--aws-secret-key "$(< "$CREDENTIALS_DIRECTORY/creds_aws_secret")"
'';
path = [ pkgs.git pkgs.gnupg pkgs.openssh ];
};
};
##
## HACKAGE MIRROR
##
# Same as the other overlay, this is only exposed because it can be. It's
# just used to define the hackage-mirror-tool package.
overlays.hackage-mirror-tool =
let
myPackage = "hackage-mirror-tool";
hsOverlay = pkgs: self: super:
let
amazonkaRepo = {
owner = "brendanhay";
repo = "amazonka";
rev = "85e0289f8dc23c54b00f7f1a09845be7e032a1eb";
sha256 = "sha256-o3TOP+5vOuUELlqZbAn99lxKobh/f6ZnL4Bxflb67dU=";
};
hackageMirrorRepo = {
owner = "chreekat";
repo = myPackage;
rev = "6cfb57885e5e8d7d17cb85531508ae79622cdaae";
sha256 = "sha256-lk687q5ekI5ukBtd2+lXUJN4S4FdSwrGCwQb+JjCEz4=";
};
in {
amazonka-core = pkgs.haskell.lib.compose.overrideSrc
{ src = "${pkgs.fetchFromGitHub amazonkaRepo}/lib/amazonka-core"; }
super.amazonka-core;
# Jailbreak to get around my amazonka>2.0 failsafe
${myPackage} = pkgs.haskell.lib.compose.doJailbreak (self.callCabal2nix
myPackage
(pkgs.fetchFromGitHub hackageMirrorRepo)
{});
};
in final: prev: {
myHaskellPackages = prev.haskellPackages.override {
overrides = hsOverlay final;
};
};
packages.x86_64-linux.hackage-mirror-tool =
let
myPkgs = import inputs.nixpkgs-2311 {
system = "x86_64-linux"; overlays = [ self.overlays.hackage-mirror-tool ];
};
in myPkgs.myHaskellPackages.hackage-mirror-tool;
# Make a service out of hackage-mirror-tool. It doesn't have a loop built
# in, which means we get to control it with systemd (which I appreciate).
nixosModules.hackage-mirror = import ./stackage-builder/nixos-modules/hackage-mirror.nix {
hackage-mirror-tool-app = self.packages.x86_64-linux.hackage-mirror-tool;
};
##
## STACKAGE SERVER
##
##
## Comprised of stackage-server-update and stackage-server itself.
## Just used to define the stackage-server package.
overlays.stackage-server =
let
myPackage = "stackage-server";
hsOverlay = pkgs: self: super: {
# WARNING: Changing the hoogle version causes stackage-server-cron to
# regenerate Hoogle databases FOR EVERY SNAPSHOT, EVER. Usually,
# that's ok! But don't forget! The consequences are: (1) More disk
# usage. Hoogle databases are not cleaned up on the
# stackage-server-cron side, nor on the stackage-server side. (Yet.
# This will change.) (2) More bucket usage. While it's easy to say
# it's a drop in the literal bucket, such excessive misuse of storage
# makes administration, backups, disaster recovery, and many other
# DevOps concerns harder and harder. All but the latest LTS's database
# are literally never used anyway. (3) The Hoogle database schema is
# defined by the first three version components. Any more frequent
# regeneration is pure unadulterated waste. (4) Stackage's Hoogle
# search will be unavailable until the new databases have been
# generated.
${myPackage} = pkgs.haskell.lib.buildStackProject {
name = myPackage;
src = pkgs.fetchFromGitHub {
owner = "commercialhaskell";
repo = myPackage;
rev = "6d6b20e63f149a1459d07ca9b16a54c151c0fa5b";
sha256 = "sha256-M+P+uhxQ0AgLXV0S+UjoCaEnfSTU9v/1GvtUA3Hfhhk=";
# stackage-server uses `gitrev`
leaveDotGit = true;
};
ghc = pkgs.haskell.compiler.ghc963;
buildInputs = [ pkgs.zlib pkgs.openssl pkgs.git pkgs.postgresql ];
# During build, static files are generated into the source tree's
# static/ dir. Plus, config/ is needed at runtime.
postInstall = ''
mkdir -p $out/lib
cp -a {static,config} $out/lib
'';
};
};
in final: prev: {
myHaskellPackages = prev.haskellPackages.override {
overrides = hsOverlay final;
};
};
packages.x86_64-linux.stackage-server =
let
myPkgs = import inputs.nixpkgs-2311 {
system = "x86_64-linux"; overlays = [ self.overlays.stackage-server ];
};
in myPkgs.myHaskellPackages.stackage-server;
nixosModules.stackage-server = import ./stackage-builder/nixos-modules/stackage-server.nix {
stackage-update-uid = 1005;
stackage-uid = 1006;
stackage-server-app = self.packages.x86_64-linux.stackage-server;
};
##
## CASA SERVER
##
# Just used to define the casa package.
overlays.casa =
let
myPackage = "casa";
hsOverlay = pkgs: self: super: {
${myPackage} = pkgs.haskell.lib.buildStackProject {
name = myPackage;
src = pkgs.fetchFromGitHub {
owner = "commercialhaskell";
repo = myPackage;
rev = "9ce3ae6653120ca00b898c193ee5c9955b697d34";
sha256 = "sha256-bBjHW8IWpxl/J4GzTziyBq5DWTB6dagPFvzJAFVpSLY=";
};
ghc = pkgs.haskell.compiler.ghc8107;
buildInputs = [ pkgs.zlib pkgs.git pkgs.postgresql ];
# FIXME: Shifting the tests to lts-15.6 proved too much work, so
# I've disabled them.
checkPhase = "";
};
};
in final: prev: {
myHaskellPackages = prev.haskellPackages.override {
overrides = hsOverlay final;
};
};
packages.x86_64-linux.casa =
let
myPkgs = import inputs.nixpkgs-2009 {
system = "x86_64-linux"; overlays = [ self.overlays.casa ];
};
in myPkgs.myHaskellPackages.casa;
# Just used to define the curator package. This package has both "curator",
# used by curators manually, and "casa-curator", which I'll set up in the
# casa-server nixos module below.
overlays.curator =
let
myPackage = "curator";
hsOverlay = pkgs: self: super: {
${myPackage} = pkgs.haskell.lib.buildStackProject {
name = myPackage;
src = pkgs.fetchFromGitHub {
owner = "commercialhaskell";
repo = myPackage;
rev = "558215d639561301a0069dc749896ad3e71b5c24";
sha256 =
"sha256-s+3RhFk0ZTorlgYEOTP93F54ARVAN3C4eIwBRUlUOQ8=";
};
patches = [ ./stackage-builder/curator_hackage-server-T1023.patch ];
ghc = pkgs.haskell.compiler.ghc947;
buildInputs = [ pkgs.zlib pkgs.openssl pkgs.sqlite ];
# FIXME: Tests have a 'Not in scope' compile error!
checkPhase = "";
};
};
in final: prev: {
myHaskellPackages = prev.haskellPackages.override {
overrides = hsOverlay final;
};
};
packages.x86_64-linux.curator =
let
myPkgs = import inputs.nixpkgs-2311 {
system = "x86_64-linux"; overlays = [ self.overlays.curator ];
};
in myPkgs.myHaskellPackages.curator;
nixosModules.casa-server = import ./stackage-builder/nixos-modules/casa-server.nix {
casa-uid = 1007;
casa-updater-uid = 1008;
casa-app = self.packages.x86_64-linux.casa;
curator-app = self.packages.x86_64-linux.curator;
};
};
}