Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -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.).

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tests/Cargo.lock
.github/install-spirv-tools/Cargo.lock
rustc-ice-*.txt
.idea
.direnv
24 changes: 13 additions & 11 deletions android.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# (you can also replace `cargo apk build` with `cargo apk run` to launch it,
# via `adb`, into either the Android Emulator, or a physical Android device)

let
pkgs = import <nixpkgs> {};
in with pkgs; mkShell rec {
{ pkgs, rustToolchain, ... }:

with pkgs; mkShell rec {
# Workaround for https://github.com/NixOS/nixpkgs/issues/60919.
# NOTE(eddyb) needed only in debug mode (warnings about needing optimizations
# turn into errors due to `-Werror`, for at least `spirv-tools-sys`).
Expand All @@ -20,15 +20,17 @@ in with pkgs; mkShell rec {
# Allow cargo to download crates (even inside `nix-shell --pure`).
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";

nativeBuildInputs = [ rustup cargo-apk jdk ];
nativeBuildInputs = [ rustToolchain cargo-apk jdk ];

ANDROID_SDK_ROOT = let
androidComposition = androidenv.composeAndroidPackages {
abiVersions = [ "arm64-v8a" "x86_64" ];
includeNDK = true;
platformVersions = [ "30" ];
};
in "${androidComposition.androidsdk}/libexec/android-sdk";
ANDROID_SDK_ROOT =
let
androidComposition = androidenv.composeAndroidPackages {
abiVersions = [ "arm64-v8a" "x86_64" ];
includeNDK = true;
platformVersions = [ "30" ];
};
in
"${androidComposition.androidsdk}/libexec/android-sdk";

ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
}
96 changes: 96 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
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.

rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
config.allowUnfree = true;
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
{
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

};
});
}
18 changes: 10 additions & 8 deletions default.nix → shell.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
let
pkgs = import <nixpkgs> {};
in with pkgs; stdenv.mkDerivation rec {
name = "rust-gpu";
{ pkgs, rustToolchain, ... }:

with pkgs; mkShell {
# Workaround for https://github.com/NixOS/nixpkgs/issues/60919.
# NOTE(eddyb) needed only in debug mode (warnings about needing optimizations
# turn into errors due to `-Werror`, for at least `spirv-tools-sys`).
Expand All @@ -11,16 +9,20 @@ in with pkgs; stdenv.mkDerivation rec {
# Allow cargo to download crates (even inside `nix-shell --pure`).
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";

nativeBuildInputs = [ rustup ];
nativeBuildInputs = [ rustToolchain ];

# Runtime dependencies (for the example runners).
LD_LIBRARY_PATH = with xorg; lib.makeLibraryPath [
LD_LIBRARY_PATH = with pkgs.xorg; lib.makeLibraryPath [
vulkan-loader

# NOTE(eddyb) winit really wants `libxkbcommon` on Wayland for some reason
# (see https://github.com/rust-windowing/winit/issues/1760 for more info).
wayland libxkbcommon
wayland
libxkbcommon

libX11 libXcursor libXi libXrandr
libX11
libXcursor
libXi
libXrandr
];
}