From 48e5fbe8eeddf9fbe1fca3c9ee0e5fd5ac1bafb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Mon, 13 Aug 2018 14:44:30 +0900 Subject: [PATCH 1/2] buildRustPackage: allow patches to fix Cargo.lock --- pkgs/build-support/rust/default.nix | 5 +++++ pkgs/build-support/rust/fetchcargo.nix | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index fb1d6e390ae..820989a7620 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -7,6 +7,8 @@ in { name, cargoSha256 ? "unset" , src ? null , srcs ? null +, cargoPatches ? [] +, patches ? [] , sourceRoot ? null , logLevel ? "" , buildInputs ? [] @@ -23,6 +25,7 @@ let cargoDeps = if cargoVendorDir == null then fetchcargo { inherit name src srcs sourceRoot cargoUpdateHook; + patches = cargoPatches; sha256 = cargoSha256; } else null; @@ -44,6 +47,8 @@ in stdenv.mkDerivation (args // { buildInputs = [ cacert git rust.cargo rust.rustc ] ++ buildInputs; + patches = cargoPatches ++ patches; + configurePhase = args.configurePhase or '' runHook preConfigure # noop diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix index 42a3ac27cb5..2670ed52864 100644 --- a/pkgs/build-support/rust/fetchcargo.nix +++ b/pkgs/build-support/rust/fetchcargo.nix @@ -1,11 +1,11 @@ { stdenv, cacert, git, rust, cargo-vendor }: -{ name ? "cargo-deps", src, srcs, sourceRoot, sha256, cargoUpdateHook ? "" }: +{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }: stdenv.mkDerivation { name = "${name}-vendor"; nativeBuildInputs = [ cacert cargo-vendor git rust.cargo ]; - inherit src srcs sourceRoot; + inherit src srcs patches sourceRoot; - phases = "unpackPhase installPhase"; + phases = "unpackPhase patchPhase installPhase"; installPhase = '' if [[ ! -f Cargo.lock ]]; then From af960e5df9450664968d3392130e499fbaf1713f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Tue, 14 Aug 2018 11:20:30 +0900 Subject: [PATCH 2/2] buildRustPackage: add documentation about cargoPatches --- doc/languages-frameworks/rust.section.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index b77c41e9b22..eec982d4c90 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -59,6 +59,11 @@ all crate sources of this package. Currently it is obtained by inserting a fake checksum into the expression and building the package once. The correct checksum can be then take from the failed build. +When the `Cargo.lock`, provided by upstream, is not in sync with the +`Cargo.toml`, it is possible to use `cargoPatches` to update it. All patches +added in `cargoPatches` will also be prepended to the patches in `patches` at +build-time. + To install crates with nix there is also an experimental project called [nixcrates](https://github.com/fractalide/nixcrates).