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