|
| 1 | +{ system ? "aarch64-darwin" |
| 2 | +#, nixpkgs ? fetchTarball https://github.com/angerman/nixpkgs/archive/257cb120334.tar.gz #apple-silicon.tar.gz |
| 3 | +, pkgs ? import <nixpkgs> { inherit system; } |
| 4 | +, compiler ? if system == "aarch64-darwin" then "ghc8103Binary" else "ghc8103" |
| 5 | +}: pkgs.mkShell { |
| 6 | + # this prevents nix from trying to write the env-vars file. |
| 7 | + # we can't really, as NIX_BUILD_TOP/env-vars is not set. |
| 8 | + noDumpEnvVars=1; |
| 9 | + |
| 10 | + # stop polluting LDFLAGS with -liconv |
| 11 | + dontAddExtraLibs = true; |
| 12 | + |
| 13 | + # we need to inject ncurses into --with-curses-libraries. |
| 14 | + # the real fix is to teach terminfo to use libcurses on macOS. |
| 15 | + # CONFIGURE_ARGS = "--with-intree-gmp --with-curses-libraries=${pkgs.ncurses.out}/lib"; |
| 16 | + CONFIGURE_ARGS = "--with-intree-gmp --with-curses-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib --with-iconv-includes=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include --with-iconv-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib SH=/bin/bash"; |
| 17 | + |
| 18 | + # magic speedup pony :facepalm: |
| 19 | + # |
| 20 | + # nix has the ugly habbit of duplicating ld flags more than necessary. This |
| 21 | + # somewhat consolidates this. |
| 22 | + shellHook = '' |
| 23 | + export NIX_LDFLAGS=$(for a in $NIX_LDFLAGS; do echo $a; done |sort|uniq|xargs) |
| 24 | + export NIX_LDFLAGS_FOR_TARGET=$(for a in $NIX_LDFLAGS_FOR_TARGET; do echo $a; done |sort|uniq|xargs) |
| 25 | + export NIX_LDFLAGS_FOR_TARGET=$(comm -3 <(for l in $NIX_LDFLAGS_FOR_TARGET; do echo $l; done) <(for l in $NIX_LDFLAGS; do echo $l; done)) |
| 26 | +
|
| 27 | +
|
| 28 | + # Impurity hack for GHC releases. |
| 29 | + ################################# |
| 30 | + # We don't want binary releases to depend on nix, thus we'll need to make sure we don't leak in references. |
| 31 | + # GHC externally depends only on iconv and curses. However we can't force a specific curses library for |
| 32 | + # the terminfo package, as such we'll need to make sure we only look in the system path for the curses library |
| 33 | + # and not pick up the tinfo from the nix provided ncurses package. |
| 34 | + # |
| 35 | + # We also need to force us to use the systems COREFOUNDATION, not the one that nix builds. Again this is impure, |
| 36 | + # but it will allow us to have proper binary distributions. |
| 37 | + # |
| 38 | + # do not use nixpkgs provided core foundation |
| 39 | + export NIX_COREFOUNDATION_RPATH=/System/Library/Frameworks |
| 40 | + # drop curses from the LDFLAGS, we really want the system ones, not the nix ones. |
| 41 | + export NIX_LDFLAGS=$(for lib in $NIX_LDFLAGS; do case "$lib" in *curses*);; *) echo -n "$lib ";; esac; done;) |
| 42 | + export NIX_CFLAGS_COMPILE+=" -Wno-nullability-completeness -Wno-availability -Wno-expansion-to-defined -Wno-builtin-requires-header -Wno-unused-command-line-argument" |
| 43 | +
|
| 44 | + # unconditionally add the MacOSX.sdk and TargetConditional.h |
| 45 | + export NIX_CFLAGS_COMPILE+=" -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" |
| 46 | + export NIX_LDFLAGS="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib $NIX_LDFLAGS" |
| 47 | +
|
| 48 | + ''; |
| 49 | + |
| 50 | + nativeBuildInputs = (with pkgs; [ |
| 51 | + # This needs to come *before* ghc, |
| 52 | + # otherwise we migth end up with the clang from |
| 53 | + # the bootstrap GHC in PATH with higher priority. |
| 54 | + clang_11 |
| 55 | + llvm_11 |
| 56 | + |
| 57 | + haskell.compiler.${compiler} |
| 58 | + haskell.packages.${compiler}.cabal-install |
| 59 | + haskell.packages.${compiler}.alex |
| 60 | + haskell.packages.${compiler}.happy # _1_19_12 is needed for older GHCs. |
| 61 | + |
| 62 | + automake |
| 63 | + autoconf |
| 64 | + m4 |
| 65 | + |
| 66 | + gmp |
| 67 | + zlib.out |
| 68 | + zlib.dev |
| 69 | + glibcLocales |
| 70 | + # locale doesn't build yet :-/ |
| 71 | + # locale |
| 72 | + |
| 73 | + git |
| 74 | + |
| 75 | + python3 |
| 76 | + # python3Full |
| 77 | + # python3Packages.sphinx |
| 78 | + perl |
| 79 | + |
| 80 | + which |
| 81 | + wget |
| 82 | + curl |
| 83 | + file |
| 84 | + |
| 85 | + xz |
| 86 | + xlibs.lndir |
| 87 | + |
| 88 | + cacert ]) |
| 89 | + ++ (with pkgs.darwin.apple_sdk.frameworks; [ Foundation Security ]); |
| 90 | +} |
0 commit comments