at master 2.0 kB view raw
1{ 2 stdenv, 3 ghc, 4 pkg-config, 5 glibcLocales, 6 cacert, 7 stack, 8 makeSetupHook, 9 lib, 10}@depArgs: 11 12{ 13 buildInputs ? [ ], 14 nativeBuildInputs ? [ ], 15 extraArgs ? [ ], 16 LD_LIBRARY_PATH ? [ ], 17 ghc ? depArgs.ghc, 18 stack ? depArgs.stack, 19 ... 20}@args: 21 22let 23 24 stackCmd = "stack --internal-re-exec-version=${stack.version}"; 25 26 # Add all dependencies in buildInputs including propagated ones to 27 # STACK_IN_NIX_EXTRA_ARGS. 28 stackHook = makeSetupHook { 29 name = "stack-hook"; 30 } ./stack-hook.sh; 31 32in 33stdenv.mkDerivation ( 34 args 35 // { 36 37 # Doesn't work in the sandbox. Pass `--option sandbox relaxed` or 38 # `--option sandbox false` to be able to build this 39 __noChroot = true; 40 41 buildInputs = buildInputs ++ lib.optional (stdenv.hostPlatform.libc == "glibc") glibcLocales; 42 43 nativeBuildInputs = nativeBuildInputs ++ [ 44 ghc 45 pkg-config 46 stack 47 stackHook 48 ]; 49 50 STACK_PLATFORM_VARIANT = "nix"; 51 STACK_IN_NIX_SHELL = 1; 52 STACK_IN_NIX_EXTRA_ARGS = extraArgs; 53 54 # XXX: workaround for https://ghc.haskell.org/trac/ghc/ticket/11042. 55 LD_LIBRARY_PATH = lib.makeLibraryPath (LD_LIBRARY_PATH ++ buildInputs); 56 # ^^^ Internally uses `getOutput "lib"` (equiv. to getLib) 57 58 # Non-NixOS git needs cert 59 GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; 60 61 # Fixes https://github.com/commercialhaskell/stack/issues/2358 62 LANG = "en_US.UTF-8"; 63 64 preferLocalBuild = true; 65 66 preConfigure = '' 67 export STACK_ROOT=$NIX_BUILD_TOP/.stack 68 ''; 69 70 buildPhase = 71 args.buildPhase or '' 72 runHook preBuild 73 74 ${stackCmd} build 75 76 runHook postBuild 77 ''; 78 79 checkPhase = 80 args.checkPhase or '' 81 runHook preCheck 82 83 ${stackCmd} test 84 85 runHook postCheck 86 ''; 87 88 doCheck = args.doCheck or true; 89 90 installPhase = 91 args.installPhase or '' 92 runHook preInstall 93 94 ${stackCmd} --local-bin-path=$out/bin build --copy-bins 95 96 runHook postInstall 97 ''; 98 } 99)