From 7cf0473ccda2ba2ba73d10027eab556c61db5569 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 27 Mar 2025 18:43:02 +0000 Subject: [PATCH] rustPlatform.fetchCargoTarball: drop --- doc/release-notes/rl-2505.section.md | 9 +- .../rust/build-rust-package/default.nix | 27 +-- .../cargo-vendor-normalise.py | 43 ----- .../rust/fetch-cargo-tarball/default.nix | 170 ------------------ .../compilers/rust/make-rust-platform.nix | 8 +- 5 files changed, 14 insertions(+), 243 deletions(-) delete mode 100755 pkgs/build-support/rust/fetch-cargo-tarball/cargo-vendor-normalise.py delete mode 100644 pkgs/build-support/rust/fetch-cargo-tarball/default.nix diff --git a/doc/release-notes/rl-2505.section.md b/doc/release-notes/rl-2505.section.md index e386ead66797..a11e8b6c3205 100644 --- a/doc/release-notes/rl-2505.section.md +++ b/doc/release-notes/rl-2505.section.md @@ -25,9 +25,12 @@ The `nixLog` function, which logs unconditionally, was also re-introduced and modified to prefix messages with the function name of the caller. For more information, [see this PR](https://github.com/NixOS/nixpkgs/pull/370742). -- The `rustPlatform.fetchCargoTarball` function is deprecated, because it relied on `cargo vendor` not changing its output format to keep fixed-output derivation hashes the same, which is a Nix invariant, and Cargo 1.84.0 changed `cargo vendor`'s output format. - It should generally be replaced with `rustPlatform.fetchCargoVendor`, but `rustPlatform.importCargoLock` may also be appropriate in some circumstances. - `rustPlatform.buildRustPackage` users must set `useFetchCargoVendor` to `true` and regenerate the `cargoHash`. +- Rust packages will need to regenerate their `cargoHash`. + Cargo 1.84.0 changed the format of `cargo vendor` output, which invalidated all existing `rustPlatform.fetchCargoTarball` hashes. + To preserve Nix’s invariants, it has been replaced with `rustPlatform.fetchCargoVendor`, an independent implementation prioritizing format stability. + `rustPlatform.buildRustPackage` now uses `rustPlatform.fetchCargoVendor` by default; a hash mismatch error is expected in third‐party Rust packages when updating to Nixpkgs 25.05. + Packages wishing to maintain compatibility with Nixpkgs 24.11 must set `useFetchCargoVendor` to `true` explicitly. + `rustPlatform.importCargoLock` may also be appropriate in some circumstances. - NetBox was updated to `>= 4.2.0`. Have a look at the breaking changes of the [4.1 release](https://github.com/netbox-community/netbox/releases/tag/v4.1.0) diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index 665546481217..2d215a4eb010 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -1,7 +1,6 @@ { lib, importCargoLock, - fetchCargoTarball, fetchCargoVendor, stdenv, cargoBuildHook, @@ -50,7 +49,7 @@ lib.extendMkDerivation { cargoDepsHook ? "", buildType ? "release", meta ? { }, - useFetchCargoVendor ? false, + useFetchCargoVendor ? true, cargoDeps ? null, cargoLock ? null, cargoVendorDir ? null, @@ -72,6 +71,9 @@ lib.extendMkDerivation { ... }@args: + assert lib.assertMsg useFetchCargoVendor + "buildRustPackage: `useFetchCargoVendor` is non‐optional and enabled by default as of 25.05"; + lib.optionalAttrs (stdenv.hostPlatform.isDarwin && buildType == "debug") { RUSTFLAGS = "-C split-debuginfo=packed " + (args.RUSTFLAGS or ""); } @@ -85,7 +87,7 @@ lib.extendMkDerivation { importCargoLock cargoLock else if args.cargoHash or null == null then throw "cargoHash, cargoVendorDir, cargoDeps, or cargoLock must be set" - else if useFetchCargoVendor then + else fetchCargoVendor ( { inherit @@ -102,25 +104,6 @@ lib.extendMkDerivation { hash = args.cargoHash; } // depsExtraArgs - ) - else - fetchCargoTarball ( - { - inherit - src - srcs - sourceRoot - cargoRoot - preUnpack - unpackPhase - postUnpack - cargoUpdateHook - ; - hash = args.cargoHash; - name = cargoDepsName; - patches = cargoPatches; - } - // depsExtraArgs ); inherit buildAndTestSubdir; diff --git a/pkgs/build-support/rust/fetch-cargo-tarball/cargo-vendor-normalise.py b/pkgs/build-support/rust/fetch-cargo-tarball/cargo-vendor-normalise.py deleted file mode 100755 index 90933b089c92..000000000000 --- a/pkgs/build-support/rust/fetch-cargo-tarball/cargo-vendor-normalise.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python - -import sys - -import toml - - -def quote(s: str) -> str: - escaped = s.replace('"', r"\"").replace("\n", r"\n").replace("\\", "\\\\") - return '"{}"'.format(escaped) - - -def main() -> None: - data = toml.load(sys.stdin) - - # There is no dependency to vendor in this project. - if not list(data.keys()) == ["source"]: - return - - # this value is non deterministic - data["source"]["vendored-sources"]["directory"] = "@vendor@" - - lines = [] - inner = data["source"] - for source, attrs in sorted(inner.items()): - lines.append("[source.{}]".format(quote(source))) - if source == "vendored-sources": - lines.append('"directory" = "@vendor@"\n') - else: - for key, value in sorted(attrs.items()): - attr = "{} = {}".format(quote(key), quote(value)) - lines.append(attr) - lines.append("") - - result = "\n".join(lines) - real = toml.loads(result) - assert real == data, "output = {} while input = {}".format(real, data) - - print(result) - - -if __name__ == "__main__": - main() diff --git a/pkgs/build-support/rust/fetch-cargo-tarball/default.nix b/pkgs/build-support/rust/fetch-cargo-tarball/default.nix deleted file mode 100644 index c477262968af..000000000000 --- a/pkgs/build-support/rust/fetch-cargo-tarball/default.nix +++ /dev/null @@ -1,170 +0,0 @@ -{ - lib, - stdenv, - cacert, - git, - cargo, - python3, -}: -let - cargo-vendor-normalise = stdenv.mkDerivation { - name = "cargo-vendor-normalise"; - src = ./cargo-vendor-normalise.py; - nativeBuildInputs = [ python3.pkgs.wrapPython ]; - dontUnpack = true; - installPhase = "install -D $src $out/bin/cargo-vendor-normalise"; - pythonPath = [ python3.pkgs.toml ]; - postFixup = "wrapPythonPrograms"; - doInstallCheck = true; - installCheckPhase = '' - # check that ../fetchcargo-default-config.toml is a fix point - reference=${../fetchcargo-default-config.toml} - < $reference $out/bin/cargo-vendor-normalise > test; - cmp test $reference - ''; - preferLocalBuild = true; - }; -in -{ - pname ? null, - version ? null, - name ? if args ? pname && args ? version then "${pname}-${version}" else "cargo-deps", - src ? null, - srcs ? [ ], - patches ? [ ], - sourceRoot ? "", - cargoUpdateHook ? "", - nativeBuildInputs ? [ ], - ... -}@args: - -assert lib.assertMsg ( - (args ? pname || args ? version) -> !(args ? name) -) "Either specify `pname` with `version`, or specify `name` only, not a mix of both."; -assert lib.assertMsg ( - args ? pname == args ? version -) "If `pname` is specified, `version` must be also, and vice versa."; -let - # args to remove from the final call to stdenv.mkDerivation, as we've already handled them - removedArgs = [ - "name" - "pname" - "version" - "sha256" - "cargoUpdateHook" - "nativeBuildInputs" - ]; - - hash_ = - if args ? hash then - { - outputHashAlgo = if args.hash == "" then "sha256" else null; - outputHash = args.hash; - } - else if args ? sha256 then - { - outputHashAlgo = "sha256"; - outputHash = args.sha256; - } - else - throw "fetchCargoTarball requires a hash for ${name}"; -in -lib.warn - '' - rustPlatform.fetchCargoTarball is deprecated in favor of rustPlatform.fetchCargoVendor. - If you are using buildRustPackage, try setting useFetchCargoVendor = true and regenerating cargoHash. - See the 25.05 release notes for more information. - '' - ( - stdenv.mkDerivation ( - { - name = "${name}-vendor.tar.gz"; - nativeBuildInputs = [ - cacert - git - cargo-vendor-normalise - cargo - ] ++ nativeBuildInputs; - - dontConfigure = true; - buildPhase = '' - runHook preBuild - - # Ensure deterministic Cargo vendor builds - export SOURCE_DATE_EPOCH=1 - - if [ -n "''${cargoRoot-}" ]; then - cd "$cargoRoot" - fi - - if [[ ! -f Cargo.lock ]]; then - echo - echo "ERROR: The Cargo.lock file doesn't exist" - echo - echo "Cargo.lock is needed to make sure that cargoHash/cargoSha256 doesn't change" - echo "when the registry is updated." - echo - - exit 1 - fi - - # Keep the original around for copyLockfile - cp Cargo.lock Cargo.lock.orig - - export CARGO_HOME=$(mktemp -d cargo-home.XXX) - CARGO_CONFIG=$(mktemp cargo-config.XXXX) - - if [[ -n "$NIX_CRATES_INDEX" ]]; then - cat >$CARGO_HOME/config.toml < $CARGO_CONFIG - - # Create an empty vendor directory when there is no dependency to vendor - mkdir -p $name - # Add the Cargo.lock to allow hash invalidation - cp Cargo.lock.orig $name/Cargo.lock - - # Packages with git dependencies generate non-default cargo configs, so - # always install it rather than trying to write a standard default template. - install -D $CARGO_CONFIG $name/.cargo/config - - runHook postBuild - ''; - - # Build a reproducible tar, per instructions at https://reproducible-builds.org/docs/archives/ - installPhase = '' - tar --owner=0 --group=0 --numeric-owner --format=gnu \ - --sort=name --mtime="@$SOURCE_DATE_EPOCH" \ - -czf $out $name - ''; - - inherit (hash_) outputHashAlgo outputHash; - - impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "NIX_CRATES_INDEX" ]; - } - // (removeAttrs args removedArgs) - ) - ) diff --git a/pkgs/development/compilers/rust/make-rust-platform.nix b/pkgs/development/compilers/rust/make-rust-platform.nix index e7d0da9cbb5b..03564bc068f7 100644 --- a/pkgs/development/compilers/rust/make-rust-platform.nix +++ b/pkgs/development/compilers/rust/make-rust-platform.nix @@ -26,11 +26,6 @@ inherit (self) callPackage; in { - fetchCargoTarball = buildPackages.callPackage ../../../build-support/rust/fetch-cargo-tarball { - git = buildPackages.gitMinimal; - inherit cargo; - }; - fetchCargoVendor = buildPackages.callPackage ../../../build-support/rust/fetch-cargo-vendor.nix { inherit cargo; }; @@ -81,4 +76,7 @@ rustc = lib.warn "rustPlatform.rust.rustc is deprecated. Use rustc instead." rustc; cargo = lib.warn "rustPlatform.rust.cargo is deprecated. Use cargo instead." cargo; }; + + # Added in 25.05. + fetchCargoTarball = throw "`rustPlatform.fetchCargoTarball` has been removed in 25.05, use `rustPlatform.fetchCargoVendor` instead"; }