bevy
bevy copied to clipboard
Add NixOS example for following rust-toolchain.toml to docs
Objective
To make it easier for projects using nix to work with changing channels.
Solution
Adding a section to the documentation to show how this can be done with a modified nix file.
Welcome, new contributor!
Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨
A friend of mine contributed a nix file to a project of mine, and added this neat little snippet. I thought more people would have use of it, so I suggested he contribute it. He did not have time so he gave the go-ahead for me to contribute it.
I don't read much nix, but I tested it at least. I do recommend someone else testing it on their nix system as well.
Hope this is helpful!
Seconding James' stance here :)
I'm a bit confused: Why run rustup toolchain install when entering the shell, when rustup tools (including cargo) already install and use the toolchain specified by rust-toolchain.toml automatically ? As far as I can tell, the only difference between this file and the example already documented is bringing in rustup and installing a toolchain.
If using rustup to handle rust toolchains (instead of say rust-overlay), this shouldn't need to be handled by nix. Just having rustup in the nativeBuildInputs should be enough. I don't really understand why this is nix-specific ?
I feel like maybe I don't understand the issue in the first place ?
Asked my friend, he said that wasn't his experience, and that he needs to try again. I'll update this pull when he's had time to check.
I'm a bit confused: Why run
rustup toolchain installwhen entering the shell, when rustup tools (including cargo) already install
This is the confusion, on nix installing rustup doesn't automatically add a toolchain (unlike the official rust installer that adds one by default), which means no cargo that reads the rust-toolchain.toml, to add the correct toolchain.
The classical chicken and egg problem. You need cargo to use rust-toolchain.toml but don't have one as nix itself wasn't told to add one.
The used solution solves this by installing a toolchain "manually".
@rustbicycle (on discord) and me tested it, and the rustup-provided cargo (installed with the rustup package) does follow and automatically installs the right toolchain following appropriate rustup overrides as on other distros (be it the default toolchain, the per-directory manual overrides, the rust-toolchain.toml file or toolchain override arguments like cargo +beta). I can still reproduce it: nix-shell -p rustup -c cargo build (without a shell.nix) will build with the toolchain specified in a rust-toolchain.toml file.
Are you sure you don't have the nixpkgs-distributed cargo in your $PATH ? The cargo program from the nixpkgs cargo package (unlike cargo from the rustup package) doesn't allow changing toolchain, which is intended to ensure build reproducibility (the way I understand it).
TL;DR: I don't think this is an issue people should encounter assuming they use either rustup or nixpkgs' cargo with the rust overlay, but not both. I believe using both is discouraged, partly because of the issue I suspect you're encountering.
When I tested it many months ago it didn't work, but perhaps it was since fixed (or I did something wrong).
This seems more "how to use Rust with NixOS" than "how to use Bevy with NixOS". The current doc says https://github.com/bevyengine/bevy/blob/2fd432c463b3f02ee39c3ab3a47b8fa8c56c0689/docs/linux_dependencies.md?plain=1#L144 which seems good enough for me