From 3fc5d611f53d24973ce38459ab10e5d2e75b88ef Mon Sep 17 00:00:00 2001 From: MiguVT Date: Mon, 30 Nov 2026 19:15:58 +0100 Subject: [PATCH] nix: dev shell for building the Windows executable on NixOS --- .envrc | 1 + .github/workflows/ci.yml | 19 ++++++++++++++++ .gitignore | 4 ++++ README.md | 3 +++ docs/linux.md | 33 +++++++++++++++++++++++++-- flake.lock | 48 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 47 +++++++++++++++++++++++++++++++++++++++ xtask/src/policy.rs | 3 +++ 8 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1a4466..d5e4313 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,25 @@ jobs: - name: Tests run: cargo test --workspace --locked + # The flake's dev shell and the portable crates through it: keeps the NixOS + # instructions honest and catches a stale flake.lock. + nix: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v5 + - uses: cachix/install-nix-action@v32 + with: + extra_nix_config: | + experimental-features = nix-command flakes + extra-substituters = https://nix-community.cachix.org + extra-trusted-public-keys = nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= + - name: Dev shell and platform-independent tests + run: >- + nix develop --command cargo test --locked + -p victory-core -p victory-formats -p victory-pipeline + -p victory-shader -p victory-game -p xtask + # The crates that do not need Windows or D3D12, tested on Linux: a quicker # signal, and a check that they stay portable. victory-pe is left out # because its tests parse their own test executable as a PE image. diff --git a/.gitignore b/.gitignore index f6fd208..a4c552b 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,10 @@ validate_*.txt *.swp Thumbs.db .DS_Store +.direnv/ +# `nix build` / `nix develop` result symlinks +/result +/result-* # Play-session logs written by the Play-VIctory*.cmd launchers /logs/ diff --git a/README.md b/README.md index 7039cf1..5afc7e3 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,9 @@ cd cool_fox cargo build --release --locked -p victory ``` +On Linux (including NixOS), victory is cross-built with `cargo xwin` and run under +Proton or Wine; see [docs/linux.md](docs/linux.md). + On **Windows 10**, build with the D3D12 Agility SDK instead. Windows 10's own D3D12 has no shader model 6.6 bindless heaps, and root signatures then fail with `0x80070057`: diff --git a/docs/linux.md b/docs/linux.md index 0c4d695..d9b3526 100644 --- a/docs/linux.md +++ b/docs/linux.md @@ -52,14 +52,17 @@ What it took, in the order it was found (each in its own code comment): - **The NVIDIA driver from RPM Fusion** (`akmod-nvidia`), not nouveau. vkd3d-proton needs shader model 6.6 and mesh shaders, which it gets from the - proprietary driver's Vulkan. + proprietary driver's Vulkan. On NixOS use `hardware.nvidia` (with + `nixpkgs.config.allowUnfree`) instead. - **umu-launcher**, to run Windows programs under Proton outside Steam. It is not in Fedora's own repositories: take it from its GitHub releases. With `PROTONPATH=GE-Proton` (the script's default) it downloads GE-Proton itself. For Steam's Proton instead, see step 4. - **Your own complete dump of the title**, outside this checkout. -## 2. Build victory.exe on Fedora +## 2. Build victory.exe + +### Fedora ```sh sudo dnf install clang llvm # clang-cl and llvm-lib for C parts of dependencies @@ -78,6 +81,32 @@ For the diagnostics build (log lines, F3 panel, frame recording): `cargo xwin build --locked --profile diag -p victory --features diagnostics --target x86_64-pc-windows-msvc`, then point `VICTORY_EXE` at `target/x86_64-pc-windows-msvc/diag/victory.exe`. +### NixOS + +The repository ships a flake with the pinned toolchain, `cargo-xwin`, clang and +LLVM/lld: + +```sh +nix develop # or: direnv allow +cargo xwin build --release --locked -p victory --target x86_64-pc-windows-msvc +``` + +The flake reads `rust-toolchain.toml`, so the channel, components and +`x86_64-pc-windows-msvc` target match the other platforms. `cargo-xwin` downloads +the Windows SDK and CRT into `~/.cache/cargo-xwin` on first use (they come under +Microsoft's license); the shell's own packages are pure Nix. + +The platform-independent crates test natively: + +```sh +cargo test --locked -p victory-core -p victory-formats -p victory-pipeline \ + -p victory-shader -p victory-game -p xtask +``` + +To run the executable, take `umu-launcher` from nixpkgs (`nix shell +nixpkgs#umu-launcher`, or add it to `environment.systemPackages`) and use +`scripts/play-proton.sh` as below. + ## 3. Start it ```sh diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3e44e00 --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1795911899, + "narHash": "sha256-OKvZpNQnLc24N/vuklyiHDYmFT4ZQRb5b3Rovh1/Hkg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e713fda5ec9fad59317d86214b1ee646a11896ea", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1796037704, + "narHash": "sha256-RPXxaeH+QYru3gHcECgrhECLiFpFBjnzrg+/bXbpNQQ=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "b444040d9bdb292abbd223922d24d57f7ee8b7cd", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c3f1684 --- /dev/null +++ b/flake.nix @@ -0,0 +1,47 @@ +{ + description = "VIctory — build the Windows executable on NixOS"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + nixpkgs, + rust-overlay, + ... + }: + let + # The only supported development platform: the toolchain in + # rust-toolchain.toml cross-builds x86_64-pc-windows-msvc. + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + in + { + devShells.${system}.default = pkgs.mkShellNoCC { + packages = with pkgs; [ + # Same channel, components and windows target as rustup would use. + (rust-bin.fromRustupToolchainFile ./rust-toolchain.toml) + # The Fedora instructions in docs/linux.md, in one shell: + # cargo-xwin fetches the Windows SDK/CRT into ~/.cache/cargo-xwin. + cargo-xwin + clang + llvm + lld + git + ]; + + shellHook = '' + echo "VIctory: cargo xwin build --release --locked -p victory --target x86_64-pc-windows-msvc" + echo "Tests: cargo test --locked -p victory-core -p victory-formats -p victory-pipeline -p victory-shader -p victory-game -p xtask" + ''; + }; + }; +} diff --git a/xtask/src/policy.rs b/xtask/src/policy.rs index 2bde833..92a1d49 100644 --- a/xtask/src/policy.rs +++ b/xtask/src/policy.rs @@ -16,6 +16,8 @@ const MAX_ENCODED_RUN: usize = 512; const ALLOWED_EXTENSIONS: &[&str] = &[ "rs", "toml", "md", "txt", "lock", "yml", "yaml", "json", "hlsl", "hlsli", "ps1", "cmd", "sh", + // NixOS development shell (flake.nix). + "nix", // Source patches for host tools (patches/), held to the same size and // encoded-run checks as the rest. "patch", "diff", @@ -24,6 +26,7 @@ const ALLOWED_NAMES: &[&str] = &[ ".gitignore", ".gitattributes", ".editorconfig", + ".envrc", ".victory-root", "pre-commit", "LICENSE",