Skip to content

Commit 906fbe3

Browse files
committed
fix: remove unnecessary modifiedSrc derivation to resolve IFD cross-compilation issues
The root issue was that the buildPgrxExtension was creating a modifiedSrc derivation to copy external Cargo.lock files for crane. This derivation was being created for each target platform during evaluation, causing system conflicts when evaluating aarch64-darwin packages on x86_64-linux systems. The solution is to remove the modifiedSrc logic entirely and rely on the existing postPatch mechanism in the extensions, which already handles external lockfiles by creating symlinks. Crane works perfectly with this approach and doesn't need the lockfiles copied during evaluation. This resolves the IFD (Import From Derivation) issues while maintaining crane's incremental build benefits and cross-compilation support.
1 parent 7e3bdbf commit 906fbe3

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
pkg-config,
3434
rustPlatform,
3535
stdenv,
36-
buildPackages,
3736
writeShellScriptBin,
3837
defaultBindgenHook,
3938
}:
@@ -144,37 +143,13 @@ let
144143
pg_ctl stop
145144
'';
146145

147-
# Crane-specific: handle external Cargo.lock files
148-
# Crane expects Cargo.lock at source root, but rustPlatform allows external lockFile paths.
149-
# Without this, crane fails with:
150-
# "error: unable to find Cargo.lock at /nix/store/...-source. please ensure one of the following:
151-
# - a Cargo.lock exists at the root of the source directory"
146+
# Crane-specific: Determine if we're using crane and handle cargo lock info
152147
useCrane = craneLib != null;
153148
cargoLockInfo = args.cargoLock or null;
154-
hasExternalLockFile = cargoLockInfo != null && cargoLockInfo ? lockFile;
155-
156-
# Copy external Cargo.lock into source directory to satisfy crane's requirements
157-
modifiedSrc =
158-
if useCrane && hasExternalLockFile then
159-
# Use buildPackages.stdenv to ensure this runs on the build platform
160-
# This derivation just copies files and should be buildable during evaluation
161-
buildPackages.stdenv.mkDerivation {
162-
name = "${args.pname or "source"}-with-lockfile";
163-
src = args.src;
164-
dontBuild = true;
165-
# Ensure this derivation runs locally during evaluation
166-
preferLocalBuild = true;
167-
allowSubstitutes = false;
168-
installPhase = ''
169-
cp -r $src $out
170-
chmod -R u+w $out
171-
${lib.optionalString (cargoLockInfo ? lockFile) ''
172-
cp ${cargoLockInfo.lockFile} $out/Cargo.lock
173-
''}
174-
'';
175-
}
176-
else
177-
args.src;
149+
150+
# External Cargo.lock files are handled by the extension's postPatch phase
151+
# which creates symlinks. Crane will find them during the build phase.
152+
modifiedSrc = args.src;
178153

179154
# Use rustPlatform.importCargoLock instead of crane's vendorCargoDeps for git dependencies.
180155
# crane's vendorCargoDeps uses builtins.fetchGit which only searches the default branch,
@@ -183,7 +158,7 @@ let
183158
# 'refs/heads/main' of repository 'https://github.com/burmecia/iceberg-rust'!"
184159
# rustPlatform.importCargoLock with allowBuiltinFetchGit searches all refs (branches/tags).
185160
cargoVendorDir =
186-
if useCrane && hasExternalLockFile && cargoLockInfo ? outputHashes then
161+
if useCrane && cargoLockInfo != null && cargoLockInfo ? outputHashes then
187162
rustPlatform.importCargoLock {
188163
lockFile = cargoLockInfo.lockFile;
189164
outputHashes = cargoLockInfo.outputHashes;
@@ -212,7 +187,7 @@ let
212187
commonArgs =
213188
argsForBuilder
214189
// {
215-
src = modifiedSrc;
190+
src = args.src; # Use original source - extensions handle external lockfiles via postPatch
216191
strictDeps = true;
217192

218193
buildInputs = (args.buildInputs or [ ]);

0 commit comments

Comments
 (0)