From f4201e95baeaf14af93be15bca435515608f539e Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 24 Jan 2026 18:48:14 -0700 Subject: [PATCH] feat: add nix flake with fenix rust toolchain Configure hermetic development environment: - fenix toolchain from rust-toolchain.toml - clangStdenv for Tree-sitter C grammar compilation - Multi-platform devShells (x86_64/aarch64, linux/darwin) - Generated flake.lock with pinned inputs --- .envrc | 1 + .gitignore | 1 + flake.lock | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 52 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 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..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index c995cfc..8e3f1b2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ target # Local Netlify folder .netlify +.direnv target/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1e2be3c --- /dev/null +++ b/flake.lock @@ -0,0 +1,66 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1769237067, + "narHash": "sha256-o2UfbFRcL/UClXaDI8NR3WAulOoda55rdw0oVXAst0A=", + "owner": "nix-community", + "repo": "fenix", + "rev": "93523fa073f781d3d02d326cdbb85f8709b00c40", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1769268028, + "narHash": "sha256-mAdJpV0e5IGZjnE4f/8uf0E4hQR7ptRP00gnZKUOdMo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ab9fbbcf4858bd6d40ba2bbec37ceb4ab6e1f562", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1769166439, + "narHash": "sha256-HjSoNRYe8tPdzfhJ0IBQrrJATOrtVKOHvk8OoTew1Do=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "39018acf3477a26f4e6d2ead6a48954d623adcaa", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f898ce5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,52 @@ +{ + description = "nrd.sh - bespoke static site compiler"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + self, + nixpkgs, + fenix, + }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn system); + in + { + devShells = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + fenixPkgs = fenix.packages.${system}; + toolchain = fenixPkgs.fromToolchainFile { file = ./rust-toolchain.toml; sha256 = "sha256-vra6TkHITpwRyA5oBKAHSX0Mi6CBDNQD+ryPSpxFsfg=";}; + in + { + default = pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } { + RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + packages = + [ + toolchain + fenixPkgs.default.rustfmt + pkgs.pkg-config + ] + ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + pkgs.apple-sdk + pkgs.libiconv + ]; + }; + } + ); + }; +}