Skip to content

Commit a16adc7

Browse files
Myxogastria0808nukanotoalice-i-cecileistudyatuni
authored
Update add flake.nix example (#19321)
# Objective I can't build a project using bevy under the environment of NixOS, so I have to create flake.nix file. ## Solution I add flake.nix example to `linux_dependencies.md`. ## Testing I checked my NixOS environment in a project using bevy and booted the project's game successfully. --- ## Showcase <details> <summary>Click to view showcase</summary> 1. Create a GitHub project using bevy. 2. Add a flake.nix file. 3. Commit to add this file to the GitHub repository. 4. Run `nix develop` </details> --------- Co-authored-by: nukanoto <[email protected]> Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Ilia <[email protected]>
1 parent ddee5cc commit a16adc7

File tree

1 file changed

+80
-6
lines changed

1 file changed

+80
-6
lines changed

docs/linux_dependencies.md

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Set the `PKG_CONFIG_PATH` env var to `/usr/lib/<target>/pkgconfig/`. For example
9191
export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/"
9292
```
9393

94-
## Arch / Manjaro
94+
## [Arch](https://archlinux.org/) / [Manjaro](https://manjaro.org/)
9595

9696
```bash
9797
sudo pacman -S libx11 pkgconf alsa-lib libxcursor libxrandr libxi
@@ -102,14 +102,88 @@ Install `pipewire-alsa` or `pulseaudio-alsa` depending on the sound server you a
102102
Depending on your graphics card, you may have to install one of the following:
103103
`vulkan-radeon`, `vulkan-intel`, or `mesa-vulkan-drivers`
104104

105-
## Void
105+
## [Void](https://voidlinux.org/)
106106

107107
```bash
108108
sudo xbps-install -S pkgconf alsa-lib-devel libX11-devel eudev-libudev-devel
109109
```
110110

111111
## [Nix](https://nixos.org)
112112

113+
### flake.nix
114+
115+
Add a `flake.nix` file to the root of your GitHub repository containing:
116+
117+
```nix
118+
{
119+
description = "bevy flake";
120+
121+
inputs = {
122+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
123+
rust-overlay.url = "github:oxalica/rust-overlay";
124+
flake-utils.url = "github:numtide/flake-utils";
125+
};
126+
127+
outputs =
128+
{
129+
nixpkgs,
130+
rust-overlay,
131+
flake-utils,
132+
...
133+
}:
134+
flake-utils.lib.eachDefaultSystem (
135+
system:
136+
let
137+
overlays = [ (import rust-overlay) ];
138+
pkgs = import nixpkgs {
139+
inherit system overlays;
140+
};
141+
in
142+
{
143+
devShells.default =
144+
with pkgs;
145+
mkShell {
146+
buildInputs =
147+
[
148+
# Rust dependencies
149+
(rust-bin.stable.latest.default.override { extensions = [ "rust-src" ]; })
150+
pkg-config
151+
]
152+
++ lib.optionals (lib.strings.hasInfix "linux" system) [
153+
# for Linux
154+
# Audio (Linux only)
155+
alsa-lib
156+
# Cross Platform 3D Graphics API
157+
vulkan-loader
158+
# For debugging around vulkan
159+
vulkan-tools
160+
# Other dependencies
161+
libudev-zero
162+
xorg.libX11
163+
xorg.libXcursor
164+
xorg.libXi
165+
xorg.libXrandr
166+
libxkbcommon
167+
];
168+
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
169+
LD_LIBRARY_PATH = lib.makeLibraryPath [
170+
vulkan-loader
171+
xorg.libX11
172+
xorg.libXi
173+
xorg.libXcursor
174+
libxkbcommon
175+
];
176+
};
177+
}
178+
);
179+
}
180+
```
181+
182+
> [!TIP]
183+
> We have confirmed that this flake.nix can be used successfully on NixOS and MacOS with Rust's edition set to 2021.
184+
185+
### shell.nix
186+
113187
Add a `shell.nix` file to the root of the project containing:
114188

115189
```nix
@@ -138,8 +212,8 @@ If running nix on a non NixOS system (such as ubuntu, arch etc.), [NixGL](https:
138212
to link graphics drivers into the context of software installed by nix:
139213

140214
1. Install a system specific nixGL wrapper ([docs](https://github.com/nix-community/nixGL)).
141-
* If you're running a nvidia GPU choose `nixVulkanNvidia`.
142-
* Otherwise, choose another wrapper appropriate for your system.
215+
- If you're running a nvidia GPU choose `nixVulkanNvidia`.
216+
- Otherwise, choose another wrapper appropriate for your system.
143217
2. Run `nixVulkanNvidia-xxx.xxx.xx cargo run` to compile a bevy program, where `xxx-xxx-xx` denotes the graphics driver version `nixVulkanNvidia` was compiled with.
144218

145219
This is also possible with [Nix flakes](https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html).
@@ -152,7 +226,7 @@ for more information about `devShells`.
152226
Note that this template does not add Rust to the environment because there are many ways to do it.
153227
For example, to use stable Rust from nixpkgs, you can add `cargo` and `rustc` to `nativeBuildInputs`.
154228

155-
[Here]([https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/ju/jumpy/package.nix](https://github.com/NixOS/nixpkgs/blob/0da3c44a9460a26d2025ec3ed2ec60a895eb1114/pkgs/games/jumpy/default.nix))
229+
[Here](https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/ju/jumpy/package.nix)
156230
is an example of packaging a Bevy program in nix.
157231

158232
## [OpenSUSE](https://www.opensuse.org/)
@@ -161,7 +235,7 @@ is an example of packaging a Bevy program in nix.
161235
sudo zypper install libudev-devel gcc-c++ alsa-lib-devel
162236
```
163237

164-
## Gentoo
238+
## [Gentoo](https://www.gentoo.org/)
165239

166240
```bash
167241
sudo emerge --ask libX11 pkgconf alsa-lib

0 commit comments

Comments
 (0)