haskell.buildStackProject: use setup hook
This makes things easier and hopefully fixes the arg too long issue. Fixes #49206.
This commit is contained in:
parent
04beae0979
commit
0dabacae00
@ -1,6 +1,5 @@
|
|||||||
{ stdenv, ghc, pkgconfig, glibcLocales, cacert, stack }@depArgs:
|
{ stdenv, ghc, pkgconfig, glibcLocales
|
||||||
|
, cacert, stack, makeSetupHook, lib }@depArgs:
|
||||||
with stdenv.lib;
|
|
||||||
|
|
||||||
{ buildInputs ? []
|
{ buildInputs ? []
|
||||||
, extraArgs ? []
|
, extraArgs ? []
|
||||||
@ -10,34 +9,27 @@ with stdenv.lib;
|
|||||||
, ...
|
, ...
|
||||||
}@args:
|
}@args:
|
||||||
|
|
||||||
let stackCmd = "stack --internal-re-exec-version=${stack.version}";
|
let
|
||||||
|
|
||||||
|
stackCmd = "stack --internal-re-exec-version=${stack.version}";
|
||||||
|
|
||||||
|
# Add all dependencies in buildInputs including propagated ones to
|
||||||
|
# STACK_IN_NIX_EXTRA_ARGS.
|
||||||
|
stackHook = makeSetupHook {} ./stack-hook.sh;
|
||||||
|
|
||||||
# Add all dependencies in buildInputs including propagated ones to
|
|
||||||
# STACK_IN_NIX_EXTRA_ARGS.
|
|
||||||
addStackArgsHook = ''
|
|
||||||
for pkg in ''${pkgsHostHost[@]} ''${pkgsHostBuild[@]} ''${pkgsHostTarget[@]}
|
|
||||||
do
|
|
||||||
[ -d "$pkg/lib" ] && \
|
|
||||||
export STACK_IN_NIX_EXTRA_ARGS+=" --extra-lib-dirs=$pkg/lib"
|
|
||||||
[ -d "$pkg/include" ] && \
|
|
||||||
export STACK_IN_NIX_EXTRA_ARGS+=" --extra-include-dirs=$pkg/include"
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
in stdenv.mkDerivation (args // {
|
in stdenv.mkDerivation (args // {
|
||||||
|
|
||||||
buildInputs =
|
buildInputs = buildInputs
|
||||||
buildInputs ++
|
++ lib.optional (stdenv.hostPlatform.libc == "glibc") glibcLocales;
|
||||||
optional (stdenv.hostPlatform.libc == "glibc") glibcLocales ++
|
|
||||||
[ ghc pkgconfig stack ];
|
|
||||||
|
|
||||||
STACK_PLATFORM_VARIANT="nix";
|
nativeBuildInputs = [ ghc pkgconfig stack stackHook ];
|
||||||
STACK_IN_NIX_SHELL=1;
|
|
||||||
|
STACK_PLATFORM_VARIANT = "nix";
|
||||||
|
STACK_IN_NIX_SHELL = 1;
|
||||||
STACK_IN_NIX_EXTRA_ARGS = extraArgs;
|
STACK_IN_NIX_EXTRA_ARGS = extraArgs;
|
||||||
shellHook = addStackArgsHook + args.shellHook or "";
|
|
||||||
|
|
||||||
|
|
||||||
# XXX: workaround for https://ghc.haskell.org/trac/ghc/ticket/11042.
|
# XXX: workaround for https://ghc.haskell.org/trac/ghc/ticket/11042.
|
||||||
LD_LIBRARY_PATH = makeLibraryPath (LD_LIBRARY_PATH ++ buildInputs);
|
LD_LIBRARY_PATH = lib.makeLibraryPath (LD_LIBRARY_PATH ++ buildInputs);
|
||||||
# ^^^ Internally uses `getOutput "lib"` (equiv. to getLib)
|
# ^^^ Internally uses `getOutput "lib"` (equiv. to getLib)
|
||||||
|
|
||||||
# Non-NixOS git needs cert
|
# Non-NixOS git needs cert
|
||||||
@ -48,18 +40,33 @@ in stdenv.mkDerivation (args // {
|
|||||||
|
|
||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
|
|
||||||
configurePhase = args.configurePhase or ''
|
preConfigure = ''
|
||||||
export STACK_ROOT=$NIX_BUILD_TOP/.stack
|
export STACK_ROOT=$NIX_BUILD_TOP/.stack
|
||||||
${addStackArgsHook}
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
buildPhase = args.buildPhase or "${stackCmd} build";
|
buildPhase = args.buildPhase or ''
|
||||||
|
runHook preBuild
|
||||||
|
|
||||||
checkPhase = args.checkPhase or "${stackCmd} test";
|
${stackCmd} build
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
|
||||||
|
checkPhase = args.checkPhase or ''
|
||||||
|
runHook preCheck
|
||||||
|
|
||||||
|
${stackCmd} test
|
||||||
|
|
||||||
|
runHook postCheck
|
||||||
|
'';
|
||||||
|
|
||||||
doCheck = args.doCheck or true;
|
doCheck = args.doCheck or true;
|
||||||
|
|
||||||
installPhase = args.installPhase or ''
|
installPhase = args.installPhase or ''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
${stackCmd} --local-bin-path=$out/bin build --copy-bins
|
${stackCmd} --local-bin-path=$out/bin build --copy-bins
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
11
pkgs/development/haskell-modules/stack-hook.sh
Normal file
11
pkgs/development/haskell-modules/stack-hook.sh
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
addStackArgs () {
|
||||||
|
if [ -d "$1/lib" ] && [[ "$STACK_IN_NIX_EXTRA_ARGS" != *"--extra-lib-dirs=$1/lib"* ]]; then
|
||||||
|
STACK_IN_NIX_EXTRA_ARGS+=" --extra-lib-dirs=$1/lib"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "$1/include" ] && [[ "$STACK_IN_NIX_EXTRA_ARGS" != *"--extra-include-dirs=$1/include"* ]]; then
|
||||||
|
STACK_IN_NIX_EXTRA_ARGS+=" --extra-include-dirs=$1/include"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
addEnvHooks "$hostOffset" addStackArgs
|
Loading…
x
Reference in New Issue
Block a user