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