Add direnv support

This commit is contained in:
Luc Perkins 2022-07-16 16:48:23 +02:00
parent cac35739be
commit 701e9ff772
No known key found for this signature in database
GPG key ID: 4F102D0C16E232F2
12 changed files with 185 additions and 5 deletions

View file

@ -6,4 +6,7 @@ nix flake init --template github:the-nix-way/dev-templates#go_1_17
# Go 1.18 # Go 1.18
nix flake init --template github:the-nix-way/dev-templates#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
``` ```

View file

@ -13,9 +13,9 @@
description = "Go 1.18 development environment"; description = "Go 1.18 development environment";
}; };
rails = { rust = {
path = ./ruby-on-rails; path = ./rust;
description = "Ruby on Rails development environment"; description = "Rust development environment";
}; };
}; };
}; };

View file

@ -32,6 +32,11 @@
# https://github.com/uudashr/gopkgs # https://github.com/uudashr/gopkgs
gopkgs gopkgs
]; ];
shellHook = ''
echo "Entering Go env"
echo "Running `${pkgs.go}/bin/go version`"
'';
}; };
}; };
} }

View file

@ -32,6 +32,11 @@
# https://github.com/uudashr/gopkgs # https://github.com/uudashr/gopkgs
gopkgs gopkgs
]; ];
shellHook = ''
echo "Entering Go env"
echo "Running `${pkgs.go}/bin/go version`"
'';
}; };
}; };
} }

4
rust/.envrc Normal file
View file

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

2
rust/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.direnv
target

7
rust/Cargo.lock generated Normal file
View file

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

8
rust/Cargo.toml Normal file
View file

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

93
rust/flake.lock Normal file
View file

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

48
rust/flake.nix Normal file
View file

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

2
rust/rust-toolchain.toml Normal file
View file

@ -0,0 +1,2 @@
[toolchain]
channel = "1.61.0"

3
rust/src/main.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}