From 36ad5b9b963c37917f65ae00bb3ea603cea95970 Mon Sep 17 00:00:00 2001 From: Artturin Date: Sat, 28 May 2022 21:06:27 +0300 Subject: [PATCH 1/3] buildRustPackage: add missing attr to remove cargoUpdateHook is used in cargoDeps --- pkgs/build-support/rust/build-rust-package/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index e4772592e46c..95b6f357e56a 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -97,7 +97,7 @@ in # See https://os.phil-opp.com/testing/ for more information. assert useSysroot -> !(args.doCheck or true); -stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoLock" ]) // lib.optionalAttrs useSysroot { +stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "cargoLock" ]) // lib.optionalAttrs useSysroot { RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or ""); } // { inherit buildAndTestSubdir cargoDeps; From 9ca1379bdf44774f236219abc38c72dbfdc6534b Mon Sep 17 00:00:00 2001 From: Artturin Date: Sat, 28 May 2022 21:55:39 +0300 Subject: [PATCH 2/3] fetchCargoTarball: allow adding nativeBuildInputs --- pkgs/build-support/rust/fetch-cargo-tarball/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/rust/fetch-cargo-tarball/default.nix b/pkgs/build-support/rust/fetch-cargo-tarball/default.nix index d36200aa5f90..2f1f3547dbb0 100644 --- a/pkgs/build-support/rust/fetch-cargo-tarball/default.nix +++ b/pkgs/build-support/rust/fetch-cargo-tarball/default.nix @@ -23,6 +23,7 @@ in , patches ? [] , sourceRoot ? "" , cargoUpdateHook ? "" +, nativeBuildInputs ? [] , ... } @ args: @@ -32,7 +33,7 @@ let hash_ = else throw "fetchCargoTarball requires a hash for ${name}"; in stdenv.mkDerivation ({ name = "${name}-vendor.tar.gz"; - nativeBuildInputs = [ cacert git cargo-vendor-normalise cargo ]; + nativeBuildInputs = [ cacert git cargo-vendor-normalise cargo ] ++ nativeBuildInputs; buildPhase = '' runHook preBuild @@ -82,5 +83,5 @@ in stdenv.mkDerivation ({ impureEnvVars = lib.fetchers.proxyImpureEnvVars; } // (builtins.removeAttrs args [ - "name" "sha256" "cargoUpdateHook" + "name" "sha256" "cargoUpdateHook" "nativeBuildInputs" ])) From 7d735f01a4046fed90a2d14ecfceeb40fc18b88c Mon Sep 17 00:00:00 2001 From: Artturin Date: Sat, 28 May 2022 22:10:16 +0300 Subject: [PATCH 3/3] nushell: use cargo-edit instead of a patch to add pkg-config feature to zstd-sys cargo add has been merged in to cargo so the extra package won't be needed once 1.62.0 is available in nixpkgs --- pkgs/shells/nushell/default.nix | 32 +++++++++++--------- pkgs/shells/nushell/use-system-zstd-lib.diff | 32 -------------------- 2 files changed, 18 insertions(+), 46 deletions(-) delete mode 100644 pkgs/shells/nushell/use-system-zstd-lib.diff diff --git a/pkgs/shells/nushell/default.nix b/pkgs/shells/nushell/default.nix index b096301f0e63..7c3c586ae129 100644 --- a/pkgs/shells/nushell/default.nix +++ b/pkgs/shells/nushell/default.nix @@ -13,6 +13,7 @@ , Security , nghttp2 , libgit2 +, cargo-edit , withExtraFeatures ? true , testers , nushell @@ -29,7 +30,23 @@ rustPlatform.buildRustPackage rec { sha256 = "sha256-4thvUSOSvH/bv0aW7hGGQMvtXdS+yDfZzPRLZmPZQMQ="; }; - cargoSha256 = "sha256-ALUp6sPcmnJy/A078umyKg8KBv23P0vv8mwoO9OU+DQ="; + cargoSha256 = "sha256-Vd8R9EsO52q840HqRzc37PirZZyTZr+Bnow5qHEacJ0="; + # Since 0.34, nu has an indirect dependency on `zstd-sys` (via `polars` and + # `parquet`, for dataframe support), which by default has an impure build + # (git submodule for the `zstd` C library). The `pkg-config` feature flag + # fixes this, but it's hard to invoke this in the right place, because of + # the indirect dependencies. So add a direct dependency on `zstd-sys` here + # at the top level, along with this feature flag, to ensure that when + # `zstd-sys` is transitively invoked, it triggers a pure build using the + # system `zstd` library provided above. + depsExtraArgs = { nativeBuildInputs = [ cargo-edit ]; }; + # cargo add has been merged in to cargo so the above can be removed once 1.62.0 is available in nixpkgs + # https://github.com/rust-lang/cargo/pull/10472 + cargoUpdateHook = '' + cargo add zstd-sys --features pkg-config --offline + # write the change to the lockfile + cargo update --package zstd-sys --offline + ''; nativeBuildInputs = [ pkg-config ] ++ lib.optionals (withExtraFeatures && stdenv.isLinux) [ python3 ]; @@ -41,19 +58,6 @@ rustPlatform.buildRustPackage rec { buildFeatures = lib.optional withExtraFeatures "extra"; - # Since 0.34, nu has an indirect dependency on `zstd-sys` (via `polars` and - # `parquet`, for dataframe support), which by default has an impure build - # (git submodule for the `zstd` C library). The `pkg-config` feature flag - # fixes this, but it's hard to invoke this in the right place, because of - # the indirect dependencies. So add a direct dependency on `zstd-sys` here - # at the top level, along with this feature flag, to ensure that when - # `zstd-sys` is transitively invoked, it triggers a pure build using the - # system `zstd` library provided above. - # - # (If this patch needs updating, in a nushell repo add the zstd-sys line to - # Cargo.toml, then `cargo update --package zstd-sys` to update Cargo.lock.) - cargoPatches = [ ./use-system-zstd-lib.diff ]; - # TODO investigate why tests are broken on darwin # failures show that tests try to write to paths # outside of TMPDIR diff --git a/pkgs/shells/nushell/use-system-zstd-lib.diff b/pkgs/shells/nushell/use-system-zstd-lib.diff deleted file mode 100644 index 6b0831cd9fbc..000000000000 --- a/pkgs/shells/nushell/use-system-zstd-lib.diff +++ /dev/null @@ -1,32 +0,0 @@ -diff --git a/Cargo.lock b/Cargo.lock -index 6cebf66d..b6e40cd9 100644 ---- a/Cargo.lock -+++ b/Cargo.lock -@@ -2443,6 +2443,7 @@ dependencies = [ - "rstest", - "serial_test", - "tempfile", -+ "zstd-sys", - ] - - [[package]] -@@ -5365,4 +5366,5 @@ checksum = "9fd07cbbc53846d9145dbffdf6dd09a7a0aa52be46741825f5c97bdd4f73f12b" - dependencies = [ - "cc", - "libc", -+ "pkg-config", - ] -diff --git a/Cargo.toml b/Cargo.toml -index 0791d462..d520d9ae 100644 ---- a/Cargo.toml -+++ b/Cargo.toml -@@ -58,6 +58,9 @@ rayon = "1.5.1" - reedline = { version = "0.6.0", features = ["bashisms"]} - is_executable = "1.0.1" - -+# Specify that the indirect dependency ztsd-sys should pick up the system zstd C library -+zstd-sys = { version = "2", features = [ "pkg-config" ] } -+ - [dev-dependencies] - nu-test-support = { path="./crates/nu-test-support", version = "0.63.0" } - tempfile = "3.2.0"