Skip to content

Conversation

@jla2000
Copy link

@jla2000 jla2000 commented Nov 15, 2025

I have created a nix flake, that will fetch the required rust toolchain using rust-overlay.
By doing this, the toolchain does not need to be installed into the user environment directly.
I also added an .envrc, this will allow to directly drop into a devshell if eg. direnv is used.

@LegNeato
Copy link
Collaborator

I don't know anything about nix, @eddyb ?

@alphastrata
Copy link
Contributor

not maintainer --but I think forcing everyone to pull in the android toolchain might be a bit of an ask no?

{
devShells = {
default = pkgs.callPackage ./shell.nix { inherit rustToolchain; };
android = pkgs.callPackage ./android.nix { inherit rustToolchain; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alphastrata This means you need to run nix develop .#android to get a dev shell with android, otherwise it'll just use default. (Though it wouldn't allow you to run the examples locally, since it's missing the deps that shell.nix provides... Maybe we should treat android as a purely additive thing?)

It looks good to me, but I'm not super familiar with nix myself, so I'll get @eddyb review it as well.

Copy link
Contributor

@alphastrata alphastrata Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see. ty.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure for what the android.nix was used for, I am assuming just to cross compile to android? If so, I think it's fine that it won't allow to run the examples per default as it was already like this before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can compile the example-runner-wgpu to Android. But it's not documented in the example readme, could only find our Android CI building it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What packages would be missing? I could just try add them to the android devshell

@jla2000
Copy link
Author

jla2000 commented Nov 19, 2025

One thing I am not sure about yet is how the rust-overlay flake input can be automatically updated when upgrading to a newer toolchain without forcing someone to use nix. With these changes, every time the rust toolchain is being updated, it would be necessary to run "nix flake update rust-overlay" as well to make sure the new toolchain version is known to nix.

description = "rust-gpu";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the proper solution is but I will note that this approach has failed in the past:

Rust-GPU/rust-gpu-shadertoys#43 (comment)

Keeping default.nix (as shell.nix, which I suppose is more appropriate), does make this less drastic, and I can explicitly avoid touching the flake path until it's usable for myself on NixOS etc.

But it's hard to tell what value of flakes really is outside of e.g. CI.

@@ -0,0 +1 @@
use flake
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this common practice? I've never used a repo that came with an .envrc, and always did it locally, e.g. by running this (with a check that makes it idempotent, just in case I accidentally run it twice in the same directory):

git check-ignore -q .envrc || \
  echo /.envrc >> $(git rev-parse --git-path info/exclude) && echo use nix >> .envrc && direnv allow

(split onto two lines for readability on GitHub, it's just a oneliner in my shell history)

I use fish so typing any of envrc/use nix/direnv allow, and pressing ⬆️, is enough to recall it, but it is a weird thing I came up with when starting to use direnv (having already been using .git/info/exclude here and there whenever I didn't want to modify .gitignore etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants