From 579bc49e9485b337b0b13671fc3e368c6c93483b Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 25 Nov 2021 13:44:50 +0100 Subject: [PATCH 1/7] haskell.compiler.ghc*Binary: don't propagate LLVM, use wrapper Copy the approach from the normal GHC derivations for adding an `export PATH` into the scripts in `$out/bin` and use it to put the specific LLVM version of the binary GHC into its PATH. This will prevent the LLVM version of the GHC we are building later to take precedence over the LLVM version this GHC needs. --- pkgs/development/compilers/ghc/8.10.2-binary.nix | 16 ++++++++++++++-- pkgs/development/compilers/ghc/8.10.7-binary.nix | 16 +++++++++++++--- pkgs/development/compilers/ghc/8.6.5-binary.nix | 14 +++++++++++++- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.2-binary.nix b/pkgs/development/compilers/ghc/8.10.2-binary.nix index 93ebca2b6c4a..d610e4bcd8cb 100644 --- a/pkgs/development/compilers/ghc/8.10.2-binary.nix +++ b/pkgs/development/compilers/ghc/8.10.2-binary.nix @@ -140,6 +140,10 @@ let libEnvVar = lib.optionalString stdenv.hostPlatform.isDarwin "DY" + "LD_LIBRARY_PATH"; + runtimeDeps = lib.optionals useLLVM [ + (lib.getBin llvmPackages.llvm) + ]; + in stdenv.mkDerivation rec { @@ -156,7 +160,6 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ perl ]; propagatedBuildInputs = - lib.optionals useLLVM [ llvmPackages.llvm ] # Because musl bindists currently provide no way to tell where # libgmp is (see not [musl bindists have no .buildinfo]), we need # to propagate `gmp`, otherwise programs built by this ghc will @@ -177,7 +180,7 @@ stdenv.mkDerivation rec { # fixing the above-mentioned release issue, # and for GHC >= 9.* it is not clear as of writing whether that switch # will be made there too. - ++ lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this + lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this # Set LD_LIBRARY_PATH or equivalent so that the programs running as part # of the bindist installer can find the libraries they expect. @@ -278,6 +281,15 @@ stdenv.mkDerivation rec { # calls install-strip ... dontBuild = true; + # Patch scripts to include runtime dependencies in $PATH. + postInstall = '' + for i in "$out/bin/"*; do + test ! -h "$i" || continue + isScript "$i" || continue + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i" + done + ''; + # Apparently necessary for the ghc Alpine (musl) bindist: # When we strip, and then run the # patchelf --set-rpath "${libPath}:$(patchelf --print-rpath $p)" $p diff --git a/pkgs/development/compilers/ghc/8.10.7-binary.nix b/pkgs/development/compilers/ghc/8.10.7-binary.nix index a8ec751d2d24..b8164ae9f6f3 100644 --- a/pkgs/development/compilers/ghc/8.10.7-binary.nix +++ b/pkgs/development/compilers/ghc/8.10.7-binary.nix @@ -155,6 +155,10 @@ let libEnvVar = lib.optionalString stdenv.hostPlatform.isDarwin "DY" + "LD_LIBRARY_PATH"; + runtimeDeps = lib.optionals useLLVM [ + (lib.getBin llvmPackages.llvm) + ]; + in stdenv.mkDerivation rec { @@ -175,9 +179,6 @@ stdenv.mkDerivation rec { # and update this comment accordingly. nativeBuildInputs = [ perl ]; - propagatedBuildInputs = - lib.optionals useLLVM [ llvmPackages.llvm ] - ; # Set LD_LIBRARY_PATH or equivalent so that the programs running as part # of the bindist installer can find the libraries they expect. @@ -278,6 +279,15 @@ stdenv.mkDerivation rec { # calls install-strip ... dontBuild = true; + # Patch scripts to include runtime dependencies in $PATH. + postInstall = '' + for i in "$out/bin/"*; do + test ! -h "$i" || continue + isScript "$i" || continue + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i" + done + ''; + # Apparently necessary for the ghc Alpine (musl) bindist: # When we strip, and then run the # patchelf --set-rpath "${libPath}:$(patchelf --print-rpath $p)" $p diff --git a/pkgs/development/compilers/ghc/8.6.5-binary.nix b/pkgs/development/compilers/ghc/8.6.5-binary.nix index e8ae6761be8d..95b381b955fd 100644 --- a/pkgs/development/compilers/ghc/8.6.5-binary.nix +++ b/pkgs/development/compilers/ghc/8.6.5-binary.nix @@ -30,6 +30,10 @@ let downloadsUrl = "https://downloads.haskell.org/ghc"; + runtimeDeps = lib.optionals useLLVM [ + (lib.getBin llvmPackages.llvm) + ]; + in stdenv.mkDerivation rec { @@ -62,7 +66,6 @@ stdenv.mkDerivation rec { or (throw "cannot bootstrap GHC on this platform")); nativeBuildInputs = [ perl ]; - propagatedBuildInputs = lib.optionals useLLVM [ llvmPackages.llvm ]; # Cannot patchelf beforehand due to relative RPATHs that anticipate # the final install location/ @@ -130,6 +133,15 @@ stdenv.mkDerivation rec { # calls install-strip ... dontBuild = true; + # Patch scripts to include runtime dependencies in $PATH. + postInstall = '' + for i in "$out/bin/"*; do + test ! -h "$i" || continue + isScript "$i" || continue + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i" + done + ''; + # On Linux, use patchelf to modify the executables so that they can # find editline/gmp. postFixup = lib.optionalString stdenv.isLinux '' From 5384a35a0c5198e224435b7295b3d273e645243d Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 25 Nov 2021 13:52:57 +0100 Subject: [PATCH 2/7] haskell.compiler.ghc*Binary: add all missing runtimeDeps to PATH This brings the binary GHCs on parity with the source built ones in terms of the wrapper. The upshot of this is that compiling something using the binary GHCs no longer depends on PATH being populated with the tools included in stdenv at all. We can even test this by running the installCheck with an empty environment (via `env -i`). --- .../compilers/ghc/8.10.2-binary.nix | 18 +++++++++++++++--- .../compilers/ghc/8.10.7-binary.nix | 16 +++++++++++++--- .../development/compilers/ghc/8.6.5-binary.nix | 16 +++++++++++++--- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.2-binary.nix b/pkgs/development/compilers/ghc/8.10.2-binary.nix index d610e4bcd8cb..a29a5b0b5ab6 100644 --- a/pkgs/development/compilers/ghc/8.10.2-binary.nix +++ b/pkgs/development/compilers/ghc/8.10.2-binary.nix @@ -3,6 +3,8 @@ , ncurses5 , ncurses6, gmp, libiconv, numactl , llvmPackages +, coreutils +, targetPackages # minimal = true; will remove files that aren't strictly necessary for # regular builds and GHC bootstrapping. @@ -140,8 +142,17 @@ let libEnvVar = lib.optionalString stdenv.hostPlatform.isDarwin "DY" + "LD_LIBRARY_PATH"; - runtimeDeps = lib.optionals useLLVM [ + runtimeDeps = [ + targetPackages.stdenv.cc + targetPackages.stdenv.cc.bintools + coreutils # for cat + ] + ++ lib.optionals useLLVM [ (lib.getBin llvmPackages.llvm) + ] + # On darwin, we need unwrapped bintools as well (for otool) + ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ + targetPackages.stdenv.cc.bintools.bintools ]; in @@ -372,7 +383,6 @@ stdenv.mkDerivation rec { doInstallCheck = true; installCheckPhase = '' - unset ${libEnvVar} # Sanity check, can ghc create executables? cd $TMP mkdir test-ghc; cd test-ghc @@ -381,7 +391,9 @@ stdenv.mkDerivation rec { module Main where main = putStrLn \$([|"yes"|]) EOF - $out/bin/ghc --make main.hs || exit 1 + # can't use env -i here because otherwise we don't find -lgmp on musl + env ${libEnvVar}= PATH= \ + $out/bin/ghc --make main.hs || exit 1 echo compilation ok [ $(./main) == "yes" ] ''; diff --git a/pkgs/development/compilers/ghc/8.10.7-binary.nix b/pkgs/development/compilers/ghc/8.10.7-binary.nix index b8164ae9f6f3..7b10f60affda 100644 --- a/pkgs/development/compilers/ghc/8.10.7-binary.nix +++ b/pkgs/development/compilers/ghc/8.10.7-binary.nix @@ -3,6 +3,8 @@ , ncurses5 , ncurses6, gmp, libiconv, numactl , llvmPackages +, coreutils +, targetPackages # minimal = true; will remove files that aren't strictly necessary for # regular builds and GHC bootstrapping. @@ -155,8 +157,17 @@ let libEnvVar = lib.optionalString stdenv.hostPlatform.isDarwin "DY" + "LD_LIBRARY_PATH"; - runtimeDeps = lib.optionals useLLVM [ + runtimeDeps = [ + targetPackages.stdenv.cc + targetPackages.stdenv.cc.bintools + coreutils # for cat + ] + ++ lib.optionals useLLVM [ (lib.getBin llvmPackages.llvm) + ] + # On darwin, we need unwrapped bintools as well (for otool) + ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ + targetPackages.stdenv.cc.bintools.bintools ]; in @@ -370,7 +381,6 @@ stdenv.mkDerivation rec { doInstallCheck = true; installCheckPhase = '' - unset ${libEnvVar} # Sanity check, can ghc create executables? cd $TMP mkdir test-ghc; cd test-ghc @@ -379,7 +389,7 @@ stdenv.mkDerivation rec { module Main where main = putStrLn \$([|"yes"|]) EOF - $out/bin/ghc --make main.hs || exit 1 + env -i $out/bin/ghc --make main.hs || exit 1 echo compilation ok [ $(./main) == "yes" ] ''; diff --git a/pkgs/development/compilers/ghc/8.6.5-binary.nix b/pkgs/development/compilers/ghc/8.6.5-binary.nix index 95b381b955fd..22bfae79c0ce 100644 --- a/pkgs/development/compilers/ghc/8.6.5-binary.nix +++ b/pkgs/development/compilers/ghc/8.6.5-binary.nix @@ -2,6 +2,8 @@ , fetchurl, perl, gcc , ncurses5, ncurses6, gmp, glibc, libiconv , llvmPackages +, coreutils +, targetPackages }: # Prebuilt only does native @@ -30,8 +32,17 @@ let downloadsUrl = "https://downloads.haskell.org/ghc"; - runtimeDeps = lib.optionals useLLVM [ + runtimeDeps = [ + targetPackages.stdenv.cc + targetPackages.stdenv.cc.bintools + coreutils # for cat + ] + ++ lib.optionals useLLVM [ (lib.getBin llvmPackages.llvm) + ] + # On darwin, we need unwrapped bintools as well (for otool) + ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ + targetPackages.stdenv.cc.bintools.bintools ]; in @@ -175,7 +186,6 @@ stdenv.mkDerivation rec { doInstallCheck = true; installCheckPhase = '' - unset ${libEnvVar} # Sanity check, can ghc create executables? cd $TMP mkdir test-ghc; cd test-ghc @@ -184,7 +194,7 @@ stdenv.mkDerivation rec { module Main where main = putStrLn \$([|"yes"|]) EOF - $out/bin/ghc --make main.hs || exit 1 + env -i $out/bin/ghc --make main.hs || exit 1 echo compilation ok [ $(./main) == "yes" ] ''; From 035f20bc6bf809c7be9bb5b6d4dd19b0a2df9d17 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 25 Nov 2021 13:12:40 +0100 Subject: [PATCH 3/7] haskell.compiler.*: prefix PATH with runtimeDeps This will prevent freak accidents where the wrong tools are used because they are in PATH by chance. --- pkgs/development/compilers/ghc/8.10.7.nix | 6 +++--- pkgs/development/compilers/ghc/8.8.4.nix | 6 +++--- pkgs/development/compilers/ghc/9.0.1.nix | 6 +++--- pkgs/development/compilers/ghc/9.2.1.nix | 6 +++--- pkgs/development/compilers/ghc/head.nix | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index f0c57f7fae8b..9cf459f45167 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -134,7 +134,7 @@ let runtimeDeps = [ targetPackages.stdenv.cc.bintools - coreutils + coreutils # for cat ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -321,11 +321,11 @@ stdenv.mkDerivation (rec { # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc - # Patch scripts to include "readelf" and "cat" in $PATH. + # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do test ! -h $i || continue egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i done ''; diff --git a/pkgs/development/compilers/ghc/8.8.4.nix b/pkgs/development/compilers/ghc/8.8.4.nix index e0f6c84637b2..069657808a35 100644 --- a/pkgs/development/compilers/ghc/8.8.4.nix +++ b/pkgs/development/compilers/ghc/8.8.4.nix @@ -142,7 +142,7 @@ let runtimeDeps = [ targetPackages.stdenv.cc.bintools - coreutils + coreutils # for cat ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -320,11 +320,11 @@ stdenv.mkDerivation (rec { # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc - # Patch scripts to include "readelf" and "cat" in $PATH. + # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do test ! -h $i || continue egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i done ''; diff --git a/pkgs/development/compilers/ghc/9.0.1.nix b/pkgs/development/compilers/ghc/9.0.1.nix index 005333a8d83e..3f2ea4dedca5 100644 --- a/pkgs/development/compilers/ghc/9.0.1.nix +++ b/pkgs/development/compilers/ghc/9.0.1.nix @@ -129,7 +129,7 @@ let runtimeDeps = [ targetPackages.stdenv.cc.bintools - coreutils + coreutils # for cat ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -286,11 +286,11 @@ stdenv.mkDerivation (rec { # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc - # Patch scripts to include "readelf" and "cat" in $PATH. + # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do test ! -h $i || continue egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i done ''; diff --git a/pkgs/development/compilers/ghc/9.2.1.nix b/pkgs/development/compilers/ghc/9.2.1.nix index 2ebbdc63ac93..d1c69e5c4633 100644 --- a/pkgs/development/compilers/ghc/9.2.1.nix +++ b/pkgs/development/compilers/ghc/9.2.1.nix @@ -128,7 +128,7 @@ let runtimeDeps = [ targetPackages.stdenv.cc.bintools - coreutils + coreutils # for cat ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -289,11 +289,11 @@ stdenv.mkDerivation (rec { # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc - # Patch scripts to include "readelf" and "cat" in $PATH. + # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do test ! -h $i || continue egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i done ''; diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix index f50b3b76e15d..50bd9527093b 100644 --- a/pkgs/development/compilers/ghc/head.nix +++ b/pkgs/development/compilers/ghc/head.nix @@ -142,7 +142,7 @@ let runtimeDeps = [ targetPackages.stdenv.cc.bintools - coreutils + coreutils # for cat ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -309,11 +309,11 @@ stdenv.mkDerivation (rec { # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc - # Patch scripts to include "readelf" and "cat" in $PATH. + # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do test ! -h $i || continue egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i done ''; From f5c3b6523cab9861a343b1f49081205d799695c6 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 25 Nov 2021 13:58:06 +0100 Subject: [PATCH 4/7] haskell.compiler.*: move propagatedBuildInputs into runtimeDeps This has two main benefits: * GHC will work reliably outside of stdenv, even when using -fllvm since everything it'll call at runtime will be provided in PATH via the wrapper scripts. * LLVM will no longer leak into haskell packages' configure scripts. This was an issue with llvm-hs which fails to build if the LLVM version of the compiler since the propagatedBuildInputs of GHC take precedence over the nativeBuildInputs added in the derivation. --- pkgs/development/compilers/ghc/8.10.7.nix | 9 ++++++--- pkgs/development/compilers/ghc/8.8.4.nix | 9 ++++++--- pkgs/development/compilers/ghc/9.0.1.nix | 9 ++++++--- pkgs/development/compilers/ghc/9.2.1.nix | 9 ++++++--- pkgs/development/compilers/ghc/head.nix | 9 ++++++--- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 9cf459f45167..f2f1bfc64e14 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -132,9 +132,15 @@ let useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); + # Tools GHC will need to call at runtime. Some of these were handled using + # propagatedBuildInputs before, however this allowed for GHC environment and + # a derivations build environment to interfere, especially when GHC is built. runtimeDeps = [ + targetPackages.stdenv.cc targetPackages.stdenv.cc.bintools coreutils # for cat + ] ++ lib.optionals useLLVM [ + (lib.getBin llvmPackages.llvm) ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -290,9 +296,6 @@ stdenv.mkDerivation (rec { buildInputs = [ perl bash ] ++ (libDeps hostPlatform); - propagatedBuildInputs = [ targetPackages.stdenv.cc ] - ++ lib.optional useLLVM llvmPackages.llvm; - depsTargetTarget = map lib.getDev (libDeps targetPlatform); depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); diff --git a/pkgs/development/compilers/ghc/8.8.4.nix b/pkgs/development/compilers/ghc/8.8.4.nix index 069657808a35..44d8d33fecc4 100644 --- a/pkgs/development/compilers/ghc/8.8.4.nix +++ b/pkgs/development/compilers/ghc/8.8.4.nix @@ -140,9 +140,15 @@ let useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); + # Tools GHC will need to call at runtime. Some of these were handled using + # propagatedBuildInputs before, however this allowed for GHC environment and + # a derivations build environment to interfere, especially when GHC is built. runtimeDeps = [ + targetPackages.stdenv.cc targetPackages.stdenv.cc.bintools coreutils # for cat + ] ++ lib.optionals useLLVM [ + (lib.getBin llvmPackages.llvm) ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -293,9 +299,6 @@ stdenv.mkDerivation (rec { buildInputs = [ perl bash ] ++ (libDeps hostPlatform); - propagatedBuildInputs = [ targetPackages.stdenv.cc ] - ++ lib.optional useLLVM llvmPackages.llvm; - depsTargetTarget = map lib.getDev (libDeps targetPlatform); depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); diff --git a/pkgs/development/compilers/ghc/9.0.1.nix b/pkgs/development/compilers/ghc/9.0.1.nix index 3f2ea4dedca5..a778fda31a73 100644 --- a/pkgs/development/compilers/ghc/9.0.1.nix +++ b/pkgs/development/compilers/ghc/9.0.1.nix @@ -127,9 +127,15 @@ let useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); + # Tools GHC will need to call at runtime. Some of these were handled using + # propagatedBuildInputs before, however this allowed for GHC environment and + # a derivations build environment to interfere, especially when GHC is built. runtimeDeps = [ + targetPackages.stdenv.cc targetPackages.stdenv.cc.bintools coreutils # for cat + ] ++ lib.optionals useLLVM [ + (lib.getBin llvmPackages.llvm) ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -255,9 +261,6 @@ stdenv.mkDerivation (rec { buildInputs = [ perl bash ] ++ (libDeps hostPlatform); - propagatedBuildInputs = [ targetPackages.stdenv.cc ] - ++ lib.optional useLLVM llvmPackages.llvm; - depsTargetTarget = map lib.getDev (libDeps targetPlatform); depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); diff --git a/pkgs/development/compilers/ghc/9.2.1.nix b/pkgs/development/compilers/ghc/9.2.1.nix index d1c69e5c4633..5442a423bdd0 100644 --- a/pkgs/development/compilers/ghc/9.2.1.nix +++ b/pkgs/development/compilers/ghc/9.2.1.nix @@ -126,9 +126,15 @@ let # see #84670 and #49071 for more background. useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && !targetPlatform.isMusl); + # Tools GHC will need to call at runtime. Some of these were handled using + # propagatedBuildInputs before, however this allowed for GHC environment and + # a derivations build environment to interfere, especially when GHC is built. runtimeDeps = [ + targetPackages.stdenv.cc targetPackages.stdenv.cc.bintools coreutils # for cat + ] ++ lib.optionals useLLVM [ + (lib.getBin llvmPackages.llvm) ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -258,9 +264,6 @@ stdenv.mkDerivation (rec { buildInputs = [ perl bash ] ++ (libDeps hostPlatform); - propagatedBuildInputs = [ targetPackages.stdenv.cc ] - ++ lib.optional useLLVM llvmPackages.llvm; - depsTargetTarget = map lib.getDev (libDeps targetPlatform); depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix index 50bd9527093b..40dbe131f9dd 100644 --- a/pkgs/development/compilers/ghc/head.nix +++ b/pkgs/development/compilers/ghc/head.nix @@ -140,9 +140,15 @@ let useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); + # Tools GHC will need to call at runtime. Some of these were handled using + # propagatedBuildInputs before, however this allowed for GHC environment and + # a derivations build environment to interfere, especially when GHC is built. runtimeDeps = [ + targetPackages.stdenv.cc targetPackages.stdenv.cc.bintools coreutils # for cat + ] ++ lib.optionals useLLVM [ + (lib.getBin llvmPackages.llvm) ] # On darwin, we need unwrapped bintools as well (for otool) ++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [ @@ -278,9 +284,6 @@ stdenv.mkDerivation (rec { buildInputs = [ perl bash ] ++ (libDeps hostPlatform); - propagatedBuildInputs = [ targetPackages.stdenv.cc ] - ++ lib.optional useLLVM llvmPackages.llvm; - depsTargetTarget = map lib.getDev (libDeps targetPlatform); depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); From a7c564596e195cf9aa46ad2762f78e4d9cc9789b Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 25 Nov 2021 14:06:35 +0100 Subject: [PATCH 5/7] haskell.compiler.*: use `isScript` over grepping for `#!` --- pkgs/development/compilers/ghc/8.10.7.nix | 6 +++--- pkgs/development/compilers/ghc/8.8.4.nix | 6 +++--- pkgs/development/compilers/ghc/9.0.1.nix | 6 +++--- pkgs/development/compilers/ghc/9.2.1.nix | 6 +++--- pkgs/development/compilers/ghc/head.nix | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index f2f1bfc64e14..bfcd53141fa0 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -326,9 +326,9 @@ stdenv.mkDerivation (rec { # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do - test ! -h $i || continue - egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i + test ! -h "$i" || continue + isScript "$i" || continue + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i" done ''; diff --git a/pkgs/development/compilers/ghc/8.8.4.nix b/pkgs/development/compilers/ghc/8.8.4.nix index 44d8d33fecc4..c3efc2f2a7ba 100644 --- a/pkgs/development/compilers/ghc/8.8.4.nix +++ b/pkgs/development/compilers/ghc/8.8.4.nix @@ -325,9 +325,9 @@ stdenv.mkDerivation (rec { # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do - test ! -h $i || continue - egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i + test ! -h "$i" || continue + isScript "$i" || continue + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i" done ''; diff --git a/pkgs/development/compilers/ghc/9.0.1.nix b/pkgs/development/compilers/ghc/9.0.1.nix index a778fda31a73..e7da05871070 100644 --- a/pkgs/development/compilers/ghc/9.0.1.nix +++ b/pkgs/development/compilers/ghc/9.0.1.nix @@ -291,9 +291,9 @@ stdenv.mkDerivation (rec { # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do - test ! -h $i || continue - egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i + test ! -h "$i" || continue + isScript "$i" || continue + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i" done ''; diff --git a/pkgs/development/compilers/ghc/9.2.1.nix b/pkgs/development/compilers/ghc/9.2.1.nix index 5442a423bdd0..78dbdb617e64 100644 --- a/pkgs/development/compilers/ghc/9.2.1.nix +++ b/pkgs/development/compilers/ghc/9.2.1.nix @@ -294,9 +294,9 @@ stdenv.mkDerivation (rec { # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do - test ! -h $i || continue - egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i + test ! -h "$i" || continue + isScript "$i" || continue + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i" done ''; diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix index 40dbe131f9dd..053c43649f3f 100644 --- a/pkgs/development/compilers/ghc/head.nix +++ b/pkgs/development/compilers/ghc/head.nix @@ -314,9 +314,9 @@ stdenv.mkDerivation (rec { # Patch scripts to include runtime dependencies in $PATH. for i in "$out/bin/"*; do - test ! -h $i || continue - egrep --quiet '^#!' <(head -n 1 $i) || continue - sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' $i + test ! -h "$i" || continue + isScript "$i" || continue + sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i" done ''; From 50f256f5efb8ec79a76c5de0c4d37d84643a98e8 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 25 Nov 2021 17:14:21 +0100 Subject: [PATCH 6/7] ghcWithPackages: don't wrap GHC with LLVM unnecessarily Since GHC now will have LLVM available when needed, we don't need to add it in the wrapper anymore. It can still be added if NCG is available, but -fllvm should be used (e. g. to work around an NCG bug). --- .../haskell-modules/with-packages-wrapper.nix | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pkgs/development/haskell-modules/with-packages-wrapper.nix b/pkgs/development/haskell-modules/with-packages-wrapper.nix index f7bebbc4aa07..e5fe60a0ae5c 100644 --- a/pkgs/development/haskell-modules/with-packages-wrapper.nix +++ b/pkgs/development/haskell-modules/with-packages-wrapper.nix @@ -1,14 +1,8 @@ { lib, stdenv, ghc, llvmPackages, packages, symlinkJoin, makeWrapper -# Include LLVM by default if GHC doesn't have native code generation support -# See https://gitlab.haskell.org/ghc/ghc/-/wikis/platforms -, useLLVM ? !(lib.any lib.id ([ - stdenv.targetPlatform.isx86 - stdenv.targetPlatform.isPowerPC - stdenv.targetPlatform.isSparc - ] ++ lib.optionals (lib.versionAtLeast ghc.version "9.2") [ - (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin) - # TODO(@sternenseemann): Is armv7a supported for iOS? - ])) +# GHC will have LLVM available if necessary for the respective target, +# so useLLVM only needs to be changed if -fllvm is to be used for a +# platform that has NCG support +, useLLVM ? false , postBuild ? "" , ghcLibdir ? null # only used by ghcjs, when resolving plugins }: From ef081bf3056f3facd2a0b85b172c5c730a0404e8 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 25 Nov 2021 19:30:05 +0100 Subject: [PATCH 7/7] haskell.compiler.*: don't useLLVM if aarch64-darwin NCG is available aarch64-darwin NCG was added in 9.2.1 which makes it unnecessary to include LLVM in the wrapper. --- pkgs/development/compilers/ghc/9.2.1.nix | 3 ++- pkgs/development/compilers/ghc/head.nix | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/ghc/9.2.1.nix b/pkgs/development/compilers/ghc/9.2.1.nix index 78dbdb617e64..2401a8900530 100644 --- a/pkgs/development/compilers/ghc/9.2.1.nix +++ b/pkgs/development/compilers/ghc/9.2.1.nix @@ -12,7 +12,8 @@ , # GHC can be built with system libffi or a bundled one. libffi ? null -, useLLVM ? !stdenv.targetPlatform.isx86 +, useLLVM ? !(stdenv.targetPlatform.isx86 + || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin)) , # LLVM is conceptually a run-time-only depedendency, but for # non-x86, we need LLVM to bootstrap later stages, so it becomes a # build-time dependency too. diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix index 053c43649f3f..5be02df13b4a 100644 --- a/pkgs/development/compilers/ghc/head.nix +++ b/pkgs/development/compilers/ghc/head.nix @@ -17,7 +17,8 @@ !stdenv.targetPlatform.isWindows , elfutils # for DWARF support -, useLLVM ? !stdenv.targetPlatform.isx86 || stdenv.targetPlatform.isiOS +, useLLVM ? !(stdenv.targetPlatform.isx86 + || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin)) , # LLVM is conceptually a run-time-only depedendency, but for # non-x86, we need LLVM to bootstrap later stages, so it becomes a # build-time dependency too.