From ffeb07222241e3f63fc1570b103cb2e8eb3aaf98 Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Fri, 20 May 2022 12:32:45 +0100 Subject: [PATCH] Add initial rust template --- flake.lock | 41 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 16 ++++++++++++++++ rust/.envrc | 1 + rust/flake.nix | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust/.envrc create mode 100644 rust/flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7239226 --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1652840887, + "narHash": "sha256-gEK4NNa4GwIgTZE63kt/4WTFAWRTJVSa30+h4ZjFh9U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "52dc75a4fee3fdbcb792cb6fba009876b912bfe0", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1652776076, + "narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..19d3e76 --- /dev/null +++ b/flake.nix @@ -0,0 +1,16 @@ +{ + description = "Samw's Nix flake templates"; + inputs = { utils.url = "github:numtide/flake-utils"; }; + + outputs = { self, utils, nixpkgs }: + { + templates = { + rust = { + path = ./rust; + description = "My preferred rust setup."; + }; + }; + } // utils.lib.eachDefaultSystem (system: + let pkgs = import nixpkgs { inherit system; }; + in { formatter = pkgs.nixfmt; }); +} diff --git a/rust/.envrc b/rust/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/rust/.envrc @@ -0,0 +1 @@ +use flake diff --git a/rust/flake.nix b/rust/flake.nix new file mode 100644 index 0000000..1da168c --- /dev/null +++ b/rust/flake.nix @@ -0,0 +1,36 @@ +{ + description = "Another cool rust disaster from samw."; + + inputs = { + utils.url = "github:numtide/flake-utils"; + devshell.url = "github:numtide/devshell"; + naersk.url = "github:nix-community/naersk"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, utils, naersk, devshell, rust-overlay }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + rust = rust-bin.stable.latest.default; + naersk-lib = naersk.lib.${system}.override { + cargo = rust; + rust = rust; + }; + in { + defaultPackage = naersk-lib.buildPackage ./.; + + defaultApp = utils.lib.mkApp { drv = self.defaultPackage."${system}"; }; + + # Provide a dev env with rust and rls + devShell = let + pkgs = import nixpkgs { + inherit system; + + overlays = [ devshell.overlay (import rust-overlay) ]; + }; + in pkgs.devshell.mkShell { + packages = with pkgs; [ (rust.override { extensions = [ "rls" ]; }) ]; + }; + }); +}