Generate Cargo.nix manually
- ✅ Does not use import from derivation feature from Nix which may lead to disabling build parallelism,
- 🛠️ but you need to regenerate
Cargo.nix
whenever you change your dependencies or other config affectingCargo.lock
.
Disregarding whether you use nix with flakes or without, you might want to generate
your Cargo.nix
file manually. That way you avoid using the
import from derivation
feature from nix which might disable build parallelism.
Here is a simple example which uses all the defaults and will generate a Cargo.nix
file.
If you installed crate2nix locally:
If you prefer to run it without installation:
Here is a more elaborate example that uses <nixos-unstable>
as the default pkgs
path
(instead of <nixpkgs>
) and specifies both the path
to the Cargo.toml
file (-f
) and the output (-o
) file explicitly (usually not needed).
Use crate2nix help
to show all commands and options.
Look at the ./crate2nix/Cargo.nix file of this project for a non-trivial example. (How meta!)