From 83ae1044f3c9c469e683f6dc9ff486590ec4acfa Mon Sep 17 00:00:00 2001 From: mat ess Date: Tue, 29 Nov 2022 22:19:54 -0500 Subject: [PATCH] Tweak rust template --- flake.nix | 6 +++++- templates/rust/.gitignore | 4 ++++ templates/rust/flake.nix | 29 ++++++++++++++--------------- 3 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 templates/rust/.gitignore diff --git a/flake.nix b/flake.nix index 6afc272..de8a9de 100644 --- a/flake.nix +++ b/flake.nix @@ -310,7 +310,11 @@ templates = { rust = { description = "A rust flake template based on flake.parts"; - welcomeText = "Run `cargo init` to start a new project"; + welcomeText = '' + welcome to a new rust project ミ(・・)ミ + + run `direnv allow` and `cargo init` to start a new project + ''; path = ./templates/rust; }; }; diff --git a/templates/rust/.gitignore b/templates/rust/.gitignore new file mode 100644 index 0000000..6bf609e --- /dev/null +++ b/templates/rust/.gitignore @@ -0,0 +1,4 @@ +/.direnv +/result +/target +/.pre-commit-config.yaml diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix index 59ee5bd..31ee16b 100644 --- a/templates/rust/flake.nix +++ b/templates/rust/flake.nix @@ -7,40 +7,39 @@ crane.url = "github:ipetkov/crane"; crane.inputs.nixpkgs.follows = "nixpkgs"; pre-commit.url = "github:cachix/pre-commit-hooks.nix"; + pre-commit.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, flake-parts, ... }: + outputs = { self, flake-parts, crane, pre-commit, ... }: flake-parts.lib.mkFlake { inherit self; } { + imports = [ pre-commit.flakeModule ]; systems = [ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ]; - perSystem = { self', inputs', pkgs, ... }: + perSystem = { config, pkgs, system, ... }: let - inherit (inputs') crane pre-commit; - crane-lib = crane.lib; + crane-lib = crane.lib.${system}; package = crane-lib.buildPackage { src = crane-lib.cleanCargoSource ./.; nativeBuildInputs = [ pkgs.libiconv ]; }; in { - checks = { - inherit package; - pre-commit = pre-commit.lib.run { - src = ./.; - hooks = { - rustfmt.enable = true; - clippy.enable = true; - cargo-check.enable = true; - }; - }; + pre-commit.settings.hooks = { + rustfmt.enable = true; + clippy.enable = true; + cargo-check.enable = true; }; + checks = { inherit package; }; packages.default = package; devShells.default = pkgs.mkShell { - inherit (self'.checks.pre-commit) shellHook; + shellHook = '' + ${config.pre-commit.installationScript} + echo "welcome to your rust project ミ(・・)ミ" 1>&2 + ''; inputsFrom = builtins.attrValues self.checks; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";