diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..51170946 --- /dev/null +++ b/flake.lock @@ -0,0 +1,65 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1759070547, + "narHash": "sha256-JVZl8NaVRYb0+381nl7LvPE+A774/dRpif01FKLrYFQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "647e5c14cbd5067f44ac86b74f014962df460840", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", + "systems": "systems" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1759199574, + "narHash": "sha256-w24RYly3VSVKp98rVfCI1nFYfQ0VoWmShtKPCbXgK6A=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "381776b12d0d125edd7c1930c2041a1471e586c0", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "flake": false, + "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..2a264d62 --- /dev/null +++ b/flake.nix @@ -0,0 +1,35 @@ +{ + description = "Noita Entangled Worlds"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + systems = { + url = "github:nix-systems/default"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, rust-overlay, systems, }: + let + inherit (nixpkgs) lib; + eachSystem = lib.genAttrs (import systems); + pkgsFor = eachSystem (system: + import nixpkgs { + localSystem = system; + overlays = [ self.overlays.default ]; + }); + in { + overlays = import ./nix/overlays { inherit self lib rust-overlay; }; + + devShells = lib.mapAttrs + (system: pkgs: { default = pkgs.callPackage ./nix/shell.nix { }; }) + pkgsFor; + + formatter = + eachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-classic); + }; +} diff --git a/nix/overlays/default.nix b/nix/overlays/default.nix new file mode 100644 index 00000000..43d90f12 --- /dev/null +++ b/nix/overlays/default.nix @@ -0,0 +1,14 @@ +{ self, lib, rust-overlay }: { + default = lib.composeManyExtensions [ + # This is to ensure that other overlays and invocations of `callPackage` + # receive `rust-bin`, but without hard-coding a specific derivation. + # This can be overridden by consumers. + self.overlays.rust-overlay + ]; + + # This flake exposes `overlays.rust-overlay` which is automatically applied + # by `overlays.default`. This overlay is intended to provide `rust-bin` for + # the package overlay, in the event it is not already present. + rust-overlay = final: prev: + if prev ? rust-bin then { } else rust-overlay.overlays.default final prev; +} diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 00000000..fba4ed2f --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,18 @@ +{ rust-bin, mkShell }: +mkShell { + strictDeps = true; + + packages = [ + # Derivations in `rust-stable` provide the toolchain, + # must be listed first to take precedence over nightly. + (rust-bin.stable.latest.minimal.override { + extensions = [ "rust-src" "rust-docs" "clippy" ]; + }) + + # Use rustfmt, and other tools that require nightly features. + (rust-bin.selectLatestNightlyWith (toolchain: + toolchain.minimal.override { + extensions = [ "rustfmt" "rust-analyzer" ]; + })) + ]; +}