-
Notifications
You must be signed in to change notification settings - Fork 31
barebones flake.nix #532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
barebones flake.nix #532
Conversation
|
Hi, thanks for the PR! I'm not comfortable reviewing this PR yet, as I still am too unfamiliar with Nix (and none of the other maintainers use it I believe). At some point I do want to support this, but I don't want to merge it without understanding the technology behind it. In the meantime, feel free to use your fork as an unofficial Nix Flake! You may also be interested in #390, which tried to do this same thing in the past. I no longer agree with what I said in #390 (comment), and now believe that Nix Flakes are the way to go, but it may be a while before we can merge this. Sorry! |
|
@BD103 I understand, thanks for the response. Would you consider pulling in these changes on a feature branch, as opposed to main? That way others might benefit from the flake while main is kept intact, until you are comfortable with the feature and opt to merge it in. Or, if you ultimately decide against it, just drop the branch altogether. I would also be interested in making this a nixpkgs package in addition to the flake. I have some prior experience with that and would be happy to add that as another way for those who are anti-flake to still use the CLI in a declarative manner. |
I gave this some thought, but I don't think I'm comfortable doing this yet. Anything on the main repository has some level of "officialness", even if it's on a separate branch. I don't want to give code that I don't understand any sort of (arguably small) endorsement like that. Given, I'm just one maintainer. If one of the others tests and approves this PR, then I have no complaints! I don't have anything against NixOS, it's just not at the top of my todo list yet :) |
|
I also have no nix experience unfortunately, but it seems that there is enough interest in this to warrant pulling this in. I'd also like instructions on how to use this in the README, along with a warning that this is supported on a best-effort basis and might break at any time :) |
|
I would love an addition to |
|
@TimJentzsch Absolutely, I'll get in touch with some folks in the Discord. |
|
I just cherry-picked this to my local fork so that I could test a change, so this both works, and is valuable for contributors using Nix. The benefit of being able to use it as a direct flake input until it's accepted in nixpkgs is also valuable, as that PR has gone stale. As long as there aren't test that are affected by it there should be no way this can affect other users, and since nix projects depending on the repo will use a specific sha there's no issue if it does go out of date. I therefore propose we merge this. I only had one issue when using it, and I've added a comment for that |
|
I'm open to merge this after resolving the outstanding issues.
I like the disclaimer (and a good description of what the flake provides, you mentioned it does not support the linter as of now), but I wonder if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, could you also add the required user documentation with the disclaimer (what @TimJentzsch ) mentioned.
There was a problem hiding this comment.
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:
- Nightly toolchain
bevy_lintrequires the nightly compiler, so we need to pull in a community-maintained overlay sincenixpkgsdoesn't provide one. Therust-toolchain.tomlfrom the repo is used here, so we'll never go out-of-sync. See the official manual for details. - Sysroot location
We can't expectrustupto be available on NixOS systems, so we need to pointBEVY_LINT_SYSROOTto the same nightly toolchain used to build the linter. cargoBuildFlags = [ "--all" ];
This just builds all the packages in the workspace so that we get bothbevyandbevy_lint. Is it worth it to be more specific?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. :)
| ]; | ||
| in | ||
| { | ||
| packages.default = pkgs.rustPlatform.buildRustPackage { |
There was a problem hiding this comment.
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 = ...;
}|
I'm marking this as blessed! It was originally controversial, but I think this is the direction we want to take in regard to the Nix ecosystem. |
Absolutely, just returned from travel. I will work on it this weekend! |
I'm definitely not the best with Nix and am especially new to writing flakes of my own, but I gave a shot at writing one for the Bevy CLI as I use NixOS as a daily driver. I was able to get my Bevy app running in my browser by adding the following to the Nix flake in Bevy's docs:
{ 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"; + bevy_cli.url = "github:TheBevyFlock/bevy_cli"; }; outputs = { nixpkgs, rust-overlay, flake-utils, + bevy_cli, ... }: 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" ]; }) + ( + rust-bin.stable.latest.default.override { + extensions = [ "rust-src" ]; + targets = [ "wasm32-unknown-unknown" ]; + } + ) 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 + wasm-bindgen-cli ]; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; LD_LIBRARY_PATH = lib.makeLibraryPath [ vulkan-loader xorg.libX11 xorg.libXi xorg.libXcursor libxkbcommon ]; }; } ); }I wasn't able to get the linter to work. I'm not quite sure how to deal with it in a declarative way since it requires
rustupat runtime. Was hoping someone more experienced with Nix might be able to provide a solution here. Regardless I think this flake should be a good starting point.