# Is it possible to override cargoSha256 in buildRustPackage?

**URL:** https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393
**Category:** Help
**Created:** [October 16, 2019, 1:07pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393 "2019-10-16T13:07:34Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![eraserhd](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eraserhd/32/1513_2.png) [@eraserhd](https://discourse.nixos.org/u/eraserhd)
#### Post date: [October 16, 2019, 1:07pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/1 "2019-10-16T13:07:35Z")

</div>

The problem I’m trying to solve: I want to use newer src from github to install a beta version of a package I maintain using an overlay in NixOS and nix-darwin.

I’ve been able to do it by copying the derivation into my dotfiles repo and modifying it, but shouldn’t it be possible to use overrideAttrs and override to modify the package?

---

<div class="post-metadata">

### Author: ![lilyball](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lilyball/32/939_2.png) [@lilyball](https://discourse.nixos.org/u/lilyball)
#### Post date: [October 16, 2019, 6:27pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/2 "2019-10-16T18:27:37Z")

</div>

Ok I took a look and it looks at first glance as though `overrideAttrs` might work on the results of `buildRustPackage`. I’m not entirely certain though because I don’t have a 100% grasp of the override system implementation.

In any case, you could certainly try creating an overlay that calls `overrideAttrs` to change both the `src` and `cargoSha256`.

---

<div class="post-metadata">

### Author: ![aszlig](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aszlig/32/78_2.png) [@aszlig](https://discourse.nixos.org/u/aszlig)
#### Post date: [October 17, 2019, 1:02am UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/3 "2019-10-17T01:02:47Z")

</div>

`overrideAttrs` works on the attributes passed to `stdenv.mkDerivation`, not on the attributes passed to `buildRustPackage`, so at that point you already get the attributes that `buildRustPackage` is passing to `stdenv.mkDerivation`.

In order to get around this you need to look at the [source of `buildRustPackage`](https://github.com/NixOS/nixpkgs/blob/823da4d492b8b4ad46bf812db8421d99ff17a8fc/pkgs/build-support/rust/default.nix) and figure out how the `mkDerivation` attributes came to be.

For `buildRustPackage` the important part here is [`cargoDeps`](https://github.com/NixOS/nixpkgs/blob/823da4d492b8b4ad46bf812db8421d99ff17a8fc/pkgs/build-support/rust/default.nix#L62), which is the only location where `cargoSha256` is used. So let’s say if you have a package `foo` and you’d like to change `src` and `cargoSha256` you could override it like this:

```nix
foo.overrideAttrs (drv: rec {
  src = ...;
  cargoDeps = drv.cargoDeps.overrideAttrs (_: {
    inherit src; # You need to pass "src" here again,
                 # otherwise the old "src" will be used.
    outputHash = "... new cargoSha256 ...";
  });
})

```

The nested `overrideAttrs` is for the [`fetchcargo` function](https://github.com/NixOS/nixpkgs/blob/29b5aaeb5d8282f7bb4ce112aaae44309ec3410c/pkgs/build-support/rust/default.nix#L30-L35) ([source](https://github.com/NixOS/nixpkgs/blob/29b5aaeb5d8282f7bb4ce112aaae44309ec3410c/pkgs/build-support/rust/fetchcargo.nix)), which again overrides `mkDerivation` attributes, so instead of passing `sha256`, you need to pass [`outputHash`](https://github.com/NixOS/nixpkgs/blob/29b5aaeb5d8282f7bb4ce112aaae44309ec3410c/pkgs/build-support/rust/fetchcargo.nix#L75).

To illustrate this with a more concrete (but probably stupid) example, here is how to downgrade [`loc`](https://github.com/NixOS/nixpkgs/blob/29b5aaeb5d8282f7bb4ce112aaae44309ec3410c/pkgs/development/misc/loc/default.nix) to version 0.4.0:

```nix
{ pkgs ? import <nixpkgs> {}, lib ? pkgs.lib }:

pkgs.loc.overrideAttrs (drv: rec {
  name = "loc-${version}";
  version = "0.4.0";

  src = pkgs.fetchFromGitHub {
    owner = "cgag";
    repo = "loc";
    rev = "v${version}";
    sha256 = "0cdcalfb0njvlswwvzbp0s7lwfqx4acxcmlsjw2bkanszbdz10s8";
  };

  cargoDeps = drv.cargoDeps.overrideAttrs (lib.const {
    name = "${name}-vendor";
    inherit src;
    outputHash = "1qiib37qlm1z239mfr5020m4a1ig2abhlnwava7il8dqvrxzsxpl";
  });
})

```

Here I also passed `name` along with the `src` attribute to make sure that the store path actually reflects the version change, so it’s less confusing than having a store path that says something like `0.4.1` but the actual version is `0.4.0`.

---

<div class="post-metadata">

### Author: ![lilyball](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lilyball/32/939_2.png) [@lilyball](https://discourse.nixos.org/u/lilyball)
#### Post date: [October 17, 2019, 7:44pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/4 "2019-10-17T19:44:39Z")

</div>

> [@aszlig](#):
>
> `overrideAttrs` works on the attributes passed to `stdenv.mkDerivation` , not on the attributes passed to `buildRustPackage` , so at that point you already get the attributes that `buildRustPackage` is passing to `stdenv.mkDerivation` .

Ok I wasn’t sure because I saw `overrideAttrs` was mentioned in the implementation of `makeOverridable`, but looking closer, I think all it’s doing is wrapping `overrideAttrs` such that the results of calling it is made overridable again.

It would be nice if functions like `buildRustPackage` had their own version of `overrideAttrs`. I guess we’d want a different name though.

Another option here is to use something like

```nix
self: super:

{
  ffsend = super.callPackage <nixpkgs/pkgs/tools/misc/ffsend> {
    rustPlatform = super.rustPlatform // {
      buildRustPackage = args:
        super.rustPlatform.buildRustPackage (args // {
          src = newSrcValue;
          cargoSha256 = newSha;
        });
    };
  };
}

```

This re-invokes the original package (whose path you need to know of course) but overrides the call to `rustPlatform.buildRustPackage` such that it modifies the args before passing them along.

---

<div class="post-metadata">

### Author: ![Sandro](https://discourse.nixos.org/user_avatar/discourse.nixos.org/sandro/32/2865_2.png) [@Sandro](https://discourse.nixos.org/u/Sandro)
#### Post date: [August 29, 2020, 1:29am UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/5 "2020-08-29T01:29:13Z")

</div>

If anyone stumbles upon this and gets the following error type:

```auto
do not know how to unpack source archive /nix/store/1qiib37qlm1z239mfr5020m4a1ig2abhlnwava7il8dqvrxzsxpl-loc-0.4.0-vendor

```

You need to set the file type in name:

```auto
...
cargoDeps = drv.cargoDeps.overrideAttrs (lib.const {
    name = "${name}-vendor.tar.gz";
    inherit src;
    outputHash = "1qiib37qlm1z239mfr5020m4a1ig2abhlnwava7il8dqvrxzsxpl";
  });
...

```

---

<div class="post-metadata">

### Author: ![teutat3s](https://discourse.nixos.org/user_avatar/discourse.nixos.org/teutat3s/32/4144_2.png) [@teutat3s](https://discourse.nixos.org/u/teutat3s)
#### Post date: [February 2, 2022, 6:31pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/6 "2022-02-02T18:31:01Z")

</div>

In case anybody tries to do this with flakes:

```auto
final: prev: {
  mdbook-multilang = prev.mdbook.overrideAttrs (oldAttrs: rec {
    pname = "mdbook";

    version = "pr1306";

    src = prev.fetchFromGitHub {
       owner = "Ruin0x11";
       repo = "mdBook";
       rev = "9d8147c52dd9d50047ba5b29e4af99f92577806e";
       sha256 = "sha256-gJnQKHssO2ChiT4d037Lncd7hiOa5uh756p8TzPzbgQ=";
     };

    cargoDeps = oldAttrs.cargoDeps.overrideAttrs (prev.lib.const {
      name = "${pname}-vendor.tar.gz";
      inherit src;
      outputHash = "sha256-QCEyl5FZqECYYb5eRm8mn+R6owt+CLQwCq/AMMPygE0=";
    });
  });
}

```

---

<div class="post-metadata">

### Author: ![amjoseph](https://discourse.nixos.org/user_avatar/discourse.nixos.org/amjoseph/32/28378_2.png) [@amjoseph](https://discourse.nixos.org/u/amjoseph)
#### Post date: [May 8, 2022, 4:21am UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/7 "2022-05-08T04:21:38Z")

</div>

Hi folks, just to clarify: it appears that while you can override the _outputs_ of a `buildRustPackage` derivation, it isn’t possible to override the _inputs_ (i.e. dependencies). Please let me know if I’m wrong about this (and feel free to revert my edits to the [wiki page](https://nixos.wiki/wiki/Rust) which note this).

I [struggled quite a bit with this](https://github.com/a-m-joseph/nixpkgs/commit/232887fef66d50649714b3b45618ce7497ea6da0) before giving up, going so far as to reify the `Cargo.lock` using `fromTOML`, patching it, then writing it back out with `remarshal`, and using `cargo-edit` to patch the dependencies’ `Cargo.toml` files. My use case involves an A-\>B-\>C dependency where I need to replace “C”, so the `Cargo.toml` in “B” needs to be rewritten.

Specifically, I’m trying to swap out the [ring](https://github.com/briansmith/ring) cryptography library with [IBM’s fork](https://github.com/IBM/ring/tree/ppc-0.16.20) which has support for powerpc64le ([PR to merge upstream](https://github.com/briansmith/ring/pull/1057)). I picked `tiny` as an example case but pretty much anything written in Rust that uses cryptography or HTTPs relies on ring. **The goal here was _not_ to have to run `cargo update` for every single rust package that uses ring (or that _can_ use it in place of openssl).** This is a large and rapidly growing number of packages. It ought to be possible to calculate the new checksum for ring once, and then patch that value in using non-network-accessing operations, inside of nix derivations.

I ended up in never-ending fights with cargo, which really wants to do things its way. The closest I ever got always managed to end with something like

```auto
error: the lock file /build/source/Cargo.lock needs to be updated but --frozen was passed to prevent this

```

If there is a way around this please do let me know. Until then my working assumption is that `cargo` simply doesn’t support the kinds of magic that nix has gotten me addicted to using. The only way forward here appears to be to skip cargo and have nix drive the build process with [crate2nix](https://github.com/kolloch/crate2nix).

---

<div class="post-metadata">

### Author: ![amjoseph](https://discourse.nixos.org/user_avatar/discourse.nixos.org/amjoseph/32/28378_2.png) [@amjoseph](https://discourse.nixos.org/u/amjoseph)
#### Post date: [August 22, 2022, 9:49am UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/8 "2022-08-22T09:49:52Z")

</div>

It turns out that this _is_ possible, but requires changes to `buildRustPackage` in order to invoke `cargo build` with the weaker `--offline` flag rather than the `--frozen` flag. Once [#187838](https://github.com/NixOS/nixpkgs/pull/187838) is merged that will be possible.

Here’s what [an example override looks like](https://github.com/amjoseph-nixpkgs/nixpkgs/commit/78b4b5bf68d41f412944a2ee846715dfb090d045).

This was a really motivating use for this ability. The `ring` crate is basically the Rust standard crypto library, and by now is a dependency of a huge part of the Rust ecosystem, as well as a big chunk of the Python ecosystem as well!

For reasons which remain mysterious, the `ring` maintainer has been ignoring [a pull request from IBM to add the assembler primitives for PowerPC](https://github.com/briansmith/ring/pull/1057) for almost two years now. These primitives are copied from BoringSSL, just like all the other `ring` primitives. It’s a pretty weird situation. No response of any kind, positive or negative.

In the example above I was able to replace (the non-openssl version of) the `tiny` IRC client with a version of `ring` that has IBM’s patches. It built, and I was able to successfully connect to libera.chat using TLS. ~~Note that if you have powerpc64le hardware and want to try the same thing, you will also need [#168983](https://github.com/NixOS/nixpkgs/pull/168983) because we’re still waiting for [the bootstrap files to be uploaded](https://github.com/NixOS/nixpkgs/pull/185182).~~

---

<div class="post-metadata">

### Author: ![vazae](https://discourse.nixos.org/user_avatar/discourse.nixos.org/vazae/32/9979_2.png) [@vazae](https://discourse.nixos.org/u/vazae)
#### Post date: [March 19, 2024, 4:21am UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/9 "2024-03-19T04:21:14Z")

</div>

> This re-invokes the original package (whose path you need to know of course) but overrides the call to `rustPlatform.buildRustPackage` such that it modifies the args before passing them along.

Packages created with `callPackage` automatically get a `.override` function (technically speaking, a functor, an attribute set which behaves like a function thanks to its `__functor` attribute), since `lib.callPackageWith` uses `lib.makeOverridable` to make packages overridable.

```nix
nix-repl> pkgs.ffsend.override
{ __functionArgs = { ... };__ functor = «lambda @ /nix/store/gzf4zwcakda1nykn6h0avh45xhjhvsz4-source/lib/trivial.nix:440:19»; }

```

Since `lib.callPackageWith` takes either a function or a path,

```nix
  callPackageWith = autoArgs: fn: args:
    let
      f = if isFunction fn then fn else import fn;

```

one can use `super.callPackage super.ffsend.override` instead of `super.callPackage <nixpkgs/pkgs/tools/misc/ffsend>`. This avoids the [lookup path impurity](https://nix.dev/guides/best-practices#lookup-paths) and allows overlaying packages that don’t have their own dedicated file (e.g. `pkgs.xorg.xorgserver`) or come from a flake.

I (ab)use this trick significantly when [patching out `/bin/sh`](https://github.com/stephen-huan/nixos-config/blob/39b65fe00104bd7b7323f328483788f28b20bc9e/overlays/nobinsh.nix). For example, [tectonic](https://github.com/stephen-huan/nixos-config/commit/1acd7e292f7ce43e517348f696ccbf2aa5401fa8) can be overlayed like

```nix
final: prev:

{
  tectonic-unwrapped = final.callPackage prev.tectonic-unwrapped.override {
    rustPlatform = final.rustPlatform // {
      buildRustPackage = args: final.rustPlatform.buildRustPackage (args // {
        src = final.fetchFromGitHub {
          owner = "tectonic-typesetting";
          repo = "tectonic";
          rev = "78fd97716ee111861bd981a45e6816589d16f504";
          sha256 = "sha256-pKx2fzBllkv3fzUfhv9qKlPqD4JKdEN74+gsLbmwZ/o=";
        };
        cargoHash = "sha256-BcVepSoFogh/OU0DoQNnT8X9bNc74rMDT+3zelmfwkY=";
        # https://github.com/NixOS/nixpkgs/pull/291770
        buildFeatures = ["external-harfbuzz"];
      });
    };
  };
}

```

---

<div class="post-metadata">

### Author: ![lilyball](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lilyball/32/939_2.png) [@lilyball](https://discourse.nixos.org/u/lilyball)
#### Post date: [March 21, 2024, 10:22pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/10 "2024-03-21T22:22:04Z")

</div>

If you’re using `.override` to replace `rustPlatform`, you don’t need or want the `final.callPackage`. At best it’s going to do nothing, but if the package already was overridden to change things it’s going to lose those previous overrides. Also `override` gives you access to the original values, so you can customize those instead of replacing them.

```nix
final: prev:
{
  tectonic-unwrapped = prev.tectonic-unwrapped.override (old: {
    rustPlatform = old.rustPlatform // {
      buildRustPackage = args: old.rustPlatform.buildRustPackage (args // {
        # override src/cargoHash/buildFeatures here
      });
    };
  });
}

```

---

<div class="post-metadata">

### Author: ![ede1998](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/e/9d8465/32.png) [@ede1998](https://discourse.nixos.org/u/ede1998)
#### Post date: [November 2, 2024, 10:59am UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/11 "2024-11-02T10:59:53Z")

</div>

The solutions in this thread worked for me but I wanted to be able to apply potentially multiple patches to the code. By overriding `src`, I would have to do that manually. So came up with this: I take old source and create a new derivation by running `patch` on it. Then I continue as described in previous posts.

```nix
  modifications =
    final: prev:
    let
      # Rust packages need special handling: https://nixos.wiki/wiki/Overlays
      addRustPatches =
        pkg: patches: cargoHash:
        pkg.overrideAttrs (oldAttrs: rec {
          # take the original source and apply all patches before making it the new source
          # we cannot use patches or patchPhase because all dependencies are vendored into
          # a separate derivation before the patch phase resulting in mismatching Cargo.lock
          # checksums
          src = prev.runCommand "patched-source" { } ''
            cp --no-preserve=mode -r ${oldAttrs.src} $out
            cd $out
            ${prev.lib.concatMapStringsSep "\n" (patch: ''patch -p1 < "${patch}"'') patches}
          '';
          cargoDeps = oldAttrs.cargoDeps.overrideAttrs (
            prev.lib.const {
              inherit src;
              outputHash = cargoHash;
            }
          );
        });
    in
    {
      fclones = addRustPatches prev.fclones [
        (builtins.fetchurl {
          url = "https://patch-diff.githubusercontent.com/raw/pkolaczk/fclones/pull/280.patch";
          sha256 = "sha256:0inir6g158hfc4a1s2hwsbr887szb6mzpm961xjpisy1vgbjg9hy";
        })
      ] "sha256-o+jsVnw9FvaKagiEVGwc+l0hE25X+KYY36hFhJwlcj0=";
    };

```

---

<div class="post-metadata">

### Author: ![TomaSajt](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tomasajt/32/10546_2.png) [@TomaSajt](https://discourse.nixos.org/u/TomaSajt)
#### Post date: [November 2, 2024, 12:35pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/12 "2024-11-02T12:35:17Z")

</div>

By the way, nixpkgs already has `applyPatches` which does your patched-source logic.

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [November 2, 2024, 2:09pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/13 "2024-11-02T14:09:28Z")

</div>

I assume you meant [`cargoPatches`](https://nixos.org/manual/nixpkgs/unstable/#building-a-crate-with-an-absent-or-out-of-date-cargo.lock-file)? I’ve never seen `applyPatches`.

---

<div class="post-metadata">

### Author: ![TomaSajt](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tomasajt/32/10546_2.png) [@TomaSajt](https://discourse.nixos.org/u/TomaSajt)
#### Post date: [November 2, 2024, 3:30pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/14 "2024-11-02T15:30:14Z")

</div>

I meant applyPatches. It’s not widely used, but can be useful in some situations where the source needs to be transformed before the normal patches take effect.

---

<div class="post-metadata">

### Author: ![ede1998](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/e/9d8465/32.png) [@ede1998](https://discourse.nixos.org/u/ede1998)
#### Post date: [November 2, 2024, 6:12pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/15 "2024-11-02T18:12:09Z")

</div>

You can find the implementation here. It’s undocumented in the manuals.

> <https://github.com/NixOS/nixpkgs/blob/63dacb46bf939521bdc93981b4cbb7ecb58427a0/pkgs/build-support/trivial-builders/default.nix#L852>

`cargoPatches` didn’t seem to work for me

---

<div class="post-metadata">

### Author: ![bratorange](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bratorange/32/30297_2.png) [@bratorange](https://discourse.nixos.org/u/bratorange)
#### Post date: [January 6, 2025, 1:27pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/16 "2025-01-06T13:27:09Z")

</div>

When reading articles like this [Overriding | nixpkgs](https://ryantm.github.io/nixpkgs/using/overrides/) I expected the override to work something like this:

```auto
pkgs.conduwuit.overrideAttrs (finalAttrs: previousAttrs: rec {
      version = "0.5.0-rc2";
      src = pkgs.fetchFromGitHub {
        owner = "girlbossceo";
        repo = "conduwuit";
        rev = "v${version}";
        hash = "sha256-xnwqhU3yOIyWRrD/Pq3jmUHoNZSY8Ms9h8OTsZVYQ1g=";
      };
      cargoSha256 = "somethingsomething";
    });

```

But this would propably require changing overrideAttrs to include support for buildRustPackage?

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [January 6, 2025, 2:22pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/17 "2025-01-06T14:22:12Z")

</div>

Try this. Important part is overriding `cargoDeps`.

> [@Overriding version on Rust based package](https://discourse.nixos.org/t/overriding-version-on-rust-based-package/57445/2):
>
> (pkgs.FOO.overrideAttrs (finalAttrs: prevAttrs: { cargoHash = ""; # build and replace this src = pkgs.fetchBAR { ... }; # change fetcher version = "..."; # change this cargoDeps = pkgs.rustPlatform.fetchCargoTarball { inherit (finalAttrs) pname src version; hash = finalAttrs.cargoHash; }; } )) replace FOO, BAR, and version, cargoHash should stay empty until you build and get the hash.

---

<div class="post-metadata">

### Author: ![allrealmsoflife](https://discourse.nixos.org/user_avatar/discourse.nixos.org/allrealmsoflife/32/32709_2.png) [@allrealmsoflife](https://discourse.nixos.org/u/allrealmsoflife)
#### Post date: [January 6, 2025, 2:39pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/18 "2025-01-06T14:39:14Z")

</div>

There is a nix hour episode number 5 with overriding a rust source, and the problem with the updating the hash and such. I transcribed it for easy reading. It’s a very interesting episode where they explore this issue deeply. I think within the episode they checkout this thread as well. The transcript is at:

> <https://github.com/allrealmsoflife/nix-hour-transcripts/blob/6536aae0c9bd5b944a87f7cb47f60266cfd5cc2d/episodes/5/5.md>

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [January 6, 2025, 3:10pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/19 "2025-01-06T15:10:01Z")

</div>

It’s simply the fact that `.overrideAttrs` only cares about attributes of `stdenv.mkDerivation` and not builders that use it (like `buildRustPackage`). So overriding these higher-level builders requires looking at their impl details. Since `cargoHash` feeds into `cargoDeps`, that suffices here for the override.

I also will point out that `fetchCargoTarball` specifically has a weird behavior where the name affects the hash (due to some internal folder structure) so if you do change the name, you must blank out the hash, rebuild, get the new hash (as with any FOD where you change something that affects the hash). Simply leaving the hash unset will point at the old FOD, and you won’t get the rebuild that you need.

---

<div class="post-metadata">

### Author: ![sldr](https://discourse.nixos.org/user_avatar/discourse.nixos.org/sldr/32/30689_2.png) [@sldr](https://discourse.nixos.org/u/sldr)
#### Post date: [January 20, 2025, 8:28pm UTC](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/20 "2025-01-20T20:28:38Z")

</div>

Welp, I had this exact issue, but solved it without the use of `overrideAttrs` (thus sparing me from having to take into consideration the innards of `buildRustPackage`).

I wrote a blog post to document/vent about the whole ordeal (available [here](https://sldr.se/posts/2024/12/overriding-for-fun-and-profit) for the curious, with the salient part [here](https://sldr.se/posts/2024/12/overriding-for-fun-and-profit/#yo-dawg-i-heard-you-like-overriding)). The long and the short is that we can, instead of overriding the arguments passed to `buildRustPackage` , we override _that_ function itself to intercept its arguments.

```nix
pkgs.foo.override (
  let
    rp = pkgs.rustPlatform;
  in
  {
    rustPlatform = rp // {
      buildRustPackage = args: rp.buildRustPackage (
        args // rec {
          # Here's where we can toy with the inputs
          version = "foo";
          src = bar;
          cargoHash = "quack";
        }
      );
    };
  }
);

```

More verbose, but it is (I think) a general-ish solution which ought to work on _any_ wrapper around `mkDerivation`, not just `buildRustPackage`.

[Next page](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393.md?page=2)
