about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--flake.lock91
-rw-r--r--flake.nix25
3 files changed, 116 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 314d81e..403c115 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,4 @@ go.work
 # End of https://www.toptal.com/developers/gitignore/api/go
 /netlify/.netlify/
 /website/
+/.pre-commit-config.yaml
diff --git a/flake.lock b/flake.lock
index 5149901..13e0613 100644
--- a/flake.lock
+++ b/flake.lock
@@ -16,6 +16,43 @@
         "type": "github"
       }
     },
+    "flake-compat_2": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1696426674,
+        "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
+        "owner": "edolstra",
+        "repo": "flake-compat",
+        "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
+        "type": "github"
+      },
+      "original": {
+        "owner": "edolstra",
+        "repo": "flake-compat",
+        "type": "github"
+      }
+    },
+    "gitignore": {
+      "inputs": {
+        "nixpkgs": [
+          "pre-commit-hooks",
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1709087332,
+        "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
+        "owner": "hercules-ci",
+        "repo": "gitignore.nix",
+        "rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
+        "type": "github"
+      },
+      "original": {
+        "owner": "hercules-ci",
+        "repo": "gitignore.nix",
+        "type": "github"
+      }
+    },
     "gomod2nix": {
       "inputs": {
         "flake-utils": [
@@ -55,11 +92,65 @@
         "type": "github"
       }
     },
+    "nixpkgs-stable": {
+      "locked": {
+        "lastModified": 1710695816,
+        "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "614b4613980a522ba49f0d194531beddbb7220d3",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixos-23.11",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "nixpkgs_2": {
+      "locked": {
+        "lastModified": 1710765496,
+        "narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixpkgs-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "pre-commit-hooks": {
+      "inputs": {
+        "flake-compat": "flake-compat_2",
+        "gitignore": "gitignore",
+        "nixpkgs": "nixpkgs_2",
+        "nixpkgs-stable": "nixpkgs-stable"
+      },
+      "locked": {
+        "lastModified": 1716213921,
+        "narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=",
+        "owner": "cachix",
+        "repo": "pre-commit-hooks.nix",
+        "rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0",
+        "type": "github"
+      },
+      "original": {
+        "owner": "cachix",
+        "repo": "pre-commit-hooks.nix",
+        "type": "github"
+      }
+    },
     "root": {
       "inputs": {
         "flake-compat": "flake-compat",
         "gomod2nix": "gomod2nix",
         "nixpkgs": "nixpkgs",
+        "pre-commit-hooks": "pre-commit-hooks",
         "utils": "utils"
       }
     },
diff --git a/flake.nix b/flake.nix
index 85f7915..bf5695f 100644
--- a/flake.nix
+++ b/flake.nix
@@ -11,8 +11,9 @@
     inputs.nixpkgs.follows = "nixpkgs";
     inputs.flake-utils.follows = "utils";
   };
+  inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
 
-  outputs = { self, nixpkgs, utils, gomod2nix, ... }:
+  outputs = { self, nixpkgs, utils, gomod2nix, pre-commit-hooks, ... }:
     utils.lib.eachDefaultSystem
       (system:
         let
@@ -37,6 +38,7 @@
             };
             default = pkgs.mkShell {
               inputsFrom = [ packages.builder ];
+              inherit (self.checks.${system}.pre-commit-check) shellHook;
               packages = with pkgs; [
                 gopls
                 gotools
@@ -54,6 +56,27 @@
               ${pkgs.hyperlink}/bin/hyperlink ${packages.website}/website/public
               touch $out
             '';
+            pre-commit-check = pre-commit-hooks.lib.${system}.run {
+              src = ./.;
+              hooks = {
+                go-mod-tidy = {
+                  enable = true;
+                  name = "go-mod-tidy";
+                  description = "Run `go mod tidy`";
+                  types_or = [ "go" "go-mod" ];
+                  entry = "${pkgs.go}/bin/go mod tidy";
+                  pass_filenames = false;
+                };
+                gomod2nix = {
+                  enable = true;
+                  name = "gomod2nix";
+                  description = "Import go.mod updates to nix";
+                  types_or = [ "go-sum" ];
+                  entry = "${pkgs.gomod2nix}/bin/gomod2nix";
+                  pass_filenames = false;
+                };
+              };
+            };
           };
         });
 }