Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions flake.nix
Copy link

@musjj musjj Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I've tested out your PR and you just need to make a few changes to make bevy lint work:

diff --git a/tmp/.psub.oO4pntvWFW b/flake.nix
index 980c6ba..cadee16 100644
--- a/tmp/.psub.oO4pntvWFW
+++ b/flake.nix
@@ -4,13 +4,17 @@
   inputs = {
     flake-utils.url = "github:numtide/flake-utils";
     nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+    rust-overlay = {
+      url = "github:oxalica/rust-overlay";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
   };
 
-  outputs = { self, flake-utils, nixpkgs }:
+  outputs = { self, flake-utils, nixpkgs, rust-overlay }:
     flake-utils.lib.eachDefaultSystem (
       system:
       let
-        pkgs = nixpkgs.legacyPackages.${system};
+        pkgs = nixpkgs.legacyPackages.${system}.extend rust-overlay.overlays.default;
 
         nativeBuildInputs = with pkgs; [
           pkg-config
@@ -19,17 +23,34 @@
         buildInputs = with pkgs; [
           openssl
         ];
+
+        toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
+
+        rustPlatform = pkgs.makeRustPlatform {
+          cargo = toolchain;
+          rustc = toolchain;
+        };
       in
       {
-        packages.default = pkgs.rustPlatform.buildRustPackage {
+        packages.default = rustPlatform.buildRustPackage {
           pname = "bevy";
           version = "0.1.0-dev";
           src = ./.;
-          cargoLock = {
-            lockFile = ./Cargo.lock;
-          };
+          cargoLock.lockFile = ./Cargo.lock;
+          cargoBuildFlags = [ "--all" ];
           doCheck = false;
+
+          nativeBuildInputs = nativeBuildInputs ++ (with pkgs; [ makeBinaryWrapper ]);
-          inherit buildInputs nativeBuildInputs;
+          inherit buildInputs;
+
+          postInstall = ''
+            for bin in $out/bin/bevy{,_lint}; do
+              wrapProgram $bin --set BEVY_LINT_SYSROOT ${toolchain}
+            done
+          '';
         };
 
         devShells.default = pkgs.mkShell {

A few important points:

  1. Nightly toolchain
    bevy_lint requires the nightly compiler, so we need to pull in a community-maintained overlay since nixpkgs doesn't provide one. The rust-toolchain.toml from the repo is used here, so we'll never go out-of-sync. See the official manual for details.
  2. Sysroot location
    We can't expect rustup to be available on NixOS systems, so we need to point BEVY_LINT_SYSROOT to the same nightly toolchain used to build the linter.
  3. cargoBuildFlags = [ "--all" ];
    This just builds all the packages in the workspace so that we get both bevy and bevy_lint. Is it worth it to be more specific?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setting BEVY_LINT_SYSROOT for the bevy cli (not the bevy_lint cli) do anything, or should it be set for only bevy_cli?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setting BEVY_LINT_SYSROOT for the bevy cli (not the bevy_lint cli) do anything, or should it be set for only bevy_cli?

The Bevy CLI doesn't read BEVY_LINT_SYSROOT, but if you run the linter through the CLI (such as with bevy lint web, for example), you'll still want BEVY_LINT_SYSROOT to be set. Check out the docs on environmental variables for more details. :)

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
description = "A Bevy CLI tool and linter";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};

outputs = { self, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};

nativeBuildInputs = with pkgs; [
pkg-config
];

buildInputs = with pkgs; [
openssl
# rustup
];
in
{
packages.default = pkgs.rustPlatform.buildRustPackage {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, but packages are usually structured something like this:

packages = {
  default = self.outputs.packages.${system}.bevy;
  bevy = ...;
}

pname = "bevy_cli";
version = "0.1.0-dev";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
doCheck = false;
inherit buildInputs nativeBuildInputs;
};

devShells.default = pkgs.mkShell {
inherit buildInputs nativeBuildInputs;
};
}
);
}