/
default.nix
471 lines (435 loc) · 17.2 KB
/
default.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
{ nixpkgsFunc ? import ./nixpkgs
, system ? builtins.currentSystem
, config ? {}
, enableLibraryProfiling ? false
, enableExposeAllUnfoldings ? true
, enableTraceReflexEvents ? false
, useFastWeak ? true
, useReflexOptimizer ? false
, useTextJSString ? true # Use an implementation of "Data.Text" that uses the more performant "Data.JSString" from ghcjs-base under the hood.
, __useTemplateHaskell ? true # Deprecated, just here until we remove feature from reflex and stop CIing it
, iosSdkVersion ? "10.2"
, nixpkgsOverlays ? []
, haskellOverlays ? [] # TODO deprecate
, haskellOverlaysPre ? []
, haskellOverlaysPost ? haskellOverlays
, hideDeprecated ? false # The moral equivalent of "-Wcompat -Werror" for using reflex-platform.
, hieSupport ? true
}:
let iosSupport = system == "x86_64-darwin";
androidSupport = lib.elem system [ "x86_64-linux" ];
# Overlay for GHC with -load-splices & -save-splices option
splicesEval = self: super: {
haskell = super.haskell // {
compiler = super.haskell.compiler // {
ghcSplices-8_6 = super.haskell.compiler.ghc865.overrideAttrs (drv: {
enableParallelBuilding = false;
src = nixpkgs.hackGet ./haskell-overlays/splices-load-save/dep/ghc;
# When building from the ghc git repo, ./boot must be run before configuring, whereas
# in the distribution tarball on the haskell.org downloads page, ./boot has already been
# run.
preConfigure= ''
echo ${drv.version} >VERSION
./boot
'' + drv.preConfigure or "";
# Our fork of 8.6 with splices includes these patches.
# Specifically, is up to date with the `ghc-8.6` branch upstream,
# which contains various backports for any potential newer 8.6.x
# release. Nixpkgs manually applied some of those backports as
# patches onto 8.6.5 ahead of such a release, but now we get them
# from the src proper.
patches = [];
});
};
packages = super.haskell.packages // {
ghcSplices-8_6 = super.haskell.packages.ghc865.override {
buildHaskellPackages = self.buildPackages.haskell.packages.ghcSplices-8_6;
ghc = self.buildPackages.haskell.compiler.ghcSplices-8_6;
};
};
};
};
hackGetOverlay = self: super:
import ./nixpkgs-overlays/hack-get { inherit lib; } self;
bindHaskellOverlays = self: super: {
haskell = super.haskell // {
overlays = super.haskell.overlays or {} // import ./haskell-overlays {
nixpkgs = self;
inherit (self) lib;
haskellLib = self.haskell.lib;
inherit
useFastWeak useReflexOptimizer enableLibraryProfiling enableTraceReflexEvents
useTextJSString enableExposeAllUnfoldings __useTemplateHaskell
haskellOverlaysPre
haskellOverlaysPost;
inherit ghcSavedSplices;
};
};
};
forceStaticLibs = self: super: {
darwin = super.darwin // {
libiconv = super.darwin.libiconv.overrideAttrs (_:
lib.optionalAttrs (self.stdenv.hostPlatform != self.stdenv.buildPlatform) {
postInstall = "rm $out/include/libcharset.h $out/include/localcharset.h";
configureFlags = ["--disable-shared" "--enable-static"];
});
};
zlib = super.zlib.override (lib.optionalAttrs
(self.stdenv.hostPlatform != self.stdenv.buildPlatform)
{ static = true; shared = false; });
};
mobileGhcOverlay = import ./nixpkgs-overlays/mobile-ghc { inherit lib; };
allCabalHashesOverlay = import ./nixpkgs-overlays/all-cabal-hashes;
nixpkgsArgs = {
inherit system;
overlays = [
hackGetOverlay
bindHaskellOverlays
forceStaticLibs
splicesEval
mobileGhcOverlay
allCabalHashesOverlay
(import ./nixpkgs-overlays/ghc.nix { inherit lib; })
] ++ nixpkgsOverlays;
config = {
permittedInsecurePackages = [
"webkitgtk-2.4.11"
];
# XCode needed for native macOS app
# Obelisk needs it to for some reason
allowUnfree = true;
} // config;
};
nixpkgs = nixpkgsFunc nixpkgsArgs;
inherit (nixpkgs) lib fetchurl fetchgit fetchgitPrivate fetchFromGitHub fetchFromBitbucket;
nixpkgsCross = {
android = lib.mapAttrs (_: args: nixpkgsFunc (nixpkgsArgs // args)) rec {
aarch64 = {
crossSystem = lib.systems.examples.aarch64-android-prebuilt;
};
aarch32 = {
crossSystem = lib.systems.examples.armv7a-android-prebuilt // {
# Hard to find newer 32-bit phone to test with that's newer than
# this. Concretely, doing so resulted in:
# https://android.googlesource.com/platform/bionic/+/master/libc/arch-common/bionic/pthread_atfork.h#19
sdkVer = "22";
};
};
};
ios = lib.mapAttrs (_: args: nixpkgsFunc (nixpkgsArgs // args)) rec {
simulator64 = {
crossSystem = lib.systems.examples.iphone64-simulator // {
sdkVer = iosSdkVersion;
};
};
aarch64 = {
crossSystem = lib.systems.examples.iphone64 // {
sdkVer = iosSdkVersion;
};
};
aarch32 = {
crossSystem = lib.systems.examples.iphone32 // {
sdkVer = iosSdkVersion;
};
};
# Back compat
arm64 = lib.warn "nixpkgsCross.ios.arm64 has been deprecated, using nixpkgsCross.ios.aarch64 instead." aarch64;
};
ghcjs = nixpkgsFunc (nixpkgsArgs // {
crossSystem = lib.systems.examples.ghcjs;
});
};
haskellLib = nixpkgs.haskell.lib;
overrideCabal = pkg: f: if pkg == null then null else haskellLib.overrideCabal pkg f;
combineOverrides = old: new: old // new // lib.optionalAttrs (old ? overrides && new ? overrides) {
overrides = lib.composeExtensions old.overrides new.overrides;
};
# Makes sure that old `overrides` from a previous call to `override` are not
# forgotten, but composed. Do this by overriding `override` and passing a
# function which takes the old argument set and combining it. What a tongue
# twister!
makeRecursivelyOverridable = x: x // {
override = new: makeRecursivelyOverridable (x.override (old: (combineOverrides old new)));
};
cabal2nixResult = src: builtins.trace "cabal2nixResult is deprecated; use ghc.haskellSrc2nix or ghc.callCabal2nix instead" (ghc.haskellSrc2nix {
name = "for-unknown-package";
src = "file://${src}";
sha256 = null;
});
ghcSavedSplices = ghcSavedSplices-8_6;
ghcSavedSplices-8_6 = (makeRecursivelyOverridable nixpkgs.haskell.packages.integer-simple.ghcSplices-8_6).override {
overrides = lib.foldr lib.composeExtensions (_: _: {}) (let
haskellOverlays = nixpkgs.haskell.overlays;
in [
haskellOverlays.combined
haskellOverlays.saveSplices
(self: super: with haskellLib; {
blaze-textual = haskellLib.enableCabalFlag super.blaze-textual "integer-simple";
cryptonite = disableCabalFlag super.cryptonite "integer-gmp";
integer-logarithms = disableCabalFlag super.integer-logarithms "integer-gmp";
scientific = enableCabalFlag super.scientific "integer-simple";
dependent-sum-template = dontCheck super.dependent-sum-template;
generic-deriving = dontCheck super.generic-deriving;
})
]);
};
ghcjs = ghcjs8_6;
ghcjs8_6 = (makeRecursivelyOverridable (nixpkgsCross.ghcjs.haskell.packages.ghcjs86.override (old: {
ghc = old.ghc.override {
bootPkgs = nixpkgsCross.ghcjs.buildPackages.haskell.packages.ghc865;
ghcjsSrc = fetchgit {
url = "https://github.com/obsidiansystems/ghcjs.git";
rev = "06f81b44c3cc6c7f75e1a5a20d918bad37294b52";
sha256 = "02mwkf7aagxqi142gcmq048244apslrr72p568akcab9s0fn2gvy";
fetchSubmodules = true;
};
};
}))).override {
overrides = nixpkgsCross.ghcjs.haskell.overlays.combined;
};
ghc = ghc8_6;
ghcHEAD = (makeRecursivelyOverridable nixpkgs.haskell.packages.ghcHEAD).override {
overrides = nixpkgs.haskell.overlays.combined;
};
ghc8_6 = (makeRecursivelyOverridable nixpkgs.haskell.packages.ghc865).override {
overrides = nixpkgs.haskell.overlays.combined;
};
# Takes a package set with `makeRecursivelyOverridable` and ensures that any
# future overrides will be applied to both the package set itself and it's
# build-time package set (`buildHaskellPackages`).
makeRecursivelyOverridableBHPToo = x: x // {
override = new: makeRecursivelyOverridableBHPToo (x.override
(combineOverrides
{
overrides = self: super: {
buildHaskellPackages = super.buildHaskellPackages.override new;
};
}
new));
};
ghcAndroidAarch64 = ghcAndroidAarch64-8_6;
ghcAndroidAarch64-8_6 = makeRecursivelyOverridableBHPToo ((makeRecursivelyOverridable nixpkgsCross.android.aarch64.haskell.packages.integer-simple.ghcSplices-8_6).override {
overrides = nixpkgsCross.android.aarch64.haskell.overlays.combined;
});
ghcAndroidAarch32 = ghcAndroidAarch32-8_6;
ghcAndroidAarch32-8_6 = makeRecursivelyOverridableBHPToo ((makeRecursivelyOverridable nixpkgsCross.android.aarch32.haskell.packages.integer-simple.ghcSplices-8_6).override {
overrides = nixpkgsCross.android.aarch32.haskell.overlays.combined;
});
ghcIosSimulator64 = ghcIosSimulator64-8_6;
ghcIosSimulator64-8_6 = makeRecursivelyOverridableBHPToo ((makeRecursivelyOverridable nixpkgsCross.ios.simulator64.haskell.packages.integer-simple.ghcSplices-8_6).override {
overrides = nixpkgsCross.ios.simulator64.haskell.overlays.combined;
});
ghcIosAarch64 = ghcIosAarch64-8_6;
ghcIosAarch64-8_6 = makeRecursivelyOverridableBHPToo ((makeRecursivelyOverridable nixpkgsCross.ios.aarch64.haskell.packages.integer-simple.ghcSplices-8_6).override {
overrides = nixpkgsCross.ios.aarch64.haskell.overlays.combined;
});
ghcIosAarch32 = ghcIosAarch32-8_6;
ghcIosAarch32-8_6 = makeRecursivelyOverridableBHPToo ((makeRecursivelyOverridable nixpkgsCross.ios.aarch32.haskell.packages.integer-simple.ghcSplices-8_6).override {
overrides = nixpkgsCross.ios.aarch32.haskell.overlays.combined;
});
#TODO: Separate debug and release APKs
#TODO: Warn the user that the android app name can't include dashes
android = androidWithHaskellPackages {
inherit ghcAndroidAarch64 ghcAndroidAarch32;
};
android-8_6 = androidWithHaskellPackages {
ghcAndroidAarch64 = ghcAndroidAarch64-8_6;
ghcAndroidAarch32 = ghcAndroidAarch32-8_6;
};
androidWithHaskellPackages = { ghcAndroidAarch64, ghcAndroidAarch32 }: import ./android {
inherit nixpkgs nixpkgsCross ghcAndroidAarch64 ghcAndroidAarch32 overrideCabal;
acceptAndroidSdkLicenses = config.android_sdk.accept_license or false;
};
iosAarch64 = iosWithHaskellPackages ghcIosAarch64;
iosAarch64-8_6 = iosWithHaskellPackages ghcIosAarch64-8_6;
iosAarch32 = iosWithHaskellPackages ghcIosAarch32;
iosAarch32-8_6 = iosWithHaskellPackages ghcIosAarch32-8_6;
iosWithHaskellPackages = ghc: {
buildApp = nixpkgs.lib.makeOverridable (import ./ios { inherit nixpkgs ghc; });
};
in let this = rec {
inherit (nixpkgs)
filterGit
hackGet
thunkSet
;
inherit nixpkgs
nixpkgsCross
overrideCabal
ghc
ghcHEAD
ghc8_6
ghcIosSimulator64
ghcIosAarch64
ghcIosAarch64-8_6
ghcIosAarch32
ghcIosAarch32-8_6
ghcAndroidAarch64
ghcAndroidAarch64-8_6
ghcAndroidAarch32
ghcAndroidAarch32-8_6
ghcjs
ghcjs8_6
ghcSavedSplices
android
androidWithHaskellPackages
iosAarch32
iosAarch64
iosWithHaskellPackages
;
# Back compat
ios = iosAarch64;
ghcAndroidArm64 = lib.warn "ghcAndroidArm64 has been deprecated, using ghcAndroidAarch64 instead." ghcAndroidAarch64;
ghcAndroidArmv7a = lib.warn "ghcAndroidArmv7a has been deprecated, using ghcAndroidAarch32 instead." ghcAndroidAarch32;
ghcIosArm64 = lib.warn "ghcIosArm64 has been deprecated, using ghcIosAarch64 instead." ghcIosAarch64;
androidReflexTodomvc = android.buildApp {
package = p: p.reflex-todomvc;
executableName = "reflex-todomvc";
applicationId = "org.reflexfrp.todomvc";
displayName = "Reflex TodoMVC";
};
androidReflexTodomvc-8_6 = android-8_6.buildApp {
package = p: p.reflex-todomvc;
executableName = "reflex-todomvc";
applicationId = "org.reflexfrp.todomvc.via_8_6";
displayName = "Reflex TodoMVC via GHC 8.6";
};
iosReflexTodomvc = ios.buildApp {
package = p: p.reflex-todomvc;
executableName = "reflex-todomvc";
bundleIdentifier = "org.reflexfrp.todomvc";
bundleName = "Reflex TodoMVC";
};
iosReflexTodomvc-8_6 = iosAarch64-8_6.buildApp {
package = p: p.reflex-todomvc;
executableName = "reflex-todomvc";
bundleIdentifier = "org.reflexfrp.todomvc.via_8_6";
bundleName = "Reflex TodoMVC via GHC 8.6";
};
setGhcLibdir = ghcLibdir: inputGhcjs:
let libDir = "$out/lib/ghcjs-${inputGhcjs.version}";
ghcLibdirLink = nixpkgs.stdenv.mkDerivation {
name = "ghc_libdir";
inherit ghcLibdir;
buildCommand = ''
mkdir -p ${libDir}
echo "$ghcLibdir" > ${libDir}/ghc_libdir_override
'';
};
in inputGhcjs // {
outPath = nixpkgs.buildEnv {
inherit (inputGhcjs) name;
paths = [ inputGhcjs ghcLibdirLink ];
postBuild = ''
mv ${libDir}/ghc_libdir_override ${libDir}/ghc_libdir
'';
};
};
platforms = [
"ghcjs"
"ghc"
];
androidDevTools = [
ghc.haven
nixpkgs.maven
nixpkgs.androidsdk_9_0
];
# Tools that are useful for development under both ghc and ghcjs
generalDevTools' = { nativeHaskellPackages ? ghc }: {
inherit (nativeHaskellPackages)
Cabal
cabal-install
ghcid
hasktags
hdevtools
hlint
stylish-haskell # Recent stylish-haskell only builds with AMP in place
;
inherit (nixpkgs)
cabal2nix
curl
nix-prefetch-scripts
nodejs
pkgconfig
closurecompiler
;
} // lib.optionalAttrs hieSupport {
haskell-ide-engine = nixpkgs.haskell.lib.justStaticExecutables (nativeHaskellPackages.override {
overrides = nixpkgs.haskell.overlays.hie;
}).haskell-ide-engine;
};
workOn = haskellPackages: package: (overrideCabal package (drv: {
buildTools = (drv.buildTools or []) ++ builtins.attrValues (generalDevTools' {});
})).env;
# A simple derivation that just creates a file with the names of all
# of its inputs. If built, it will have a runtime dependency on all
# of the given build inputs.
pinBuildInputs = name: buildInputs: (nixpkgs.releaseTools.aggregate {
inherit name;
constituents = buildInputs;
}).overrideAttrs (old: {
buildCommand = old.buildCommand + ''
echo "$propagatedBuildInputs $buildInputs $nativeBuildInputs $propagatedNativeBuildInputs" > "$out/deps"
'';
inherit buildInputs;
});
reflexEnv = platform:
let haskellPackages = builtins.getAttr platform this;
ghcWithStuff = if platform == "ghc" || platform == "ghcjs"
then haskellPackages.ghcWithHoogle
else haskellPackages.ghcWithPackages;
in ghcWithStuff (p: import ./packages.nix {
haskellPackages = p;
inherit platform;
});
tryReflexPackages = builtins.attrValues (generalDevTools' {})
++ builtins.map reflexEnv platforms;
cachePackages =
let otherPlatforms = lib.optionals androidSupport [
"ghcAndroidAarch64"
"ghcAndroidAarch32"
] ++ lib.optional iosSupport "ghcIosAarch64";
in tryReflexPackages
++ builtins.map reflexEnv otherPlatforms
++ lib.optionals androidSupport [
androidDevTools
androidReflexTodomvc
] ++ lib.optionals iosSupport [
iosReflexTodomvc
];
inherit cabal2nixResult system androidSupport iosSupport;
project = args: import ./project this (args ({ pkgs = nixpkgs; } // this));
tryReflexShell = pinBuildInputs ("shell-" + system) tryReflexPackages;
ghcjsExternsJs = ./ghcjs.externs.js;
};
# Deprecated reexports. These were made for `./scripts/*`, but are reexported
# here for backwards compatability.
legacy = {
# Added 2019-12, will be removed 2020-06.
inherit
(import ./nix-utils/hackage { reflex-platform = this; })
attrsToList
mapSet
mkSdist
sdists
mkHackageDocs
hackageDocs
mkReleaseCandidate
releaseCandidates
;
generalDevTools = _: builtins.attrValues (this.generalDevTools' {});
generalDevToolsAttrs = _: this.generalDevTools' {};
nativeHaskellPackages = haskellPackages:
if haskellPackages.isGhcjs or false
then haskellPackages.ghc
else haskellPackages;
workOnMulti' = { env, packageNames }:
(import ./nix-utils/work-on-multi {}).workOnMulti {
envFunc = _: env;
inherit packageNames;
};
workOnMulti = env: packageNames: legacy.workOnMulti' { inherit env packageNames; };
};
in this // lib.optionalAttrs
(!hideDeprecated)
(lib.mapAttrs (attrName: builtins.trace "The attribute \"${attrName}\" is deprecated. See reflex-platform's root default.nix.") legacy)