Skip to content

Commit 711db81

Browse files
committed
Fix: write nix-support/propagated-native-build-inputs file
writeShellApplication uses writeTextFile internally, which does NOT run stdenv.mkDerivation's fixupPhase. Setting propagatedNativeBuildInputs via overrideAttrs only adds the attribute to the derivation but never materializes the $out/nix-support/propagated-native-build-inputs file that setup.sh's findInputs actually reads at runtime. Without this file, curl was invisible to the shell environment despite being set as a propagated dep — the wrapper script itself had curl on its internal PATH, but other programs (like GHC's stage0 cabal) could not find it. Fix: explicitly create the nix-support file in postInstall.
1 parent 23f1873 commit 711db81

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

writers.nix

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,20 @@
3232
#
3333
# ─── The fix ───────────────────────────────────────────────────────────────────
3434
#
35-
# We use overrideAttrs to add propagatedNativeBuildInputs to the wrapper
36-
# derivation. When stdenv's setup.sh processes the wrapper from
37-
# nativeBuildInputs, it:
35+
# We use overrideAttrs to:
36+
#
37+
# 1. Set propagatedNativeBuildInputs on the derivation
38+
# 2. Write the $out/nix-support/propagated-native-build-inputs file
39+
#
40+
# Step 2 is critical: writeShellApplication uses writeTextFile internally,
41+
# which does NOT run stdenv.mkDerivation's fixupPhase. That fixupPhase is
42+
# what normally materializes the propagatedNativeBuildInputs derivation
43+
# attribute into the $out/nix-support/propagated-native-build-inputs file
44+
# that setup.sh's findInputs reads at runtime. Without the file on disk,
45+
# setting the attribute alone has no effect — setup.sh never sees it.
46+
#
47+
# With the file in place, when stdenv's setup.sh processes the wrapper
48+
# from buildInputs or nativeBuildInputs, it:
3849
#
3950
# 1. Adds $wrapper/bin to PATH (the wrapper itself)
4051
# 2. Reads $wrapper/nix-support/propagated-native-build-inputs
@@ -64,8 +75,24 @@
6475
{ pkgs }:
6576
{
6677
writeShellApplicationWithRuntime = args@{ runtimeInputs ? [], ... }:
78+
let
79+
allPropagated = runtimeInputs;
80+
# Space-separated store paths for the propagation file, matching the
81+
# format that stdenv's setup.sh findInputs expects.
82+
propagatedPathsStr = builtins.concatStringsSep " "
83+
(map (dep: "${dep}") allPropagated);
84+
in
6785
(pkgs.writeShellApplication args).overrideAttrs (old: {
6886
propagatedNativeBuildInputs =
69-
(old.propagatedNativeBuildInputs or []) ++ runtimeInputs;
87+
(old.propagatedNativeBuildInputs or []) ++ allPropagated;
88+
89+
# writeShellApplication (via writeTextFile) does NOT run stdenv's
90+
# fixupPhase, so the propagatedNativeBuildInputs attribute is never
91+
# materialized into the nix-support/ file that setup.sh reads.
92+
# We create it explicitly in postInstall.
93+
postInstall = (old.postInstall or "") + ''
94+
mkdir -p $out/nix-support
95+
echo "${propagatedPathsStr}" > $out/nix-support/propagated-native-build-inputs
96+
'';
7097
});
7198
}

0 commit comments

Comments
 (0)