From 2db5ad16cd807063cc03fc50fa8bf9accbbf2fd1 Mon Sep 17 00:00:00 2001 From: janabhumi Date: Tue, 6 Sep 2022 00:01:28 +0300 Subject: [PATCH] add rust-flake template --- flake.nix | 4 ++++ rust-flake/.envrc | 1 + rust-flake/flake.nix | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 rust-flake/.envrc create mode 100644 rust-flake/flake.nix diff --git a/flake.nix b/flake.nix index 3440ba5..668d493 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,10 @@ path = ./base-flake; description = "An empty flake for each default system"; }; + rust-flake = { + path = ./rust-flake; + description = "Flake to develop, build and run a rust application"; + }; }; defaultTemplate = self.templates.base-flake; }; diff --git a/rust-flake/.envrc b/rust-flake/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/rust-flake/.envrc @@ -0,0 +1 @@ +use flake diff --git a/rust-flake/flake.nix b/rust-flake/flake.nix new file mode 100644 index 0000000..7be1d0b --- /dev/null +++ b/rust-flake/flake.nix @@ -0,0 +1,31 @@ +{ + inputs = { + nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable; + utils.url = github:numtide/flake-utils; + }; + + outputs = { self, nixpkgs, utils }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + cargoToml = with builtins; (fromTOML (readFile ./dexios/Cargo.toml)); + in + { + packages.default = pkgs.rustPlatform.buildRustPackage { + inherit (cargoToml.package) name version; + src = nixpkgs.lib.cleanSource ./.; + doCheck = true; + cargoLock.lockFile = ./Cargo.lock; + }; + + apps.default = utils.lib.mkApp { + inherit (cargoToml.package) name; + drv = packages.default; + }; + + devShell = with pkgs; mkShell { + packages = [ cargo rustc rustfmt clippy rust-analyzer ]; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + }); +}