Help building Rust Bevy example games

Hello guys! I’m getting into rust game development and I want to setup an environment to run the examples from the bevy game engine.

Right now, I got to this shell.nix:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = with pkgs; [
    gcc
    libGL
    pkg-config
    wayland
    alsa-lib
    cargo
    openssl
    libudev-zero
    libxkbcommon
  ];
  LD_LIBRARY_PATH="${pkgs.libGL}/lib";
}

Having setup direnv, with echo “use nix > .envrc” then direnv allow, I get to a shell in which I can run the basic one:

$ cargo run --example hello_world
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.30s
     Running `target/debug/examples/hello_world`
hello world

However, running the 2D Bloom example gives me errors:

$ cargo run --example bloom_2d
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.29s
     Running `target/debug/examples/bloom_2d`
2026-01-31T20:38:23.175965Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux (NixOS 26.05)", kernel: "6.12.67", cpu: "AMD Ryzen 5 7535U with Radeon Graphics", core_count: "6", memory: "14.4 GiB" }
2026-01-31T20:38:23.184384Z  INFO xkbcommon_dl: Failed loading `libxkbcommon.so.0`. Error: CantOpen(DlOpen { desc: "libxkbcommon.so.0: cannot open shared object file: No such file or directory" })
2026-01-31T20:38:23.184441Z  INFO xkbcommon_dl: Failed loading `libxkbcommon.so`. Error: CantOpen(DlOpen { desc: "libxkbcommon.so: cannot open shared object file: No such file or directory" })

thread 'main' (31296) panicked at /home/bernborgess/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winit-0.30.12/src/platform_impl/linux/wayland/seat/keyboard/mod.rs:300:41:
called `Result::unwrap()` on an `Err` value: XKBNotFound
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Note that I added libxkbcommon to the buildInputs after the error, but the issue persists. Any pointers at this stage?

hi @bernborgess – you are close, but missing a few dependencies and inputs that could get a dev shell working with bevy. Fortunately, the bevy community does have a recommended/minimal flake.nix to get you started – bevy/docs/linux_dependencies.md at 5f8270f2e049f90139a503d1e930070d926f9427 · bevyengine/bevy · GitHub

{
  description = "bevy flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    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
        overlays = [ (import rust-overlay) ];
        pkgs = import nixpkgs {
          inherit system overlays;
        };
      in
      {
        devShells.default =
          with pkgs;
          mkShell {
            buildInputs =
              [
                # Rust dependencies
                (rust-bin.stable.latest.default.override { extensions = [ "rust-src" ]; })
                pkg-config
              ]
              ++ lib.optionals (lib.strings.hasInfix "linux" system) [
                # for Linux
                # Audio (Linux only)
                alsa-lib
                # Cross Platform 3D Graphics API
                vulkan-loader
                # For debugging around vulkan
                vulkan-tools
                # Other dependencies
                libudev-zero
                xorg.libX11
                xorg.libXcursor
                xorg.libXi
                xorg.libXrandr
                libxkbcommon
              ];
            RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
            LD_LIBRARY_PATH = lib.makeLibraryPath [
              vulkan-loader
              xorg.libX11
              xorg.libXi
              xorg.libXcursor
              libxkbcommon
            ];
          };
      }
    );
}

I did the following:

git clone git@github.com:bevyengine/bevy.git
cd bevy
# create flake.nix with above contents
vim flake.nix 
git add flake.nix
nix develop
cargo run --example bloom_2d
(attachments)

Additionally, I would look into adding naersk [1] or crane [2] so you can avoid having to compile the entire project from source.

[1] GitHub - nix-community/naersk: Build Rust projects in Nix - no configuration, no code generation, no IFD, sandbox friendly.
[2] GitHub - ipetkov/crane: A Nix library for building cargo projects. Never build twice thanks to incremental artifact caching.

Thank you very much for your answers! Truly, if only I had looked for “nix” in the repo… I’ll be sure to look it up how to use the alternatives ‘naersk’ and ‘crane’ if the build times get long enough