-
Notifications
You must be signed in to change notification settings - Fork 214
/
shared.nix
479 lines (411 loc) · 16.1 KB
/
shared.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
let
pinned = import ./pinnedNixpkgs.nix;
defaultCompiler = "ghc843";
in
{ nixpkgs ? pinned.nixpkgs
, nixpkgsStaticLinux ? pinned.nixpkgsStaticLinux
, compiler ? defaultCompiler
, coverage ? false
, system ? builtins.currentSystem
}:
let
allDhallPackages = [
"dhall"
"dhall-bash"
"dhall-json"
"dhall-lsp-server"
"dhall-nix"
"dhall-yaml"
];
mass = function: names: haskellPackagesNew: haskellPackagesOld:
let
toNameValue = name: {
inherit name;
value = function haskellPackagesOld."${name}";
};
in
builtins.listToAttrs (map toNameValue names);
overlayShared = pkgsNew: pkgsOld: {
sdist = pkgsNew.callPackage ./sdist.nix { };
haskell = pkgsOld.haskell // {
packages = pkgsOld.haskell.packages // {
"${compiler}" = pkgsOld.haskell.packages."${compiler}".override (old: {
overrides =
let
applyCoverage = drv:
if coverage
then
pkgsNew.haskell.lib.overrideCabal
(pkgsNew.haskell.lib.doCoverage
(pkgsNew.haskell.lib.doCheck drv)
)
(old: {
postInstall = (old.postInstall or "") + ''
${pkgsNew.coreutils}/bin/mkdir --parents $out/nix-support
${pkgsNew.coreutils}/bin/ln --symbolic $out/share/hpc/vanilla/html/dhall-* "$out/share/hpc/vanilla/html/dhall"
${pkgsNew.coreutils}/bin/echo "report coverage $out/share/hpc/vanilla/html/dhall/hpc_index.html" >> $out/nix-support/hydra-build-products
'';
}
)
else
pkgsNew.haskell.lib.dontCheck drv;
failOnAllWarnings = drv:
# GHCJS incorrectly detects non-exhaustive pattern matches
if compiler == "ghcjs"
then drv
else pkgsNew.haskell.lib.failOnAllWarnings drv;
failOnMissingHaddocks = drv:
if compiler == defaultCompiler
then
drv.overrideAttrs
(old: {
postHaddock = (old.postHaddock or "") + ''
! (./Setup haddock 2>&1 | grep --quiet 'Missing documentation for:') || (echo "Error: Incomplete haddocks"; exit 1)
'';
}
)
else
drv;
doCheckExtension =
mass pkgsNew.haskell.lib.doCheck
( [ "dhall-bash"
"dhall-json"
# The test suite fails due to a relative reference
# to ../dhall/dhall-lang/
# "dhall-lsp-server"
"dhall-nix"
"dhall-yaml"
]
# Test suite doesn't work on GHCJS
++ pkgsNew.lib.optional (!(compiler == "ghcjs")) "dhall"
);
doBenchmarkExtension =
mass pkgsNew.haskell.lib.doBenchmark allDhallPackages;
doJailbreakExtension =
mass pkgsNew.haskell.lib.doJailbreak [
"hnix"
];
failOnAllWarningsExtension =
mass failOnAllWarnings [
"dhall"
"dhall-bash"
"dhall-json"
"dhall-lsp-server"
"dhall-nix"
"dhall-yaml"
];
failOnMissingHaddocksExtension =
mass failOnMissingHaddocks [
"dhall"
];
extension =
haskellPackagesNew: haskellPackagesOld: {
mkDerivation =
args: haskellPackagesOld.mkDerivation (args // {
doCheck = false;
}
);
dhall =
applyCoverage
(haskellPackagesNew.callCabal2nix
"dhall"
(pkgsNew.sdist ../dhall)
{ }
);
dhall-no-http =
pkgsNew.haskell.lib.appendConfigureFlag
haskellPackagesNew.dhall
[ "-f-with-http" ];
dhall-bash =
haskellPackagesNew.callCabal2nix
"dhall-bash"
(pkgsNew.sdist ../dhall-bash)
{ };
dhall-json =
haskellPackagesNew.callCabal2nix
"dhall-json"
(pkgsNew.sdist ../dhall-json)
{ };
dhall-nix =
haskellPackagesNew.callCabal2nix
"dhall-nix"
(pkgsNew.sdist ../dhall-nix)
{ };
dhall-lsp-server =
haskellPackagesNew.callCabal2nix
"dhall-lsp-server"
(pkgsNew.sdist ../dhall-lsp-server)
{ };
dhall-yaml =
haskellPackagesNew.callCabal2nix
"dhall-yaml"
(pkgsNew.sdist ../dhall-yaml)
{ };
dhall-try =
pkgsNew.haskell.lib.overrideCabal
(haskellPackagesNew.callCabal2nix
"dhall-try"
(pkgsNew.sdist ../dhall-try)
{ }
)
(old: {
postInstall = (old.postInstall or "") + ''
${pkgsNew.closurecompiler}/bin/closure-compiler $out/bin/dhall-try.jsexe/all.js --jscomp_off=checkVars --externs=$out/bin/dhall-try.jsexe/all.js.externs > $out/bin/dhall-try.jsexe/all.min.js
'';
}
);
};
in
pkgsNew.lib.fold
pkgsNew.lib.composeExtensions
(old.overrides or (_: _: {}))
[ (pkgsNew.haskell.lib.packagesFromDirectory { directory = ./.; })
extension
doCheckExtension
doBenchmarkExtension
doJailbreakExtension
failOnAllWarningsExtension
failOnMissingHaddocksExtension
];
}
);
};
};
};
overlayCabal2nix = pkgsNew: pkgsOld: {
haskellPackages = pkgsOld.haskellPackages.override (old: {
overrides =
let
extension =
haskellPackagesNew: haskellPackagesOld: {
# `cabal2nix` requires a newer version of `hpack`
hpack =
haskellPackagesOld.hpack_0_29_6;
};
in
pkgsNew.lib.composeExtensions
(old.overrides or (_: _: {}))
extension;
}
);
};
overlayGHC802 = pkgsNew: pkgsOld: {
haskell = pkgsOld.haskell // {
packages = pkgsOld.haskell.packages // {
"${compiler}" = pkgsOld.haskell.packages."${compiler}".override (old: {
overrides =
let
extension =
haskellPackagesNew: haskellPackagesOld: {
lens-family-core =
haskellPackagesOld.lens-family-core_1_2_1;
lens-family = haskellPackagesOld.lens-family_1_2_1;
};
in
pkgsNew.lib.composeExtensions
(old.overrides or (_: _: {}))
extension;
}
);
};
};
};
overlayGHC861 = pkgsNew: pkgsOld: {
haskell = pkgsOld.haskell // {
packages = pkgsOld.haskell.packages // {
"${compiler}" = pkgsOld.haskell.packages."${compiler}".override (old: {
overrides =
let
extension =
haskellPackagesNew: haskellPackagesOld: {
lens-family-core =
haskellPackagesOld.lens-family-core_1_2_3;
# GHC 8.6.1 accidentally shipped with an unpublished
# unix-2.8 package. Normally we'd deal with that by
# using `pkgsNew.haskell.lib.jailbreak` but it doesn't
# work for dependencies guarded by conditions. See:
#
# https://github.com/peti/jailbreak-cabal/issues/7
turtle =
pkgsNew.haskell.lib.appendPatch
haskellPackagesOld.turtle
./turtle.patch;
};
in
pkgsNew.lib.composeExtensions
(old.overrides or (_: _: {}))
extension;
}
);
};
};
};
pkgs = import nixpkgs {
inherit system;
config = {};
overlays =
[ overlayShared overlayCabal2nix ]
++ ( if compiler == "ghc802" then [ overlayGHC802 ]
else if compiler == "ghc861" then [ overlayGHC861 ]
else [ ]
);
};
overlayStaticLinux = pkgsNew: pkgsOld: {
cabal_patched_src = pkgsNew.fetchFromGitHub {
owner = "nh2";
repo = "cabal";
rev = "748f07b50724f2618798d200894f387020afc300";
sha256 = "1k559m291f6spip50rly5z9rbxhfgzxvaz64cx4jqpxgfhbh2gfs";
};
Cabal_patched_Cabal_subdir = pkgsNew.stdenv.mkDerivation {
name = "cabal-dedupe-src";
buildCommand = ''
cp -rv ${pkgsNew.cabal_patched_src}/Cabal/ $out
'';
};
haskell = pkgsOld.haskell // {
lib = pkgsOld.haskell.lib // {
useFixedCabal = drv: pkgsNew.haskell.lib.overrideCabal drv (old: {
setupHaskellDepends =
(old.setupHaskellDepends or []) ++ [
pkgsNew.haskell.packages."${compiler}".Cabal_patched
];
libraryHaskellDepends =
(old.libraryHaskellDepends or []) ++ [
pkgsNew.haskell.packages."${compiler}".Cabal_patched
];
}
);
statify = drv:
pkgsNew.lib.foldl pkgsNew.haskell.lib.appendConfigureFlag
(pkgsNew.haskell.lib.disableLibraryProfiling
(pkgsNew.haskell.lib.disableSharedExecutables
(pkgsNew.haskell.lib.useFixedCabal
(pkgsNew.haskell.lib.justStaticExecutables drv)
)
)
)
[ "--enable-executable-static"
"--extra-lib-dirs=${pkgsNew.gmp6.override { withStatic = true; }}/lib"
"--extra-lib-dirs=${pkgsNew.zlib.static}/lib"
"--extra-lib-dirs=${pkgsNew.ncurses.override { enableStatic = true; }}/lib"
];
};
packages = pkgsOld.haskell.packages // {
"${compiler}" = pkgsOld.haskell.packages."${compiler}".override (old: {
overrides =
let
extension =
haskellPackagesNew: haskellPackagesOld: {
Cabal_patched =
haskellPackagesNew.callCabal2nix
"Cabal"
pkgsNew.Cabal_patched_Cabal_subdir
{ };
dhall-static =
pkgsNew.haskell.lib.statify haskellPackagesOld.dhall;
dhall-bash-static =
pkgsNew.haskell.lib.statify haskellPackagesOld.dhall-bash;
dhall-json-static =
pkgsNew.haskell.lib.statify haskellPackagesOld.dhall-json;
dhall-lsp-server-static =
pkgsNew.haskell.lib.statify haskellPackagesOld.dhall-lsp-server;
dhall-nix-static =
pkgsNew.haskell.lib.statify haskellPackagesOld.dhall-nix;
dhall-yaml-static =
pkgsNew.haskell.lib.statify haskellPackagesOld.dhall-yaml;
};
in
pkgsNew.lib.composeExtensions
(old.overrides or (_: _: {}))
extension;
}
);
};
};
};
pkgsStaticLinux = import nixpkgsStaticLinux {
config = {};
overlays = [ overlayShared overlayStaticLinux ];
system = "x86_64-linux";
};
trivial = x: pkgs.runCommand "trivial" { inherit x; } "touch $out";
makeStaticIfPossible = name:
if pkgs.stdenv.isLinux
then
pkgsStaticLinux.pkgsMusl.haskell.packages."${compiler}"."${name}-static"
else
pkgs.haskell.lib.justStaticExecutables (pkgs.haskell.packages."${compiler}"."${name}");
makeTarball = name:
pkgsStaticLinux.releaseTools.binaryTarball rec {
src = pkgsStaticLinux.pkgsMusl.haskell.packages."${compiler}"."${name}-static";
installPhase = ''
releaseName=${name}
${pkgsStaticLinux.coreutils}/bin/install --target-directory "$TMPDIR/inst/bin" -D $src/bin/*
'';
};
toShell = drv: drv.env;
possibly-static = {
dhall = makeStaticIfPossible "dhall" ;
dhall-bash = makeStaticIfPossible "dhall-bash" ;
dhall-json = makeStaticIfPossible "dhall-json" ;
dhall-lsp-server = makeStaticIfPossible "dhall-lsp-server";
dhall-nix = makeStaticIfPossible "dhall-nix" ;
dhall-yaml = makeStaticIfPossible "dhall-yaml" ;
};
toDockerImage = name:
let
image =
pkgs.dockerTools.buildImage {
inherit name;
contents = [ possibly-static."${name}" pkgs.cacert ];
};
in
pkgs.runCommand "image-${name}" {} ''
${pkgs.coreutils}/bin/mkdir --parents "$out/nix-support"
${pkgs.coreutils}/bin/ln --symbolic '${image}' "$out/docker-image-${name}.tar.gz"
echo "file binary-dist $out/docker-image-${name}.tar.gz" >> $out/nix-support/hydra-build-products
'';
in
rec {
inherit trivial pkgs possibly-static;
tarball-dhall = makeTarball "dhall" ;
tarball-dhall-bash = makeTarball "dhall-bash" ;
tarball-dhall-json = makeTarball "dhall-json" ;
tarball-dhall-lsp-server = makeTarball "dhall-lsp-server";
tarball-dhall-nix = makeTarball "dhall-nix" ;
tarball-dhall-yaml = makeTarball "dhall-yaml" ;
inherit (pkgs) tarball-website website;
inherit (pkgs.haskell.packages."${compiler}")
dhall
dhall-no-http
dhall-bash
dhall-json
dhall-lsp-server
dhall-nix
dhall-try
dhall-yaml
;
inherit (pkgs.releaseTools) aggregate;
shell-dhall = pkgs.haskell.packages."${compiler}".dhall.env ;
shell-dhall-bash = pkgs.haskell.packages."${compiler}".dhall-bash.env ;
shell-dhall-json = pkgs.haskell.packages."${compiler}".dhall-json.env ;
shell-dhall-lsp-server = pkgs.haskell.packages."${compiler}".dhall-lsp-server.env;
shell-dhall-nix = pkgs.haskell.packages."${compiler}".dhall-nix.env ;
shell-dhall-try = pkgs.haskell.packages."${compiler}".dhall-try.env ;
shell-dhall-yaml = pkgs.haskell.packages."${compiler}".dhall-yaml.env ;
image-dhall = toDockerImage "dhall" ;
image-dhall-bash = toDockerImage "dhall-bash" ;
image-dhall-json = toDockerImage "dhall-json" ;
image-dhall-lsp-server = toDockerImage "dhall-lsp-server";
image-dhall-nix = toDockerImage "dhall-nix" ;
image-dhall-yaml = toDockerImage "dhall-yaml" ;
test-dhall =
pkgs.mkShell
{ buildInputs =
[ (pkgs.haskell.packages."${compiler}".ghcWithPackages
(pkgs: [ pkgs.dhall ])
)
];
};
}