From 3907fe605302e481509b6fd2d0ec09b0229398ec Mon Sep 17 00:00:00 2001 From: of-the-stars Date: Mon, 3 Nov 2025 02:56:05 -0600 Subject: [PATCH 1/2] Created an automatic, reproducible development environment - Created an automatic development environment via a nix flake - Supports both `nix develop` and `direnv allow` - Added `rust-toolchain.toml` to specify what version of the rust language to use --- .envrc | 1 + .gitignore | 1 + flake.lock | 158 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 64 ++++++++++++++++++ rust-toolchain.toml | 3 + 5 files changed, 227 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..3550a30f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index ea8c4bf7..0e71e344 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.direnv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..e960033b --- /dev/null +++ b/flake.lock @@ -0,0 +1,158 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "naersk", + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1752475459, + "narHash": "sha256-z6QEu4ZFuHiqdOPbYss4/Q8B0BFhacR8ts6jO/F/aOU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "bf0d6f70f4c9a9cf8845f992105652173f4b617f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "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" + } + }, + "naersk": { + "inputs": { + "fenix": "fenix", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1752689277, + "narHash": "sha256-uldUBFkZe/E7qbvxa3mH1ItrWZyT6w1dBKJQF/3ZSsc=", + "owner": "nix-community", + "repo": "naersk", + "rev": "0e72363d0938b0208d6c646d10649164c43f4d64", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1752077645, + "narHash": "sha256-HM791ZQtXV93xtCY+ZxG1REzhQenSQO020cu6rHtAPk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "be9e214982e20b8310878ac2baa063a961c1bdf6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1761907660, + "narHash": "sha256-kJ8lIZsiPOmbkJypG+B5sReDXSD1KGu2VEPNqhRa/ew=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2fb006b87f04c4d3bdf08cfdbc7fab9c13d94a15", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1752428706, + "narHash": "sha256-EJcdxw3aXfP8Ex1Nm3s0awyH9egQvB2Gu+QEnJn2Sfg=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "591e3b7624be97e4443ea7b5542c191311aa141d", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1762137611, + "narHash": "sha256-sTqb10FR/YQCuGbw16qxliX0NFlYg6evSEjN8w+9IYE=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "3a0ebe5d2965692f990cb27e62f501ad35e3deeb", + "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..c4885d6f --- /dev/null +++ b/flake.nix @@ -0,0 +1,64 @@ +{ + description = "nmrs development flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + naersk.url = "github:nix-community/naersk/master"; + flake-utils.url = "github:numtide/flake-utils"; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + naersk, + rust-overlay, + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + naersk-lib = pkgs.callPackage naersk {}; + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + + naersk' = pkgs.callPackage naersk { + cargo = toolchain; + rustc = toolchain; + clippy = toolchain; + }; + in { + devShell = with pkgs; + mkShell { + buildInputs = [ + cargo + cargo-info + rustc + rustfmt + clippy + rust-analyzer + just + + eza + fd + fzf + bat + ]; + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + + shellHook = '' + alias ls=eza + alias find=fd + ''; + }; + + packages.default = naersk-lib.buildPackage ./.; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..02cb8fcb --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "stable" +profile = "default" From 0e9216394b9b7b72e83c813b2119233b4bef18d8 Mon Sep 17 00:00:00 2001 From: of-the-stars Date: Mon, 3 Nov 2025 10:59:18 -0600 Subject: [PATCH 2/2] Removed unused package call with the custom toolchain As @cachebag pointed out, I was defining the method call with a custom toolchain attribute set but didn't use it when calling the `buildPackage` function. Removed the `naersk-lib` definition, and renamed `naersk'` to `naersk-package` for a clearer name and used it to build the package later. Whether or not this actually builds the package as needed requires more understanding on my part, but it should build a binary just fine for all targets that `nix` can run on. --- flake.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index c4885d6f..b67f351f 100644 --- a/flake.nix +++ b/flake.nix @@ -25,10 +25,9 @@ inherit system; overlays = [(import rust-overlay)]; }; - naersk-lib = pkgs.callPackage naersk {}; toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - naersk' = pkgs.callPackage naersk { + naersk-package = pkgs.callPackage naersk { cargo = toolchain; rustc = toolchain; clippy = toolchain; @@ -58,7 +57,7 @@ ''; }; - packages.default = naersk-lib.buildPackage ./.; + packages.default = naersk-package.buildPackage ./.; } ); }