diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000000..3550a30f2de38 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index ca337b93971e6..9cdad4a8aae56 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,9 @@ compressed_texture_cache # Generated by "examples/dev_tools/schedule_data.rs" **/app_data.ron + +# Generated by direnv +.direnv + +# Generated by Visual Studio Code +.vscode \ No newline at end of file diff --git a/docs/linux_dependencies.md b/docs/linux_dependencies.md index 65b3fd21122da..b8d96df68d8be 100644 --- a/docs/linux_dependencies.md +++ b/docs/linux_dependencies.md @@ -104,73 +104,14 @@ sudo xbps-install -S pkgconf alsa-lib-devel libX11-devel eudev-libudev-devel ### flake.nix -Add a `flake.nix` file to the root of your GitHub repository containing: +There is a `flake.nix` file to the root of this repository. So you can just do -```nix -{ - 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 - libx11 - libxcursor - libxi - libxrandr - libxkbcommon - wayland - ]; - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; - LD_LIBRARY_PATH = lib.makeLibraryPath [ - vulkan-loader - libx11 - libxi - libxcursor - libxkbcommon - wayland - ]; - }; - } - ); -} +```bash +nix develop +``` +If you have `direnv` installed as well you just need to allow it for this repo. +```bash +direnv allow ``` > [!TIP] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000000..1c40eca72fe42 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1782959384, + "narHash": "sha256-xnJJk+ct+D2+wdRxj1wk36w5zV9RVESwRqcklPdt3fM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "65179426c83bb3f6bc14898b42ea1c6f01d374b0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1783144302, + "narHash": "sha256-NQnzmXwpEAd5tjMBh2+P/y9NknF+WHv5+6yoXoN4h/Y=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "fe5aee0952e8e1525533d61defd9e36513db811b", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000000..6b8ace8c1c1b6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,85 @@ +{ + description = "Bevy development environment 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, + flake-utils, + rust-overlay, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + + bevyDeps = + with pkgs; + [ + pkg-config + (rust-bin.stable.latest.default.override { + extensions = [ + "rust-src" + "rust-analyzer" + ]; + }) + ] + ++ lib.optionals stdenv.isLinux ( + with pkgs; + [ + # Systembundles & Linkers + lld + clang + + # Audio + alsa-lib + + # Graphics / Windowing + vulkan-loader + vulkan-tools + wayland + libx11 + libxcursor + libxi + libxrandr + libxkbcommon + + # Input / Hardware + libudev-zero + ] + ); + + # Runtime libs for dlopen + runtimeLibs = with pkgs; [ + vulkan-loader + alsa-lib + libx11 + libxcursor + libxi + libxrandr + libxkbcommon + wayland + libudev-zero + ]; + in + { + devShells.default = pkgs.mkShell { + nativeBuildInputs = bevyDeps; + + # Make Winit en Bevy find necessary libraries on Linux + LD_LIBRARY_PATH = pkgs.lib.optionalString pkgs.stdenv.isLinux ( + pkgs.lib.makeLibraryPath runtimeLibs + ); + }; + } + ); +}