From b993c2113c8191ca9b454abfc79d02196b6a2bd0 Mon Sep 17 00:00:00 2001 From: "Ricardo M. Correia" Date: Thu, 23 Apr 2015 16:37:52 +0200 Subject: [PATCH] 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. --- pkgs/build-support/rust/default.nix | 20 +++++++++++++------ .../rust/patch-registry-deps/pkg-config | 8 ++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 pkgs/build-support/rust/patch-registry-deps/pkg-config diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 37175114d81..2a890a0d232 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -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/* - substituteInPlace "$dir/src/lib.rs" \ - --replace '"/usr"' '"/nix/store/"' - done + set -euo pipefail + + 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 '' diff --git a/pkgs/build-support/rust/patch-registry-deps/pkg-config b/pkgs/build-support/rust/patch-registry-deps/pkg-config new file mode 100644 index 00000000000..2acf489851e --- /dev/null +++ b/pkgs/build-support/rust/patch-registry-deps/pkg-config @@ -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