diff --git a/.gitignore b/.gitignore index 8b13789..eb2668a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ - +templates/*/result* +templates/*/flake.lock diff --git a/flake.nix b/flake.nix index 4744e72..6049686 100644 --- a/flake.nix +++ b/flake.nix @@ -18,5 +18,9 @@ nixosModules = { bonfire = import ./nixosModules/bonfire.nix; }; + + templates = { + rust = { path = ./templates/rust; description = "Basic Rust template"; }; + }; }; } diff --git a/templates/rust/.gitignore b/templates/rust/.gitignore new file mode 100644 index 0000000..8ea0ee8 --- /dev/null +++ b/templates/rust/.gitignore @@ -0,0 +1,2 @@ +/target +result* diff --git a/templates/rust/Cargo.lock b/templates/rust/Cargo.lock new file mode 100644 index 0000000..b7026a0 --- /dev/null +++ b/templates/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-example" +version = "0.1.0" diff --git a/templates/rust/Cargo.toml b/templates/rust/Cargo.toml new file mode 100644 index 0000000..87aa3e1 --- /dev/null +++ b/templates/rust/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rust-example" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/templates/rust/README.md b/templates/rust/README.md new file mode 100644 index 0000000..17df126 --- /dev/null +++ b/templates/rust/README.md @@ -0,0 +1,8 @@ +# Basic Rust Example + +* Creating/updating `Cargo.lock` +```shell +touch Cargo.lock +nix develop +cargo check +``` diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix new file mode 100644 index 0000000..09c0959 --- /dev/null +++ b/templates/rust/flake.nix @@ -0,0 +1,52 @@ +{ + description = "Basic rust template"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + crane = { url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; }; + }; + + outputs = inputs @ { self, nixpkgs, crane, ... }: + let + forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" ]; + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + in { + packages = forAllSystems (system: { + my-crate = let + pkgs = nixpkgsFor.${system}; + craneLib = crane.lib.${system}; + in craneLib.buildPackage { + src = craneLib.cleanCargoSource (craneLib.path ./.); + strictDeps = true; + + buildInputs = []; + }; + + default = self.packages.${system}.my-crate; + }); + + checks = forAllSystems (system: { + inherit (self.packages.${system}.my-crate); + + my-crate-fmt = let craneLib = crane.lib.${system}; in craneLib.cargoFmt { + src = craneLib.cleanCargoSource (craneLib.path ./.); + }; + }); + + apps = forAllSystems (system: { + default = { + type = "app"; + program = "${self.packages.${system}.my-crate}/bin/rust-example"; + }; + }); + + devShells = forAllSystems (system: { + default = crane.lib.${system}.devShell { + checks = self.checks.${system}; + + packages = []; + }; + }); + }; + +} diff --git a/templates/rust/src/main.rs b/templates/rust/src/main.rs new file mode 100644 index 0000000..f8e7e83 --- /dev/null +++ b/templates/rust/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, nix!"); +}