Skip to content

Commit

Permalink
flake: Add pre-commit (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbasit authored Dec 12, 2024
1 parent 5f8b1b6 commit 59516a3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ go.work.sum

# SQLite database
/db/database.sqlite3

# Pre-commit configuration (auto-generated)
/.pre-commit-config.yaml
6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
url = "github:hercules-ci/flake-parts";
};

git-hooks-nix = {
inputs.nixpkgs.follows = "nixpkgs";
url = "github:cachix/git-hooks.nix";
};

nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";

treefmt-nix = {
Expand All @@ -23,6 +28,7 @@
./nix/devshells/flake-module.nix
./nix/formatter/flake-module.nix
./nix/packages/flake-module.nix
./nix/pre-commit/flake-module.nix
];
systems = [
"x86_64-linux"
Expand Down
2 changes: 2 additions & 0 deletions nix/devshells/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
_DBMATE_VERSION = "${pkgs.dbmate.version}";

shellHook = ''
${config.pre-commit.installationScript}
${pkgs.gnused}/bin/sed -e "s:^\(go \)[0-9.]*$:\1''${_GO_VERSION}:" -i go.mod
${pkgs.gnused}/bin/sed -e "s:^\(ARG GO_VERSION=\).*$:\1''${_GO_VERSION}:" -i Dockerfile
${pkgs.gnused}/bin/sed -e "s:^\(ARG DBMATE_VERSION=\).*$:\1''${_DBMATE_VERSION}:" -i Dockerfile
Expand Down
22 changes: 22 additions & 0 deletions nix/pre-commit/flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ inputs, ... }:

{
imports = [
inputs.git-hooks-nix.flakeModule
];

perSystem = {
pre-commit.check.enable = false;
pre-commit.settings.hooks = {
deadnix.enable = true;
gofmt.enable = true;
golangci-lint.enable = true;
no-commit-to-branch.enable = true;
no-commit-to-branch.settings.branch = [ "main" ];
nixfmt-rfc-style.enable = true;
statix.enable = true;
trim-trailing-whitespace.enable = true;
yamlfmt.enable = true;
};
};
}

0 comments on commit 59516a3

Please sign in to comment.