flake: init with Rust devShell

This commit is contained in:
Jacob Birkett 2025-09-30 12:46:50 -07:00 committed by IQuant
parent b336f34fd0
commit 876d3da91e
4 changed files with 132 additions and 0 deletions

65
flake.lock generated Normal file
View file

@ -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
}

35
flake.nix Normal file
View file

@ -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);
};
}

14
nix/overlays/default.nix Normal file
View file

@ -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;
}

18
nix/shell.nix Normal file
View file

@ -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" ];
}))
];
}