diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..b9037467 --- /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": 1786599213, + "narHash": "sha256-yNJd40f11EzXBjSByCB7IPpeFFAdeoSKKM67dGkfFoU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0e251e24a4f24e036a084b6b4b2d2491af4167f4", + "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": 1786680812, + "narHash": "sha256-5lDFwethgqSULdupYl3Eu5n80jfcbb85gSJX/jb58GQ=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "f1dcc7e4ea4fdb6d8f276face22f353832b161e3", + "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 00000000..3336d6f3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,72 @@ +{ + description = "TrUAPI development environment"; + + 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.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + + stableToolchain = pkgs.rust-bin.stable.latest.default.override { + targets = [ "wasm32-unknown-unknown" ]; + }; + + nightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith + (toolchain: toolchain.default); + in + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + rustup + nodejs_22 + yarn + bun + wasm-pack + wasm-bindgen-cli + binaryen + git + pkg-config + cargo-deny + ]; + + shellHook = '' + rustup_home="''${RUSTUP_HOME:-''$HOME/.rustup}" + host_triple="$(${stableToolchain}/bin/rustc --print host-tuple)" + toolchains_dir="$rustup_home/toolchains" + mkdir -p "$toolchains_dir" + + # rustup >= 1.28 rejects channel-like names for `rustup toolchain + # link`, so link the pinned rust-overlay toolchains directly under + # the official channel directory names. `cargo +stable` and + # `cargo +nightly` then dispatch to the pinned store paths instead + # of a network download. + # + # Note: toolchains linked to read-only store paths cannot carry a + # dist manifest, so manifest-dependent introspection (`rustup + # show`, `rustup target list --toolchain `) errors with + # "Missing manifest in toolchain". Use `rustup toolchain list`, + # `rustup show active-toolchain`, and `rustc + --version` + # instead; compilation and `+` dispatch are unaffected. + for name in stable nightly; do + if [ "$name" = stable ]; then src="${stableToolchain}"; else src="${nightlyToolchain}"; fi + dir="$toolchains_dir/$name-$host_triple" + [ -L "$dir" ] || rm -rf -- "$dir" + ln -sfn "$src" "$dir" + done + + rustup default stable + ''; + }; + }); +}