about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-06-27 18:31:30 -0700
committerFranck Cuny <franck@fcuny.net>2022-06-28 07:03:26 -0700
commit4500d71f1dc72d4d3315ac8f90ae2f0ae22c7a5b (patch)
treeb9a1e2987eb2bdd84c61ef09bf84260b6f650f81
parentref(flake): import tools top-level module (diff)
downloadworld-4500d71f1dc72d4d3315ac8f90ae2f0ae22c7a5b.tar.gz
feat(flake): add pre-commit hooks
And configure them to run nixpkgs-fmt and shellcheck.

Change-Id: I0aa2025e368b80c5e7d90a4dc05448494525e31e
Reviewed-on: https://cl.fcuny.net/c/world/+/590
Reviewed-by: Franck Cuny <franck@fcuny.net>
Tested-by: CI
-rw-r--r--.gitignore1
-rw-r--r--flake.lock27
-rw-r--r--flake.nix29
3 files changed, 56 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index cfbff8c..f60514c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
 /result
 /users/fcuny/notes/result
 /tools/gerrit-hook/gerrit-hook
+/.pre-commit-config.yaml
diff --git a/flake.lock b/flake.lock
index e342937..4264efe 100644
--- a/flake.lock
+++ b/flake.lock
@@ -149,6 +149,30 @@
         "type": "github"
       }
     },
+    "pre-commit-hooks": {
+      "inputs": {
+        "flake-utils": [
+          "futils"
+        ],
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1656169028,
+        "narHash": "sha256-y9DRauokIeVHM7d29lwT8A+0YoGUBXV3H0VErxQeA8s=",
+        "owner": "cachix",
+        "repo": "pre-commit-hooks.nix",
+        "rev": "db3bd555d3a3ceab208bed48f983ccaa6a71a25e",
+        "type": "github"
+      },
+      "original": {
+        "owner": "cachix",
+        "ref": "master",
+        "repo": "pre-commit-hooks.nix",
+        "type": "github"
+      }
+    },
     "root": {
       "inputs": {
         "agenix": "agenix",
@@ -157,7 +181,8 @@
         "home-manager": "home-manager",
         "nixpkgs": "nixpkgs_2",
         "nixpkgs-unstable": "nixpkgs-unstable",
-        "nur": "nur"
+        "nur": "nur",
+        "pre-commit-hooks": "pre-commit-hooks"
       }
     }
   },
diff --git a/flake.nix b/flake.nix
index c043444..e36b4ed 100644
--- a/flake.nix
+++ b/flake.nix
@@ -24,6 +24,17 @@
       # We want home-manager to use the same set of nixpkgs as our system.
       inputs.nixpkgs.follows = "nixpkgs";
     };
+
+    pre-commit-hooks = {
+      type = "github";
+      owner = "cachix";
+      repo = "pre-commit-hooks.nix";
+      ref = "master";
+      inputs = {
+        flake-utils.follows = "futils";
+        nixpkgs.follows = "nixpkgs";
+      };
+    };
   };
 
   # Output config, or config for NixOS system
@@ -57,6 +68,22 @@
             };
           };
 
+          checks = {
+            pre-commit = inputs.pre-commit-hooks.lib.${system}.run {
+              src = ./.;
+
+              hooks = {
+                nixpkgs-fmt = {
+                  enable = true;
+                };
+
+                shellcheck = {
+                  enable = true;
+                };
+              };
+            };
+          };
+
           # `nix run .#ci.format` formats in current directory!
           apps.ci.format = ci.fmt.mkFmtScript self;
 
@@ -67,6 +94,7 @@
             default = pkgs.mkShell {
               name = "NixOS-config";
               buildInputs = with pkgs; [
+                gitAndTools.pre-commit
                 nixUnstable
                 nixfmt
                 nixpkgs-fmt
@@ -76,6 +104,7 @@
                 go
                 gopls
               ];
+              inherit (self.checks.${system}.pre-commit) shellHook;
             };
           };
         }) // {