buildRustPackage: Add a mechanism to patch registry deps

... in a more generic way.

With this commit, if you need to patch a registry package to make it
work with Nix, you just need to add a script to patch-registry-deps
in the same style as the `pkg-config` script.
wip/yesman
Ricardo M. Correia 9 years ago
parent 0cde1dc524
commit b993c2113c
  1. 20
      pkgs/build-support/rust/default.nix
  2. 8
      pkgs/build-support/rust/patch-registry-deps/pkg-config

@ -14,6 +14,8 @@ let
in stdenv.mkDerivation (args // {
inherit cargoDeps rustRegistry cargoUpdateHook;
patchRegistryDeps = ./patch-registry-deps;
buildInputs = [ git cargo rustc ] ++ buildInputs;
configurePhase = args.configurePhase or "true";
@ -41,14 +43,20 @@ in stdenv.mkDerivation (args // {
)
'' + (args.postUnpack or "");
# TODO: Probably not the best way to do this, but it should work for now
prePatch = ''
for dir in ../deps/registry/src/*/pkg-config-*; do
[ -d "$dir" ] || continue
# Patch registry dependencies, using the scripts in $patchRegistryDeps
(
cd ../deps/registry/src/*
set -euo pipefail
substituteInPlace "$dir/src/lib.rs" \
--replace '"/usr"' '"/nix/store/"'
done
for script in $patchRegistryDeps/*; do
# Run in a subshell so that directory changes and shell options don't
# affect any following commands
( . $script)
done
)
'' + (args.prePatch or "");
buildPhase = args.buildPhase or ''

@ -0,0 +1,8 @@
for dir in pkg-config-*; do
[ -d "$dir" ] || continue
echo "Patching pkg-config registry dep"
substituteInPlace "$dir/src/lib.rs" \
--replace '"/usr"' '"/nix/store/"'
done
Loading…
Cancel
Save