From 1b8c4df703f7563e206cffe912307f3bed1be300 Mon Sep 17 00:00:00 2001 From: Matthew Wilding Date: Thu, 8 Oct 2026 12:33:49 +0800 Subject: [PATCH] Add Nix flake and direnv Dev shell for x86_64-linux, aarch64-linux and aarch64-darwin. The toolchain comes from rust-toolchain.toml with rust-src and rust-analyzer, and .envrc loads the make-style .env. --- .envrc | 8 ++++++ .gitignore | 5 ++++ flake.lock | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 64 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) 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..19f4d00 --- /dev/null +++ b/.envrc @@ -0,0 +1,8 @@ +# .env is make syntax (unquoted values with spaces), so direnv's dotenv rejects it. +if [[ -f .env ]]; then + watch_file .env + while IFS='=' read -r key value; do + [[ $key =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] && export "$key=$value" + done < .env +fi +use flake diff --git a/.gitignore b/.gitignore index 7dc7854..b5983eb 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ iw4l.community.*.tmp # Agent working memory. None of it is the product: the artifacts, the externals, # the agent clones and the RE tooling and its bases all stay on this machine. /context/ + +# Nix / direnv +.direnv/ +result +result-* diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..075b766 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "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": 1791260994, + "narHash": "sha256-Miqqk/ammqnTUxaoCyvtwoPeLbI1ksFyLxi/CazZpWY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "151fa4e8ddfdd8dd25d945ad94ed54a13de9f6e4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1791361643, + "narHash": "sha256-HMdfSb1ONHs1RbSkQtCXm+tWEsTikisWWtXDnv0aQ+I=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "8afee9fa8caa877a4feb65adc33e8d72f3747dc9", + "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 0000000..2d331cd --- /dev/null +++ b/flake.nix @@ -0,0 +1,64 @@ +{ + description = "iw4L development shell"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + rust-overlay, + flake-utils, + }: + flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ] ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { + extensions = [ + "rust-src" + "rust-analyzer" + ]; + }; + runtimeLibs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux ( + with pkgs; + [ + alsa-lib + libxkbcommon + udev + vulkan-loader + wayland + libx11 + libxcursor + libxi + libxrandr + ] + ); + in + { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + toolchain + pkg-config + cmake + clang + git + ]; + buildInputs = runtimeLibs; + LD_LIBRARY_PATH = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ( + pkgs.lib.makeLibraryPath runtimeLibs + ); + }; + } + ); +}