pbsds
January 22, 2025, 1:49pm
21
To clarify, https://github.com/NixOS/nixpkgs/pull/234651 alone doesn’t solve the “arguments not overridable via the <pkg>.overrideAttrs” issue.
To make cargoHash overridable in buildRustPackage-constructed packages, we need to utilize the fixed-point arguments support of the base build helper and refer to cargoHash as finalAttrs.cargoHash or finalAttrs.passthru.cargoHash to use the overridden version.
For rustPlatform.buildRustPackage, the base build helper is stdenv.mkDerivation, which already supports fixed-point arguments. While for build helpers that are not directly based on stdenv.mkDerivation, it would be helpful to refactor the base build helper with lib.extendMkDerivation.
We underwent a similar transition to make vendorHash overridable for buildGoModule-constructed packages:
NixOS:staging ← ShamrockLee:go-module-overlay-stdenv
opened 09:32PM - 06 Apr 23 UTC
###### Description of changes
The Go package builder `buildGoModule` is refac… tored to adopt the overlay-style `stdenv.mkDerivation` (#119942) and to fix overriding. One can now override `vendorHash` using `overrideAttrs`. This addresses https://github.com/NixOS/nixpkgs/issues/86349#issuecomment-763914147
The `goModules` and `vendorHash` attributes are moved out of `passthru` as they are already exposed as `stdenv.mkDerivation` attributes. They can still be accessed as `pet.vendorHash`, but no longer `pet.passthru.vendorHash`. The builder now only adds `go` to `passthru`.
To address the issue of `vendorHash = null` through `overrideAttrs` may break the overriding of `goModules`, this PR also provides an overridable `passthru.overrideModAttrs` that will be applied to `goModules` when `vendorHash` is not `null`.
Closes #86349
Comparison to similar PRs:
In this PR, the diff of `pkgs/build-support/go/module.nix` is shorter than #171586.
<!--
For package updates please link to a changelog or describe changes, this helps your fellow maintainers discover breaking updates.
For new packages please briefly describe the package or provide a link to its homepage.
-->
###### Things done
- Built on platform(s)
- [X] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- [ ] For non-Linux: Is `sandbox = true` set in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
- [ ] Tested, as applicable:
- [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
- and/or [package tests](https://nixos.org/manual/nixpkgs/unstable/#sec-package-tests)
- or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
- made sure NixOS tests are [linked](https://nixos.org/manual/nixpkgs/unstable/#ssec-nixos-tests-linking) to the relevant packages
- [ ] Tested compilation of all packages that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"`. Note: all changes have to be committed, also see [nixpkgs-review usage](https://github.com/Mic92/nixpkgs-review#usage)
- [ ] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [23.05 Release Notes (or backporting 22.11 Release notes)](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#generating-2305-release-notes)
- [X] (Package updates) Added a release notes entry if the change is major or breaking
- [ ] (Module updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [X] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
<!--
To help with the large amounts of pull requests, we would appreciate your
reviews of other pull requests, especially simple package updates. Just leave a
comment describing what you have tested in the relevant package/service.
Reviewing helps to reduce the average time-to-merge for everyone.
Thanks a lot if you do!
List of open PRs: https://github.com/NixOS/nixpkgs/pulls
Reviewing guidelines: https://nixos.org/manual/nixpkgs/unstable/#chap-reviewing-contributions
-->
A more complex transition for Python packages to use overrideAttrs instead of overridePythonAttrs is underway. Reviews and feedbacks are welcome:
NixOS:master ← ShamrockLee:build-python-direct-overriding-simple
opened 12:00PM - 24 Jan 25 UTC
This PR makes the following attributes overridable using `overrideAttrs`:
- `… src`
- `removePythonDeps`
- `relaxPythonDeps`
- `passthru.build-system`
- `passthru.dependencies`
- `passthru.pyproject`
Depends on (the diff will shorten once the dependency merges):
- #375921
Related PRs:
- Fix `disabled` and make `passthru.disabled` overridable using `overrideAttrs`:
- #267296
- #376419
- Fix `name` and make `pname` and `version` overridable using `overrideAttrs`:
- #376714
- Make the check-related attributes overridable using `overrideAttrs`:
- #376060
## Things done
- Built on platform(s)
- [ ] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- For non-Linux: Is sandboxing enabled in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
- [ ] `sandbox = relaxed`
- [ ] `sandbox = true`
- [ ] Tested, as applicable:
- [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
- and/or [package tests](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests)
- or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
- made sure NixOS tests are [linked](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#linking-nixos-module-tests-to-a-package) to the relevant packages
- [ ] Tested compilation of all packages that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"`. Note: all changes have to be committed, also see [nixpkgs-review usage](https://github.com/Mic92/nixpkgs-review#usage)
- [ ] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [25.05 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) (or backporting [24.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md) and [25.05](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) Release notes)
- [ ] (Package updates) Added a release notes entry if the change is major or breaking
- [ ] (Module updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [ ] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
<!--
To help with the large amounts of pull requests, we would appreciate your
reviews of other pull requests, especially simple package updates. Just leave a
comment describing what you have tested in the relevant package/service.
Reviewing helps to reduce the average time-to-merge for everyone.
Thanks a lot if you do!
List of open PRs: https://github.com/NixOS/nixpkgs/pulls
Reviewing guidelines: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#reviewing-contributions
-->
---
Add a :+1: [reaction] to [pull requests you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc
I’m trying the solution here (overriding cargoDeps) but encountering a very strange error during build:
error: output path '/nix/store/xfjsxcnlw6qzrshafkj5988h5img3lyv-lazyjj-0.5.0-vendor.drv.chroot/root/nix/store/r57fwwdbf62hfrwlpvhjz9bp4f3hmzfb-lazyjj-0.5.0-vendor' should be a non-executable regular file since recursive hashing is not enabled (one of outputHashMode={flat,text} is true)
This is my code right now:
lazyjj.overrideAttrs (old: rec {
src = pkgs.fetchFromGitHub {
owner = "Cretezy";
repo = "lazyjj";
rev = "push-rymqkytxnusu";
hash = "sha256-UN2eTSgHUQQEaALZ51H4r6nKnGcm6klnbSkUrEBBoNw=";
};
cargoDeps = old.cargoDeps.overrideAttrs (
lib.const {
inherit src;
# Deliberately invalid hash -- I'm not sure how to effectively
# pre-determine it.
outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}
);
})
What’s going on here? :<
Edit: Manually setting outputHashMode = "recursive" fixed the issue, but upon updating outputHash to match what the proceeding hash mismatch error was expecting, I received the original ERROR: cargoHash or cargoSha256 is out of date error!
The result derivation of fetchCargoVendor is not currently overridable.
BTW, <pkg>.overrideAttrs (provided by stdenv.mkDerivation) supports { foo = ""; }, previousAttrs: { foo = ""; }, and finalAttrs: previousAttrs; { foo = ""; }.
Let me take back what I said above.
Even though the fetchCargoVendor-constructed derivation is not fully overridable in current implementation, the hash can be overridden by overriding the vendorStaging;
lazyjj.overrideAttrs (finalAttrs: previousAttrs: {
src = pkgs.fetchFromGitHub {
owner = "Cretezy";
repo = "lazyjj";
rev = "push-rymqkytxnusu";
hash = "sha256-UN2eTSgHUQQEaALZ51H4r6nKnGcm6klnbSkUrEBBoNw=";
};
cargoDeps = previousAttrs.cargoDeps.overrideAttrs (previousAttrs: {
vendorStaging = previousAttrs.vendorStaging.overrideAttrs {
inherit (finalAttrs) src;
# Deliberately invalid hash -- I'm not sure how to effectively
# pre-determine it.
outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
}
);
})
This seems to work but it still ultimately fails to provide me the hash I should be using like I’d expect it to…
Could you elaborate this? After replacing the fake hash with the hash got from the error message, the overridden lazyjj package builds on my machine.
Now I know why my previous suggestion doesn’t work. The src taken by cargoDeps doesn’t update when the main src is overridden. Thank you for testing and pointing out the issue.
I’m authoring a fix in Nixpkgs PR 435239. Please take a look!
master ← ShamrockLee:build-rust-package-overriding-pre
opened 11:40AM - 20 Aug 25 UTC
…riding
Make <rust-package>.cargoDeps reference the overridden <rust-package>… .src and other attributes.
Make Rust package overriding *possible* before making further design decisions about the `<pkg>.overrideAttrs` interface.
This is an initial effort to fixe #415397
## Things done
- Built on platform:
- [ ] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- Tested, as applicable:
- [ ] [NixOS tests] in [nixos/tests].
- [ ] [Package tests] at `passthru.tests`.
- [ ] Tests in [lib/tests] or [pkgs/test] for functions and "core" functionality.
- [ ] Ran `nixpkgs-review` on this PR. See [nixpkgs-review usage].
- [ ] Tested basic functionality of all binary files, usually in `./result/bin/`.
- Nixpkgs Release Notes
- [ ] Package update: when the change is major or breaking.
- NixOS Release Notes
- [ ] Module addition: when adding a new NixOS module.
- [ ] Module update: when the change is significant.
- [ ] Fits [CONTRIBUTING.md], [pkgs/README.md], [maintainers/README.md] and other READMEs.
[NixOS tests]: https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests
[Package tests]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests
[nixpkgs-review usage]: https://github.com/Mic92/nixpkgs-review#usage
[CONTRIBUTING.md]: https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md
[lib/tests]: https://github.com/NixOS/nixpkgs/blob/master/lib/tests
[maintainers/README.md]: https://github.com/NixOS/nixpkgs/blob/master/maintainers/README.md
[nixos/tests]: https://github.com/NixOS/nixpkgs/blob/master/nixos/tests
[pkgs/README.md]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md
[pkgs/test]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/test
---
Add a :+1: [reaction] to [pull requests you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc
Daua
January 28, 2026, 9:02pm
29
Just faced this issue. From the rustPlatform docs: nixpkgs/doc/languages-frameworks/rust.section.md at 6bc0621ff46a81a7fa9063788127bad9906ad1a9 · NixOS/nixpkgs · GitHub
Example:
final: prev:
let
name = "cargo-nextest";
version = "0.9.124";
src = final.fetchFromGitHub {
owner = "nextest-rs";
repo = "nextest";
rev = "cargo-nextest-${version}";
hash = "sha256-qvJ/dqbls2fVSPY++kYBIeiu14eDD8ORuvcD8dEtMZ8=";
};
in
{
${name} = prev.${name}.overrideAttrs (oldAttrs: rec {
inherit version src;
cargoDeps = prev.rustPlatform.fetchCargoVendor {
inherit src;
name = "${name}-${version}-vendor";
hash = "sha256-3fZSXBP6vMh7GN2eY2upsvV/mTuDOcSovdsbcZBQA4U=";
};
});
}
Here’s an example if you want minimal cargoDeps override. Of course, it’s coupled with fetchCargoVendor implementation, which is very likely to be break in the future.
codex = prev.codex.overrideAttrs (oldAttrs: rec {
version = "0.153.4";
src =
assert lib.assertMsg (lib.versionOlder oldAttrs.version "0.153.4")
"codex is updated in the upstream";
final.fetchFromGitHub {
owner = "openai";
repo = "codex";
tag = "rust-v${version}";
hash = "sha256-lHiDj5SodaM3mh8goMm6esfejeAT+Y3JJWrRnyj6sJo=";
};
cargoHash = "sha256-GG6kOXmCdq+bZLU2ul0DIVL8lDuweayvZvXn6+bcUZw=";
cargoDeps = oldAttrs.cargoDeps.overrideAttrs (oldAttrs: {
vendorStaging = oldAttrs.vendorStaging.overrideAttrs {
outputHash = cargoHash;
};
});
});