One reason why it takes longer than a clean cargo build is that Nix is currently building/installing the release binary target, but it’s running the tests in debug mode, so it ends up compiling all the libraries twice.
There’s work underway to try to address this, which you might be interested in trying out:
NixOS:staging
← Ma27:increase-rust-build-speed
opened 08:27PM - 11 Mar 20 UTC
###### Motivation for this change
<del> :warning: **Caution:** this is more o… r less an experiment and I'm not sure if that has implications on any leaf-packages since I just tested a few packages like rustup or cargo-audit with it, so this needs some review and testing before becoming mergable.</del>
As noted [later on](https://github.com/nixos/nixpkgs/pull/82342#issuecomment-626018989), I consider this rather usable after several iterations of reviews and tests, however we need more extensive testing before merging this to upstream.
----
When running `cargo test --release`, the artifacts from `buildPhase`
will be reused here. Previously, most of the stuff had to be recompiled
without optimizations.
###### Things done
- [x] Tested using sandboxing ([nix.useSandbox](http://nixos.org/nixos/manual/options.html#opt-nix.useSandbox) on NixOS, or option `sandbox` in [`nix.conf`](http://nixos.org/nix/manual/#sec-conf-file) on non-NixOS linux)
- Built on platform(s)
- [x] NixOS
- [ ] macOS
- [ ] other Linux distributions
- [ ] Tested via one or more NixOS test(s) if existing and applicable for the change (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
- [ ] Tested compilation of all pkgs that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review wip"`
- [ ] Tested execution of all binary files (usually in `./result/bin/`)
- [ ] Determined the impact on package closure size (by running `nix path-info -S` before and after)
- [ ] Ensured that relevant documentation is up to date
- [x] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/.github/CONTRIBUTING.md).