| name | update-rust-derivation |
| description | Update a Rust derivation to a new version with correct hashes. Use when the user wants to update a Rust package in their nix derivations. |
Update Rust Derivation
Update the Rust derivation: $ARGUMENTS
Steps
-
Read the derivation: Read the derivation file to understand its current structure, version, and hash fields.
-
Update the version: Change the version attribute to the new version.
-
Get the source hash:
nix-prefetch-url --unpack "https://github.com/<owner>/<repo>/archive/refs/tags/v<version>.tar.gz"
Then convert to SRI format:
nix hash to-sri --type sha256 <hash>
-
Update the source hash: Replace the hash attribute in fetchFromGitHub with the new SRI hash.
-
Set cargoHash to placeholder: Temporarily set cargoHash = lib.fakeHash; to trigger nix to compute the correct hash.
-
Build to get cargoHash:
nix build --impure --expr 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./<path-to-derivation> {}' 2>&1 | grep -A2 "got:"
Extract the correct cargoHash from the error output.
-
Update cargoHash: Replace lib.fakeHash with the actual cargoHash from the build output.
-
Verify the build:
nix build --impure --expr 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./<path-to-derivation> {}'
Ensure the build completes successfully.
-
Summary: Report the version update (old -> new) and remind to run darwin-rebuild switch --flake . to apply changes.
Notes
- The derivation must use
rustPlatform.buildRustPackage with cargoHash
- If using
cargoLock instead of cargoHash, the process differs (fetch Cargo.lock from repo)
- Some packages may have additional attributes that need updating (e.g.,
patches, buildInputs)