Tweak rust template

work
mat ess 2022-11-29 22:19:54 -05:00
parent ad392f8557
commit 83ae1044f3
3 changed files with 23 additions and 16 deletions

View File

@ -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;
};
};

4
templates/rust/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/.direnv
/result
/target
/.pre-commit-config.yaml

View File

@ -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 = {
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}";