chore: improve Nix flake
This commit is contained in:
parent
e9231986c3
commit
7836888456
6 changed files with 208 additions and 20 deletions
65
nix/git-hooks.nix
Normal file
65
nix/git-hooks.nix
Normal file
|
@ -0,0 +1,65 @@
|
|||
{ inputs, pkgs, ... }:
|
||||
let
|
||||
conventional-commit = pkgs.callPackage ./pkgs/conventional-pre-commit.nix { };
|
||||
in
|
||||
{
|
||||
pre-commit-check = inputs.pre-commit-hooks.lib.${pkgs.system}.run {
|
||||
src = ./..;
|
||||
hooks = {
|
||||
# TOML
|
||||
check-toml.enable = true;
|
||||
|
||||
# YAML
|
||||
check-yaml.enable = true;
|
||||
|
||||
# Nix
|
||||
deadnix.enable = true;
|
||||
flake-checker.enable = true;
|
||||
nixpkgs-fmt.enable = true;
|
||||
statix.enable = true;
|
||||
|
||||
# Rust
|
||||
clippy = {
|
||||
enable = true;
|
||||
settings = {
|
||||
denyWarnings = true;
|
||||
};
|
||||
extraPackages = with pkgs; [
|
||||
openssl
|
||||
pkg-config
|
||||
];
|
||||
};
|
||||
rustfmt.enable = true;
|
||||
cargo-check = {
|
||||
enable = true;
|
||||
extraPackages = with pkgs; [
|
||||
pkg-config
|
||||
openssl
|
||||
];
|
||||
};
|
||||
|
||||
# Git
|
||||
no-commit-to-branch = {
|
||||
enable = true;
|
||||
settings = {
|
||||
branch = [ "main" ];
|
||||
};
|
||||
};
|
||||
conventional-commit = {
|
||||
enable = true;
|
||||
name = "conventional-commit";
|
||||
description = "A pre-commit hook that checks commit messages for Conventional Commits formatting";
|
||||
package = conventional-commit;
|
||||
entry = "${conventional-commit}/bin/conventional-pre-commit";
|
||||
args = [ "--strict" "feat" "fix" "chore" "revert" "style" "docs" "build" "refactor" "test" "ci" "perf" ];
|
||||
stages = [ "commit-msg" ];
|
||||
};
|
||||
};
|
||||
|
||||
settings = {
|
||||
rust.check.cargoDeps = pkgs.rustPlatform.importCargoLock {
|
||||
lockFile = ../Cargo.lock;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
20
nix/pkgs/conventional-pre-commit.nix
Normal file
20
nix/pkgs/conventional-pre-commit.nix
Normal file
|
@ -0,0 +1,20 @@
|
|||
{ python3Packages, fetchPypi, ... }:
|
||||
|
||||
python3Packages.buildPythonApplication rec {
|
||||
pname = "conventional_pre_commit";
|
||||
version = "4.2.0";
|
||||
|
||||
src = fetchPypi {
|
||||
inherit pname version;
|
||||
hash = "sha256-a1ooZzOMWKHRTTAN5otWwXt8hAO7EiFV84Y5pCPSH/E=";
|
||||
};
|
||||
|
||||
doCheck = false;
|
||||
pyproject = true;
|
||||
|
||||
build-system = with python3Packages; [
|
||||
setuptools
|
||||
setuptools-scm
|
||||
wheel
|
||||
];
|
||||
}
|
36
nix/shell.nix
Normal file
36
nix/shell.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
{ pkgs, rust-toolchain, self, ... }:
|
||||
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
name = "immich-tools";
|
||||
buildInputs = with pkgs; [
|
||||
cargo
|
||||
cargo-edit
|
||||
cargo-insta
|
||||
cargo-machete
|
||||
cargo-release
|
||||
cargo-sort
|
||||
git-cliff
|
||||
openssl
|
||||
pkg-config
|
||||
rustc
|
||||
rust-toolchain
|
||||
] ++ lib.optionals stdenv.isDarwin [
|
||||
libiconv
|
||||
] ++ self.checks.${pkgs.system}.pre-commit-check.enabledPackages;
|
||||
RUST_BACKTRACE = 1;
|
||||
|
||||
# Copy rust-toolchain to project directory for easy use in IntelliJ
|
||||
shellHook = ''
|
||||
if [ -L ./.rust-toolchain ] && [ "$(readlink ./.rust-toolchain)" = "${rust-toolchain}" ]; then
|
||||
echo "Rust toolchain symlink is already correct."
|
||||
else
|
||||
rm -f ./.rust-toolchain
|
||||
ln -s ${rust-toolchain} ./.rust-toolchain
|
||||
echo "Rust toolchain symlink updated."
|
||||
fi
|
||||
|
||||
${self.checks.${pkgs.system}.pre-commit-check.shellHook}
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue