Add pre-commit with relevant hooks

This commit is contained in:
Erwin Boskma 2022-11-18 09:49:45 +01:00
parent 15dea9bbe9
commit 8eb8b3cf87
Signed by: erwin
SSH key fingerprint: SHA256:Vw4O4qA0i5x65Y7yyjDpWDCSMSXAhqT4X7cJ3frdnLY
5 changed files with 136 additions and 62 deletions

1
.gitignore vendored
View file

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

View file

@ -1,7 +1,10 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).defaultNix
(import
(
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
}
)
{
src = ./.;
}).defaultNix

View file

@ -1,5 +1,20 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": [
@ -37,18 +52,54 @@
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1667292599,
"narHash": "sha256-7ISOUI1aj6UKMPIL+wwthENL22L3+A9V+jS8Is3QsRo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ef2f213d9659a274985778bff4ca322f3ef3ac68",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1667992213,
"narHash": "sha256-8Ens8ozllvlaFMCZBxg6S7oUyynYx2v7yleC5M0jJsE=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "ebcbfe09d2bd6d15f68de3a0ebb1e4dcb5cd324b",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay",
"utils": "utils"
"pre-commit-hooks": "pre-commit-hooks",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"utils"
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
@ -67,21 +118,6 @@
"repo": "rust-overlay",
"type": "github"
}
},
"utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",

View file

@ -2,7 +2,7 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
flake-utils.url = "github:numtide/flake-utils";
naersk = {
url = "github:nmattia/naersk/master";
inputs.nixpkgs.follows = "nixpkgs";
@ -10,52 +10,83 @@
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "utils";
inputs.flake-utils.follows = "flake-utils";
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = { self, nixpkgs, utils, naersk, rust-overlay }:
utils.lib.eachDefaultSystem (system:
outputs = { self, nixpkgs, flake-utils, naersk, rust-overlay, pre-commit-hooks }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
naersk-lib = pkgs.callPackage naersk { };
rustToolchain =
(pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
buildInputs = [
rustToolchain
pkgs.openssl
];
nativeBuildInputs = [
pkgs.pkgconf
];
in
rec {
packages.ha-now-playing = (naersk-lib.override {
cargo = rustToolchain;
rustc = rustToolchain;
}).buildPackage
{
inherit buildInputs nativeBuildInputs;
pname = "ha-now-playing";
root = ./.;
{
formatter = pkgs.nixpkgs-fmt;
};
packages.default = packages.ha-now-playing;
packages = {
ha-now-playing = (naersk-lib.override {
cargo = rustToolchain;
rustc = rustToolchain;
}).buildPackage
{
pname = "ha-now-playing";
root = ./.;
apps.ha-now-playing = utils.lib.mkApp {
drv = self.defaultPackage."${system}";
buildInputs = with pkgs; [
rustToolchain
openssl
];
nativeBuildInputs = with pkgs; [
pkgconf
cargo-edit
cargo-expand
cargo-diet
cargo-feature
cargo-outdated
rust-analyzer
pre-commit
jq
gitflow
yaml-language-server
];
};
};
apps.default = apps.ha-now-playing;
packages.default = self.packages.${system}.ha-now-playing;
overlays = final: prev: {
ha-now-playing = packages.ha-now-playing;
apps.ha-now-playing = flake-utils.lib.mkApp {
drv = self.packages.${system}.default;
};
apps.default = self.apps.${system}.ha-now-playing;
overlays = _final: _prev: {
inherit (self.packages.${system}) ha-now-playing;
};
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
statix.enable = true;
deadnix.enable = true;
clippy.enable = true;
};
};
};
devShells.default = with pkgs; mkShell {
inherit buildInputs;
nativeBuildInputs = [ cargo-edit cargo-expand cargo-diet cargo-feature cargo-outdated rust-analyzer pre-commit jq gitflow ] ++ nativeBuildInputs;
inherit (self.checks.${system}.pre-commit-check) shellHook;
name = "ha-now-playing";
inputsFrom = [ self.packages.${system}.ha-now-playing ];
};
});

View file

@ -1,7 +1,10 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).shellNix
(import
(
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
}
)
{
src = ./.;
}).shellNix