From 701e9ff7724dbf99362faf8c9dba35038bd24a99 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 16 Jul 2022 16:48:23 +0200 Subject: [PATCH] Add direnv support --- README.md | 3 ++ flake.nix | 6 +-- go1.17/flake.nix | 7 ++- go1.18/flake.nix | 7 ++- rust/.envrc | 4 ++ rust/.gitignore | 2 + rust/Cargo.lock | 7 +++ rust/Cargo.toml | 8 ++++ rust/flake.lock | 93 ++++++++++++++++++++++++++++++++++++++++ rust/flake.nix | 48 +++++++++++++++++++++ rust/rust-toolchain.toml | 2 + rust/src/main.rs | 3 ++ 12 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 rust/.envrc create mode 100644 rust/.gitignore create mode 100644 rust/Cargo.lock create mode 100644 rust/Cargo.toml create mode 100644 rust/flake.lock create mode 100644 rust/flake.nix create mode 100644 rust/rust-toolchain.toml create mode 100644 rust/src/main.rs diff --git a/README.md b/README.md index e9ed1c3..6d96805 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,7 @@ nix flake init --template github:the-nix-way/dev-templates#go_1_17 # Go 1.18 nix flake init --template github:the-nix-way/dev-templates#go_1_18 + +# Rust +nix flake init --template github:the-nix-way/dev-templates#rust ``` diff --git a/flake.nix b/flake.nix index cc27375..522b2cd 100644 --- a/flake.nix +++ b/flake.nix @@ -13,9 +13,9 @@ description = "Go 1.18 development environment"; }; - rails = { - path = ./ruby-on-rails; - description = "Ruby on Rails development environment"; + rust = { + path = ./rust; + description = "Rust development environment"; }; }; }; diff --git a/go1.17/flake.nix b/go1.17/flake.nix index 770e04c..a71786b 100644 --- a/go1.17/flake.nix +++ b/go1.17/flake.nix @@ -32,8 +32,13 @@ # https://github.com/uudashr/gopkgs gopkgs ]; + + shellHook = '' + echo "Entering Go env" + echo "Running `${pkgs.go}/bin/go version`" + ''; }; }; } ); -} \ No newline at end of file +} diff --git a/go1.18/flake.nix b/go1.18/flake.nix index da7f1c3..91f572c 100644 --- a/go1.18/flake.nix +++ b/go1.18/flake.nix @@ -32,8 +32,13 @@ # https://github.com/uudashr/gopkgs gopkgs ]; + + shellHook = '' + echo "Entering Go env" + echo "Running `${pkgs.go}/bin/go version`" + ''; }; }; } ); -} \ No newline at end of file +} diff --git a/rust/.envrc b/rust/.envrc new file mode 100644 index 0000000..03c6004 --- /dev/null +++ b/rust/.envrc @@ -0,0 +1,4 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.1.1; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.1.1/direnvrc" "sha256-b6qJ4r34rbE23yWjMqbmu3ia2z4b2wIlZUksBke/ol0=" +fi +use flake . diff --git a/rust/.gitignore b/rust/.gitignore new file mode 100644 index 0000000..bd32e74 --- /dev/null +++ b/rust/.gitignore @@ -0,0 +1,2 @@ +.direnv +target diff --git a/rust/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 0000000..b21cc6a --- /dev/null +++ b/rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rust" +version = "0.1.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..1ec6963 --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/rust/flake.lock b/rust/flake.lock new file mode 100644 index 0000000..d213f05 --- /dev/null +++ b/rust/flake.lock @@ -0,0 +1,93 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1656928814, + "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1656065134, + "narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1657577542, + "narHash": "sha256-tJnYrGTswnCtz8hXR24y4sZ7d+kgZ7UshnFBcrDjFkU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0a1978fbe48b8bd08be138507e9dade26e5778b8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1656401090, + "narHash": "sha256-bUS2nfQsvTQW2z8SK7oEFSElbmoBahOPtbXPm0AL3I4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "16de63fcc54e88b9a106a603038dd5dd2feb21eb", + "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": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1657507721, + "narHash": "sha256-FtV5D35ikz7zvhBX66Bs3VKd/GDyIVA+WQzqkR1PS0E=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1a133f54a0229af8310879eac2c4a82c0576a0b9", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/rust/flake.nix b/rust/flake.nix new file mode 100644 index 0000000..d87baa3 --- /dev/null +++ b/rust/flake.nix @@ -0,0 +1,48 @@ +{ + description = "A Nix-flake-based Rust development environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ + (import rust-overlay) + ]; + + pkgs = import nixpkgs { + inherit system overlays; + }; + + rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + + inherit (pkgs.lib) optionals; + inherit (pkgs.stdenv) isDarwin; + in { + packages.default = rust; + + devShells = { + default = pkgs.mkShell { + nativeBuildInputs = [ + rust + pkgs.pkg-config + ]; + + buildInputs = with pkgs; [ + openssl + pkgconfig + ]; + + shellHook = '' + echo "Entering Rust env" + echo "Running `${rust}/bin/cargo --version`" + ''; + }; + }; + } + ); +} diff --git a/rust/rust-toolchain.toml b/rust/rust-toolchain.toml new file mode 100644 index 0000000..ead0271 --- /dev/null +++ b/rust/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.61.0" diff --git a/rust/src/main.rs b/rust/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/rust/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}