From a72ac37698ffc3d0a5aa63deb81f4223a09f1bc7 Mon Sep 17 00:00:00 2001 From: Tomasz Zurkowski Date: Wed, 8 Jan 2025 20:48:19 +0100 Subject: [PATCH] Add rust-toolchain and nix flake (#20) rust-toolchain will allow us to ensure that everyone developing on the repository is using the same version of rust. Nix flake will provide out-of-the-box development environment for nix users with the right rust version. --- .gitignore | 7 ++++ flake.lock | 82 +++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 60 +++++++++++++++++++++++++++++++++ rust-toolchain.toml | 1 + 4 files changed, 150 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 39ee975..e77cc4e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,10 @@ .vscode/* .DS_Store + +# Allow everyone to customize .envrc +/.envrc +# Output / cache from direnv +/.direnv +# Output from nix +/result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..80ebcfb --- /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": 1736166416, + "narHash": "sha256-U47xeACNBpkSO6IcCm0XvahsVXpJXzjPIQG7TZlOToU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b30f97d8c32d804d2d832ee837d0f1ca0695faa5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1736216977, + "narHash": "sha256-EMueGrzBpryM8mgOyoyJ7DdNRRk09ug1ggcLLp0WrCQ=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "bbe7e4e7a70d235db4bbdcabbf8a2f6671881dd7", + "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 0000000..fea17fc --- /dev/null +++ b/flake.nix @@ -0,0 +1,60 @@ +{ + # This is a Nix Flake that defines development environment for this project. + # + # Using Nix is NOT required to develop this project. + # + # Nix provides a declariative way to define reproducible development environment + # and aims to remove the issue of "works on my machine". + # + # If you use Nix, you can install and activate all dependencies required to + # develop on this project with: + # + # $ nix develop + # + # If in addition you have `direnv` installed, you can create `.envrc` file with + # `use flake` content, so that development environment activates automatically + # when the project root directory is entered. + # + # More information: + # - Nix: https://nixos.org + # - Nix flakes: https://wiki.nixos.org/wiki/Flakes + # - Direnv: https://direnv.net + description = "The New Nushell Parser"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + nixpkgs, + rust-overlay, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + in + { + devShells.default = pkgs.mkShell { + nativeBuildInputs = [ + (rustToolchain.override { + extensions = [ + "rust-src" + "rust-analyzer" + ]; + }) + ]; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml index aa2b18f..e2fad99 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -3,4 +3,5 @@ # The default profile includes rustc, rust-std, cargo, rust-docs, rustfmt and clippy. # https://rust-lang.github.io/rustup/concepts/profiles.html profile = "default" +# When updating, it might be necessary to run `nix flake update`. channel = "1.81.0"