summaryrefslogtreecommitdiffstats
path: root/pkgs/development/haskell-modules/configuration-darwin.nix
blob: bdab687233228fb77afc8a0b8848e70b68200275 (plain)
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# DARWIN-SPECIFIC OVERRIDES FOR THE HASKELL PACKAGE SET IN NIXPKGS

{ pkgs, haskellLib }:

let
  inherit (pkgs) lib darwin;
in

with haskellLib;

self: super:
(
  {

    # the tests for shell-conduit on Darwin illegitimatey assume non-GNU echo
    # see: https://github.com/psibi/shell-conduit/issues/12
    shell-conduit = dontCheck super.shell-conduit;

    conduit-extra = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.conduit-extra;

    spacecookie = overrideCabal (_: {
      __darwinAllowLocalNetworking = true;
    }) super.spacecookie;

    streaming-commons = overrideCabal (_: {
      __darwinAllowLocalNetworking = true;
    }) super.streaming-commons;

    # Hakyll's tests are broken on Darwin (3 failures); and they require util-linux
    hakyll = overrideCabal {
      testToolDepends = [ ];
      doCheck = false;
    } super.hakyll;

    double-conversion = addExtraLibrary pkgs.libcxx super.double-conversion;

    # darwin doesn't have sub-second resolution
    # https://github.com/hspec/mockery/issues/11
    mockery = overrideCabal (drv: {
      preCheck = ''
        export TRAVIS=true
      ''
      + (drv.preCheck or "");
    }) super.mockery;

    # https://github.com/ndmitchell/shake/issues/206
    shake = dontCheck super.shake;

    filecache = dontCheck super.filecache;

    # gtk/gtk3 needs to be told on Darwin to use the Quartz
    # rather than X11 backend (see eg https://github.com/gtk2hs/gtk2hs/issues/249).
    gtk3 = appendConfigureFlag "-f have-quartz-gtk" super.gtk3;
    gtk = appendConfigureFlag "-f have-quartz-gtk" super.gtk;

    # issues finding libcharset.h without libiconv in buildInputs on darwin.
    with-utf8 = addExtraLibrary pkgs.libiconv super.with-utf8;

    git-annex = overrideCabal (drv: {
      # We can't use testFlags since git-annex side steps the Cabal test mechanism
      preCheck = drv.preCheck or "" + ''
        checkFlagsArray+=(
          # The addurl test cases require security(1) to be in PATH which we can't
          # provide from nixpkgs to my (@sternenseemann) knowledge.
          "-p" "!/addurl/"
        )
      '';
    }) super.git-annex;

    # on*Finish tests rely on a threadDelay timing differential of 0.1s.
    # You'd think that's plenty of time even though immediate rescheduling
    # after threadDelay is not guaranteed. However, it appears that these
    # tests are quite flaky on Darwin.
    immortal = dontCheck super.immortal;

    # Prevents needing to add `security_tool` as a run-time dependency for
    # everything using x509-system to give access to the `security` executable.
    #
    # darwin.security_tool is broken in Mojave (#45042)
    #
    # We will use the system provided security for now.
    # Beware this WILL break in sandboxes!
    #
    # TODO(matthewbauer): If someone really needs this to work in sandboxes,
    # I think we can add a propagatedImpureHost dep here, but I’m hoping to
    # get a proper fix available soonish.
    x509-system = overrideCabal (
      drv:
      lib.optionalAttrs (!pkgs.stdenv.cc.nativeLibc) {
        postPatch = ''
          substituteInPlace System/X509/MacOS.hs --replace-fail security /usr/bin/security
        ''
        + (drv.postPatch or "");
      }
    ) super.x509-system;
    crypton-x509-system = overrideCabal (
      drv:
      lib.optionalAttrs (!pkgs.stdenv.cc.nativeLibc) {
        postPatch = ''
          substituteInPlace System/X509/MacOS.hs --replace-fail security /usr/bin/security
        ''
        + (drv.postPatch or "");
      }
    ) super.crypton-x509-system;
    HsOpenSSL-x509-system = overrideCabal (
      drv:
      lib.optionalAttrs (!pkgs.stdenv.cc.nativeLibc) {
        postPatch = ''
          substituteInPlace OpenSSL/X509/SystemStore/MacOSX.hs --replace-fail security /usr/bin/security
        ''
        + (drv.postPatch or "");
      }
    ) super.HsOpenSSL-x509-system;

    # https://github.com/haskell-foundation/foundation/pull/412
    foundation = dontCheck super.foundation;

    # Test suite attempts to create illegal paths on HFS+
    # https://github.com/fpco/haskell-filesystem/issues/37
    system-fileio = dontCheck super.system-fileio;

    llvm-hs = overrideCabal (oldAttrs: {
      # One test fails on darwin.
      doCheck = false;
      # llvm-hs's Setup.hs file tries to add the lib/ directory from LLVM8 to
      # the DYLD_LIBRARY_PATH environment variable.  This messes up clang
      # when called from GHC, probably because clang is version 7, but we are
      # using LLVM8.
      preCompileBuildDriver = ''
        substituteInPlace Setup.hs --replace-fail "addToLdLibraryPath libDir" "pure ()"
      ''
      + (oldAttrs.preCompileBuildDriver or "");
    }) super.llvm-hs;

    yesod-core = overrideCabal (drv: {
      # Allow access to local networking when the Darwin sandbox is enabled, so yesod-core can
      # run tests that access localhost.
      __darwinAllowLocalNetworking = true;
    }) super.yesod-core;

    hidapi = super.hidapi.override { systemd = null; };

    # Ensure the necessary frameworks are propagatedBuildInputs on darwin
    OpenGLRaw = overrideCabal (drv: {
      librarySystemDepends = [ ];
      libraryHaskellDepends = drv.libraryHaskellDepends;
      preConfigure = ''
        frameworkPaths=($(for i in $nativeBuildInputs; do if [ -d "$i"/Library/Frameworks ]; then echo "-F$i/Library/Frameworks"; fi done))
        frameworkPaths=$(IFS=, ; echo "''${frameworkPaths[@]}")
        configureFlags+=$(if [ -n "$frameworkPaths" ]; then echo -n "--ghc-options=-optl=$frameworkPaths"; fi)
      ''
      + (drv.preConfigure or "");
    }) super.OpenGLRaw;
    bindings-GLFW = overrideCabal (drv: {
      librarySystemDepends = [ ];
    }) super.bindings-GLFW;

    # cabal2nix likes to generate dependencies on hinotify when hfsevents is
    # really required on darwin: https://github.com/NixOS/cabal2nix/issues/146.
    hinotify = self.hfsevents;

    # FSEvents API is very buggy and tests are unreliable. See
    # http://openradar.appspot.com/10207999 and similar issues.
    fsnotify = dontCheck super.fsnotify;

    HTF = overrideCabal (drv: {
      # GNU find is not prefixed in stdenv
      postPatch = ''
        substituteInPlace scripts/local-htfpp --replace-fail "find=gfind" "find=find"
      ''
      + (drv.postPatch or "");
    }) super.HTF;

    # conditional dependency via a cabal flag
    cas-store = overrideCabal (drv: {
      libraryHaskellDepends = [
        self.kqueue
      ]
      ++ (drv.libraryHaskellDepends or [ ]);
    }) super.cas-store;

    # We are lacking pure pgrep at the moment for tests to work
    tmp-postgres = dontCheck super.tmp-postgres;

    # On darwin librt doesn't exist and will fail to link against,
    # however linking against it is also not necessary there
    GLHUI = overrideCabal (drv: {
      postPatch = ''
        substituteInPlace GLHUI.cabal --replace-fail " rt" ""
      ''
      + (drv.postPatch or "");
    }) super.GLHUI;

    SDL-image = overrideCabal (drv: {
      # Prevent darwin-specific configuration code path being taken
      # which doesn't work with nixpkgs' SDL libraries
      postPatch = ''
        substituteInPlace configure --replace-fail xDarwin noDarwinSpecialCasing
      ''
      + (drv.postPatch or "");
      patches = [
        # Work around SDL_main.h redefining main to SDL_main
        ./patches/SDL-image-darwin-hsc.patch
      ];
    }) super.SDL-image;

    # Prevent darwin-specific configuration code path being taken which
    # doesn't work with nixpkgs' SDL libraries
    SDL-mixer = overrideCabal (drv: {
      postPatch = ''
        substituteInPlace configure --replace-fail xDarwin noDarwinSpecialCasing
      ''
      + (drv.postPatch or "");
    }) super.SDL-mixer;

    # Work around SDL_main.h redefining main to SDL_main
    SDL-ttf = appendPatch ./patches/SDL-ttf-darwin-hsc.patch super.SDL-ttf;

    # Disable a bunch of test suites that fail because of darwin's case insensitive
    # file system: When a test suite has a test suite file that has the same name
    # as a module in scope, but in different case (e. g. hedgehog.hs and Hedgehog
    # in scope), GHC will complain that the file name and module name differ (in
    # the example hedgehog.hs would be Main).
    # These failures can easily be fixed by upstream by renaming files, so we
    # should create issues for them.
    # https://github.com/typeclasses/aws-cloudfront-signed-cookies/issues/2
    aws-cloudfront-signed-cookies = dontCheck super.aws-cloudfront-signed-cookies;

    # https://github.com/acid-state/acid-state/issues/133
    acid-state = dontCheck super.acid-state;

    # Otherwise impure gcc is used, which is Apple's weird wrapper
    c2hsc = addTestToolDepends [ pkgs.gcc ] super.c2hsc;

    http2 = overrideCabal (drv: {
      # Allow access to local networking when the Darwin sandbox is enabled, so http2 can run tests
      # that access localhost.
      __darwinAllowLocalNetworking = true;
    }) super.http2;

    # https://hydra.nixos.org/build/230964714/nixlog/1
    inline-c-cpp = appendPatch (pkgs.fetchpatch {
      url = "https://github.com/fpco/inline-c/commit/e8dc553b13bb847409fdced649a6a863323cff8a.patch";
      name = "revert-use-system-cxx-std-lib.patch";
      sha256 = "sha256-ql1/+8bvmWexyCdFR0VS4M4cY2lD0Px/9dHYLqlKyNA=";
      revert = true;
      stripLen = 1;
    }) super.inline-c-cpp;

    # Tests fail on macOS https://github.com/mrkkrp/zip/issues/112
    zip = dontCheck super.zip;

    dap = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.dap;

    essence-of-live-coding-warp = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.essence-of-live-coding-warp;

    http-streams = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.http-streams;

    io-streams = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.io-streams;

    io-streams-haproxy = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.io-streams-haproxy;

    jsaddle-warp = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.jsaddle-warp;

    openssl-streams = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.openssl-streams;

    servant-auth-client = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.servant-auth-client;

    servant-client = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.servant-client;

    snap = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.snap;

    warp = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
      # These fail in darwin sandbox with:
      #   Network.SendFile.MacOS.sendloopHeader: permission denied (Operation not permitted)
      testFlags = drv.testFlags or [ ] ++ [
        "--skip=/Response/range requests/"
        "--skip=/Response/partial files/"
      ];
    }) super.warp;

    ghcjs-dom-hello = overrideCabal (drv: {
      libraryHaskellDepends = with self; [
        jsaddle
        jsaddle-warp
      ];
      executableHaskellDepends = with self; [
        ghcjs-dom
        jsaddle-wkwebview
      ];
    }) super.ghcjs-dom-hello;

    jsaddle-hello = overrideCabal (drv: {
      libraryHaskellDepends = with self; [
        jsaddle
        lens
      ];
      executableHaskellDepends = with self; [
        jsaddle-warp
        jsaddle-wkwebview
      ];
    }) super.jsaddle-hello;

    jsaddle-wkwebview = overrideCabal (drv: {
      libraryHaskellDepends = with self; [
        aeson
        data-default
        jsaddle
      ]; # cabal2nix doesn't add darwin-only deps
    }) super.jsaddle-wkwebview;

    # cabal2nix doesn't add darwin-only deps
    reflex-dom = addBuildDepend self.jsaddle-wkwebview (
      super.reflex-dom.override (drv: {
        jsaddle-webkit2gtk = null;
      })
    );

    # Remove a problematic assert, the length is sometimes 1 instead of 2 on darwin
    di-core = overrideCabal (drv: {
      preConfigure = ''
        substituteInPlace test/Main.hs --replace-fail \
          "2 @=? List.length (List.nub (List.sort (map Di.log_time logs)))" ""
      '';
    }) super.di-core;

    # Template Haskell on Darwin fails to load an available symbol in these
    # transitive dependencies since GHC 9.10.3.
    # See issue https://github.com/NixOS/nixpkgs/issues/461651
    hercules-ci-agent = overrideCabal (old: {
      preBuild = ''
        DYLD_INSERT_LIBRARIES="''${DYLD_INSERT_LIBRARIES:+$DYLD_INSERT_LIBRARIES:}$(pkg-config --variable=libdir nix-store)/libnixstore.dylib:$(pkg-config --variable=libdir nix-util)/libnixutil.dylib"
        export DYLD_INSERT_LIBRARIES
        echo "DYLD_INSERT_LIBRARIES=$DYLD_INSERT_LIBRARIES"
      ''
      + (old.preBuild or "");
    }) super.hercules-ci-agent;

    # Template Haskell on Darwin fails to load an available symbol in these
    # transitive dependencies since GHC 9.10.3.
    # See issue https://github.com/NixOS/nixpkgs/issues/461651
    cachix = overrideCabal (old: {
      preBuild = ''
        DYLD_INSERT_LIBRARIES="''${DYLD_INSERT_LIBRARIES:+$DYLD_INSERT_LIBRARIES:}$(pkg-config --variable=libdir nix-store)/libnixstore.dylib:$(pkg-config --variable=libdir nix-util)/libnixutil.dylib"
        export DYLD_INSERT_LIBRARIES
        echo "DYLD_INSERT_LIBRARIES=$DYLD_INSERT_LIBRARIES"
      ''
      + (old.preBuild or "");
    }) super.cachix;

    # Require /usr/bin/security which breaks sandbox
    http-reverse-proxy = dontCheck super.http-reverse-proxy;
    servant-auth-server = dontCheck super.servant-auth-server;

    sysinfo = dontCheck super.sysinfo;

    network = overrideCabal (drv: {
      __darwinAllowLocalNetworking = true;
    }) super.network;
  }
  // lib.optionalAttrs pkgs.stdenv.hostPlatform.isAarch64 {
    # aarch64-darwin

    # Workarounds for justStaticExecutables on aarch64-darwin. Since dead code
    # elimination barely works on aarch64-darwin, any package that has a
    # dependency that uses a Paths_ module will incur a reference on GHC, making
    # it fail with disallowGhcReference (which is set by justStaticExecutables).
    #
    # To address this, you can either manually remove the references causing this
    # after verifying they are indeed erroneous (e.g. cabal2nix) or just disable
    # the check, sticking with the status quo. Ideally there'll be zero cases of
    # the latter in the future!
    cabal2nix = overrideCabal (old: {
      postInstall = ''
        remove-references-to -t ${self.hpack} "''${!outputBin}/bin/cabal2nix"
        # Note: The `data` output is needed at runtime.
        remove-references-to -t ${self.distribution-nixpkgs.out} "''${!outputBin}/bin/hackage2nix"

        ${old.postInstall or ""}
      '';
    }) super.cabal2nix;
    cabal2nix-unstable = overrideCabal (old: {
      postInstall = ''
        remove-references-to -t ${self.hpack} "''${!outputBin}/bin/cabal2nix"
        # Note: The `data` output is needed at runtime.
        remove-references-to -t ${self.distribution-nixpkgs-unstable.out} "''${!outputBin}/bin/hackage2nix"

        ${old.postInstall or ""}
      '';
    }) super.cabal2nix-unstable;
    happy = overrideCabal (old: {
      postInstall = ''
        remove-references-to -t ${lib.getLib self.happy-lib} "''${!outputBin}/bin/happy"

        ${old.postInstall or ""}
      '';
    }) super.happy;
    hadolint = overrideCabal (old: {
      postInstall = ''
        remove-references-to -t ${self.ShellCheck} "$out/bin/hadolint"

        ${old.postInstall or ""}
      '';
    }) super.hadolint;

    # https://github.com/fpco/unliftio/issues/87
    unliftio = dontCheck super.unliftio;
    # This is the same issue as above; the rio tests call functions in unliftio
    # that have issues as tracked in the GitHub issue above. Once the unliftio
    # tests are fixed, we can remove this as well.
    #
    # We skip just the problematic tests by replacing 'it' with 'xit'.
    rio = overrideCabal (drv: {
      preConfigure = ''
        sed -i 's/\bit /xit /g' test/RIO/FileSpec.hs
      '';
    }) super.rio;

    # Don't use homebrew icu on macOS
    # https://github.com/NixOS/nixpkgs/issues/462046
    text-icu = disableCabalFlag "homebrew" super.text-icu;

    # https://github.com/haskell-crypto/cryptonite/issues/360
    cryptonite = appendPatch ./patches/cryptonite-remove-argon2.patch super.cryptonite;

    # Build segfaults unless `fixity-th` is disabled.
    # https://github.com/tweag/ormolu/issues/927
    ormolu = overrideCabal (drv: {
      libraryHaskellDepends = drv.libraryHaskellDepends ++ [ self.file-embed ];
    }) (disableCabalFlag "fixity-th" super.ormolu);
    fourmolu = overrideCabal (drv: {
      libraryHaskellDepends = drv.libraryHaskellDepends ++ [ self.file-embed ];
    }) (disableCabalFlag "fixity-th" super.fourmolu);

    Agda = lib.pipe super.Agda [
      # https://github.com/NixOS/nixpkgs/issues/149692
      (disableCabalFlag "optimise-heavily")
      # https://github.com/agda/agda/issues/8016
      (appendConfigureFlag "--ghc-option=-Wwarn=deprecations")
    ];

    # https://github.com/NixOS/nixpkgs/issues/198495
    eventsourcing-postgresql = dontCheck super.eventsourcing-postgresql;
    gargoyle-postgresql-connect = dontCheck super.gargoyle-postgresql-connect;
    hs-opentelemetry-instrumentation-postgresql-simple = dontCheck super.hs-opentelemetry-instrumentation-postgresql-simple;
    moto-postgresql = dontCheck super.moto-postgresql;
    persistent-postgresql = dontCheck super.persistent-postgresql;
    pipes-postgresql-simple = dontCheck super.pipes-postgresql-simple;
    postgresql-connector = dontCheck super.postgresql-connector;
    postgresql-migration = dontCheck super.postgresql-migration;
    postgresql-schema = dontCheck super.postgresql-schema;
    postgresql-simple = dontCheck super.postgresql-simple;
    postgresql-simple-interpolate = dontCheck super.postgresql-simple-interpolate;
    postgresql-simple-migration = dontCheck super.postgresql-simple-migration;
    postgresql-simple-url = dontCheck super.postgresql-simple-url;
    postgresql-transactional = dontCheck super.postgresql-transactional;
    postgrest = dontCheck super.postgrest;
    rivet-adaptor-postgresql = dontCheck super.rivet-adaptor-postgresql;
    tmp-proc-postgres = dontCheck super.tmp-proc-postgres;

  }
  // lib.optionalAttrs pkgs.stdenv.hostPlatform.isx86_64 {
    # x86_64-darwin

    # tests appear to be failing to link or something:
    # https://hydra.nixos.org/build/174540882/nixlog/9
    regex-rure = dontCheck super.regex-rure;
    # same
    # https://hydra.nixos.org/build/174540882/nixlog/9
    jacinda = dontCheck super.jacinda;

    # Greater floating point error on x86_64-darwin (!) for some reason
    # https://github.com/ekmett/ad/issues/113
    ad = overrideCabal (drv: {
      testFlags = drv.testFlags or [ ] ++ [
        "-p"
        "!/issue-108/"
      ];
    }) super.ad;
  }
)