From 6085fff77ab48028c4aa3f3ef4eb68288597385f Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 27 Dec 2022 19:21:10 -0500 Subject: [PATCH] improve nix docs --- docs/linux_dependencies.md | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/docs/linux_dependencies.md b/docs/linux_dependencies.md index 58d45e21e3cc0..ec7b16b78c956 100644 --- a/docs/linux_dependencies.md +++ b/docs/linux_dependencies.md @@ -101,29 +101,44 @@ Depending on your graphics card, you may have to install one of the following: sudo xbps-install -S pkgconf alsa-lib-devel libX11-devel eudev-libudev-devel ``` -## NixOS +## [Nix](https://nixos.org) Add a `shell.nix` file to the root of the project containing: ```nix -{ pkgs ? import {} }: -with pkgs; mkShell rec { +{ pkgs ? import { } }: + +with pkgs; + +mkShell rec { nativeBuildInputs = [ pkg-config - llvmPackages.bintools # To use lld linker ]; buildInputs = [ udev alsa-lib vulkan-loader - xlibsWrapper xorg.libXcursor xorg.libXrandr xorg.libXi # To use x11 feature - libxkbcommon wayland # To use wayland feature + xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature + libxkbcommon wayland # To use the wayland feature ]; - LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs; + LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; } ``` -And enter it by just running `nix-shell`. You should be able compile Bevy programs using `cargo run` within this nix-shell. You can do this in one line with `nix-shell --run "cargo run"`. +And enter it by just running `nix-shell`. +You should be able compile Bevy programs using `cargo run` within this nix-shell. +You can do this in one line with `nix-shell --run "cargo run"`. + +This is also possible with [Nix flakes](https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html). +Instead of creating `shell.nix`, you just need to add the derivation (`mkShell`) +to your `devShells` in `flake.nix`. Run `nix develop` to enter the shell and +`nix develop -c cargo run` to run the program. See +[Nix's documentation](https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-develop.html) +for more information about `devShells`. + +Note that this template does not add Rust to the environment because there are many ways to do it. +For example, to use stable Rust from nixpkgs, you can add `cargo` and `rustc` to `nativeBuildInputs`. -Note that this template does not add Rust to the environment because there are many ways to do it. For example, to use stable Rust from nixpkgs you can add `cargo` to `nativeBuildInputs`. +[Here](https://github.com/NixOS/nixpkgs/blob/master/pkgs/games/jumpy/default.nix) +is an example of packaging a Bevy program in nix. ## [OpenSUSE](https://www.opensuse.org/)