Skip to content

Commit 5dd40bd

Browse files
committed
Create nix flake
1 parent b3eda4d commit 5dd40bd

File tree

6 files changed

+147
-19
lines changed

6 files changed

+147
-19
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ tests/Cargo.lock
55
.github/install-spirv-tools/Cargo.lock
66
rustc-ice-*.txt
77
.idea
8+
.direnv

android.nix

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
# (you can also replace `cargo apk build` with `cargo apk run` to launch it,
1010
# via `adb`, into either the Android Emulator, or a physical Android device)
1111

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

23-
nativeBuildInputs = [ rustup cargo-apk jdk ];
23+
nativeBuildInputs = [ rustToolchain cargo-apk jdk ];
2424

25-
ANDROID_SDK_ROOT = let
26-
androidComposition = androidenv.composeAndroidPackages {
27-
abiVersions = [ "arm64-v8a" "x86_64" ];
28-
includeNDK = true;
29-
platformVersions = [ "30" ];
30-
};
31-
in "${androidComposition.androidsdk}/libexec/android-sdk";
25+
ANDROID_SDK_ROOT =
26+
let
27+
androidComposition = androidenv.composeAndroidPackages {
28+
abiVersions = [ "arm64-v8a" "x86_64" ];
29+
includeNDK = true;
30+
platformVersions = [ "30" ];
31+
};
32+
in
33+
"${androidComposition.androidsdk}/libexec/android-sdk";
3234

3335
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
3436
}

flake.lock

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
description = "rust-gpu";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
6+
rust-overlay.url = "github:oxalica/rust-overlay";
7+
flake-utils.url = "github:numtide/flake-utils";
8+
};
9+
10+
outputs = { nixpkgs, rust-overlay, flake-utils, ... }:
11+
flake-utils.lib.eachDefaultSystem (system:
12+
let
13+
pkgs = import nixpkgs {
14+
inherit system;
15+
overlays = [ (import rust-overlay) ];
16+
config.allowUnfree = true;
17+
};
18+
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
19+
in
20+
{
21+
devShells = {
22+
default = pkgs.callPackage ./shell.nix { inherit rustToolchain; };
23+
android = pkgs.callPackage ./android.nix { inherit rustToolchain; };
24+
};
25+
});
26+
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
let
2-
pkgs = import <nixpkgs> {};
3-
in with pkgs; stdenv.mkDerivation rec {
4-
name = "rust-gpu";
1+
{ pkgs, rustToolchain, ... }:
52

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

14-
nativeBuildInputs = [ rustup ];
12+
nativeBuildInputs = [ rustToolchain ];
1513

1614
# Runtime dependencies (for the example runners).
17-
LD_LIBRARY_PATH = with xorg; lib.makeLibraryPath [
15+
LD_LIBRARY_PATH = with pkgs.xorg; lib.makeLibraryPath [
1816
vulkan-loader
1917

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

24-
libX11 libXcursor libXi libXrandr
23+
libX11
24+
libXcursor
25+
libXi
26+
libXrandr
2527
];
2628
}

0 commit comments

Comments
 (0)