From a4ede5f6f403a6f73d8ac34ee56892be2e1a4f4f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 10 May 2023 13:04:06 +0000 Subject: [PATCH] templates: add rust-cargo --- templates/default.nix | 4 + templates/rust-cargo/.envrc | 5 + templates/rust-cargo/.gitignore | 6 ++ templates/rust-cargo/.woodpecker/check.yml | 31 ++++++ templates/rust-cargo/Cargo.lock | 7 ++ templates/rust-cargo/Cargo.toml | 8 ++ templates/rust-cargo/flake.nix | 112 +++++++++++++++++++++ templates/rust-cargo/rustfmt.toml | 0 templates/rust-cargo/src/main.rs | 3 + 9 files changed, 176 insertions(+) create mode 100644 templates/rust-cargo/.envrc create mode 100644 templates/rust-cargo/.gitignore create mode 100644 templates/rust-cargo/.woodpecker/check.yml create mode 100644 templates/rust-cargo/Cargo.lock create mode 100644 templates/rust-cargo/Cargo.toml create mode 100644 templates/rust-cargo/flake.nix create mode 100644 templates/rust-cargo/rustfmt.toml create mode 100644 templates/rust-cargo/src/main.rs diff --git a/templates/default.nix b/templates/default.nix index 31c3a81..44db753 100644 --- a/templates/default.nix +++ b/templates/default.nix @@ -7,4 +7,8 @@ path = ./c++-meson; description = "A C++ project using Meson"; }; + "rust-cargo" = { + path = ./rust-cargo; + description = "A Rust project using Cargo"; + }; } diff --git a/templates/rust-cargo/.envrc b/templates/rust-cargo/.envrc new file mode 100644 index 0000000..de77fcb --- /dev/null +++ b/templates/rust-cargo/.envrc @@ -0,0 +1,5 @@ +if ! has nix_direnv_version || ! nix_direnv_version 3.0.0; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.0/direnvrc" "sha256-21TMnI2xWX7HkSTjFFri2UaohXVj854mgvWapWrxRXg=" +fi + +use flake diff --git a/templates/rust-cargo/.gitignore b/templates/rust-cargo/.gitignore new file mode 100644 index 0000000..5f360ff --- /dev/null +++ b/templates/rust-cargo/.gitignore @@ -0,0 +1,6 @@ +# Rust build directory +/target + +# Nix generated files +/.pre-commit-config.yaml +/result diff --git a/templates/rust-cargo/.woodpecker/check.yml b/templates/rust-cargo/.woodpecker/check.yml new file mode 100644 index 0000000..4ff7dba --- /dev/null +++ b/templates/rust-cargo/.woodpecker/check.yml @@ -0,0 +1,31 @@ +labels: + backend: local + +steps: +- name: pre-commit check + image: bash + commands: + - nix develop --command pre-commit run --all + +- name: nix flake check + image: bash + commands: + - nix flake check + +- name: notifiy + image: bash + environment: + ADDRESS: + from_secret: matrix_homeserver + ROOM: + from_secret: matrix_roomid + USER: + from_secret: matrix_username + PASS: + from_secret: matrix_password + commands: + - nix run github:ambroisie/matrix-notifier + when: + status: + - failure + - success diff --git a/templates/rust-cargo/Cargo.lock b/templates/rust-cargo/Cargo.lock new file mode 100644 index 0000000..4f9c86e --- /dev/null +++ b/templates/rust-cargo/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "project" +version = "0.0.0" diff --git a/templates/rust-cargo/Cargo.toml b/templates/rust-cargo/Cargo.toml new file mode 100644 index 0000000..4dfdc0b --- /dev/null +++ b/templates/rust-cargo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "project" +version = "0.0.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/templates/rust-cargo/flake.nix b/templates/rust-cargo/flake.nix new file mode 100644 index 0000000..6d50369 --- /dev/null +++ b/templates/rust-cargo/flake.nix @@ -0,0 +1,112 @@ +{ + description = "A Rust project"; + + inputs = { + futils = { + type = "github"; + owner = "numtide"; + repo = "flake-utils"; + ref = "main"; + }; + + nixpkgs = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "nixos-unstable"; + }; + + pre-commit-hooks = { + type = "github"; + owner = "cachix"; + repo = "pre-commit-hooks.nix"; + ref = "master"; + inputs = { + flake-utils.follows = "futils"; + nixpkgs.follows = "nixpkgs"; + }; + }; + }; + + outputs = { self, futils, nixpkgs, pre-commit-hooks }: + { + overlays = { + default = final: _prev: { + project = with final; rustPlatform.buildRustPackage { + pname = "project"; + version = (final.lib.importTOML ./Cargo.toml).package.version; + + src = self; + + cargoLock = { + lockFile = "${self}/Cargo.lock"; + }; + + meta = with lib; { + description = "A Rust project"; + homepage = "https://git.belanyi.fr/ambroisie/project"; + license = licenses.mit; + maintainers = with maintainers; [ ambroisie ]; + }; + }; + }; + }; + } // futils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + self.overlays.default + ]; + }; + + pre-commit = pre-commit-hooks.lib.${system}.run { + src = self; + + hooks = { + clippy = { + enable = true; + settings = { + denyWarnings = true; + }; + }; + + nixpkgs-fmt = { + enable = true; + }; + + rustfmt = { + enable = true; + }; + }; + }; + in + { + checks = { + inherit (self.packages.${system}) project; + }; + + devShells = { + default = pkgs.mkShell { + inputsFrom = with self.packages.${system}; [ + project + ]; + + packages = with pkgs; [ + clippy + rust-analyzer + rustfmt + ]; + + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + + inherit (pre-commit) shellHook; + }; + }; + + packages = futils.lib.flattenTree { + default = pkgs.project; + inherit (pkgs) project; + }; + }); +} diff --git a/templates/rust-cargo/rustfmt.toml b/templates/rust-cargo/rustfmt.toml new file mode 100644 index 0000000..e69de29 diff --git a/templates/rust-cargo/src/main.rs b/templates/rust-cargo/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/templates/rust-cargo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}