From 9b3872245178f3944eed33887fa651ba7a600af2 Mon Sep 17 00:00:00 2001 From: traxys Date: Mon, 31 Oct 2022 16:35:31 +0100 Subject: [PATCH] Add rust template in flake --- flake.nix | 6 ++++++ templates/rust/.envrc | 4 ++++ templates/rust/.gitignore | 1 + templates/rust/Cargo.toml | 7 +++++++ templates/rust/flake.nix | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 templates/rust/.envrc create mode 100644 templates/rust/.gitignore create mode 100644 templates/rust/Cargo.toml create mode 100644 templates/rust/flake.nix diff --git a/flake.nix b/flake.nix index bea8e07..e580ed6 100644 --- a/flake.nix +++ b/flake.nix @@ -40,6 +40,12 @@ nixpkgs, ... } @ inputs: { + templates = { + rust = { + path = ./templates/rust; + description = "My rust template using rust-overlay and direnv"; + }; + }; nixosConfigurations = { ZeNixLaptop = nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; diff --git a/templates/rust/.envrc b/templates/rust/.envrc new file mode 100644 index 0000000..5e9005b --- /dev/null +++ b/templates/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/templates/rust/.gitignore b/templates/rust/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/templates/rust/.gitignore @@ -0,0 +1 @@ +/target diff --git a/templates/rust/Cargo.toml b/templates/rust/Cargo.toml new file mode 100644 index 0000000..6f9b15c --- /dev/null +++ b/templates/rust/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "todo_change_name" +version = "0.1.0" +authors = ["traxys "] +edition = "2021" + +[dependencies] diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix new file mode 100644 index 0000000..8cc514e --- /dev/null +++ b/templates/rust/flake.nix @@ -0,0 +1,36 @@ +{ + description = "A basic flake with a shell"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.naersk.url = "github:nix-community/naersk"; + inputs.rust-overlay.url = "github:oxalica/rust-overlay"; + + outputs = { + self, + nixpkgs, + flake-utils, + naersk, + rust-overlay, + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + rust = pkgs.rust-bin.stable.latest.default; + naersk' = pkgs.callPackage naersk { + cargo = rust; + rustc = rust; + }; + in { + devShell = pkgs.mkShell { + nativeBuildInputs = [rust]; + RUST_PATH = "${rust}"; + shellHook = '' + alias rstddoc="firefox ${rust}/share/doc/rust/html/std/index.html" + ''; + }; + + defaultPackage = nearsk'.buildPackage ./.; + }); +}