Commit e38c389435a6

Vincent Demeester <vincent@sbr.pm>
2025-05-13 22:53:48
flake.nix: add pre-commit-hooks
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 9c324c0
Changed files (2)
flake.lock
@@ -315,6 +315,22 @@
         "type": "github"
       }
     },
+    "flake-compat_6": {
+      "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"
+      }
+    },
     "flake-parts": {
       "inputs": {
         "nixpkgs-lib": [
@@ -444,6 +460,27 @@
         "type": "github"
       }
     },
+    "gitignore_4": {
+      "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"
+      }
+    },
     "home-manager": {
       "inputs": {
         "nixpkgs": [
@@ -751,6 +788,22 @@
         "type": "github"
       }
     },
+    "nixpkgs_3": {
+      "locked": {
+        "lastModified": 1730768919,
+        "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixpkgs-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
     "pre-commit-hooks": {
       "inputs": {
         "flake-compat": "flake-compat",
@@ -820,6 +873,26 @@
         "type": "github"
       }
     },
+    "pre-commit-hooks_3": {
+      "inputs": {
+        "flake-compat": "flake-compat_6",
+        "gitignore": "gitignore_4",
+        "nixpkgs": "nixpkgs_3"
+      },
+      "locked": {
+        "lastModified": 1746537231,
+        "narHash": "sha256-Wb2xeSyOsCoTCTj7LOoD6cdKLEROyFAArnYoS+noCWo=",
+        "owner": "cachix",
+        "repo": "git-hooks.nix",
+        "rev": "fa466640195d38ec97cf0493d6d6882bc4d14969",
+        "type": "github"
+      },
+      "original": {
+        "owner": "cachix",
+        "repo": "git-hooks.nix",
+        "type": "github"
+      }
+    },
     "root": {
       "inputs": {
         "agenix": "agenix",
@@ -840,6 +913,7 @@
         "nixpkgs": "nixpkgs_2",
         "nixpkgs-24_11": "nixpkgs-24_11",
         "nixpkgs-master": "nixpkgs-master",
+        "pre-commit-hooks": "pre-commit-hooks_3",
         "system-manager": "system-manager"
       }
     },
flake.nix
@@ -16,6 +16,12 @@
           ;
       };
 
+      supportedSystems = [
+        "x86_64-linux"
+        "aarch64-linux"
+      ];
+      forAllSystems = inputs.nixpkgs.lib.genAttrs supportedSystems;
+
       stableModules = [ inputs.home-manager-24_11.nixosModules.home-manager ];
       unstableModules = [ inputs.home-manager.nixosModules.home-manager ];
       commonModules = [
@@ -187,25 +193,48 @@
 
       overlays = import ./nix/overlays { inherit inputs; };
 
-      devShells.x86_64-linux.default =
-        let
-          pkgs = import inputs.nixpkgs {
-            system = "x86_64-linux";
-            config.allowUnfree = true;
+      checks = forAllSystems (system: {
+        pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
+          src = ./.;
+          hooks = {
+            # go
+            gofmt.enable = true;
+            golangci-lint.enable = true;
+            # nix
+            deadnix.enable = true;
+            nixfmt-rfc-style.enable = true;
+            # statix.enable = true;
+            # python
+            flake8.enable = true;
+            ruff.enable = true;
+            # shell
+            shellcheck.enable = true;
           };
-        in
-        pkgs.mkShell {
-          packages = [
-            pkgs.alejandra
-            pkgs.git
-            pkgs.nodePackages.prettier
-            pkgs.deadnix
-            pkgs.nixfmt-classic
-            inputs.agenix.packages.x86_64-linux.default
-          ];
-          name = "home";
-          DIRENV_LOG_FORMAT = "";
         };
+      });
+
+      devShells = forAllSystems (system: {
+        default =
+          let
+            pkgs = import inputs.nixpkgs {
+              inherit system;
+              config.allowUnfree = true;
+            };
+          in
+          inputs.nixpkgs.legacyPackages.${system}.mkShell {
+            inherit (self.checks.${system}.pre-commit-check) shellHook;
+            buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
+            packages = [
+              pkgs.git
+              pkgs.nodePackages.prettier
+              pkgs.deadnix
+              pkgs.nixfmt-rfc-style
+              inputs.agenix.packages.${system}.default
+            ];
+            name = "home";
+            DIRENV_LOG_FORMAT = "";
+          };
+      });
     };
 
   inputs = {
@@ -236,6 +265,7 @@
       ref = "nixos-24.11";
     };
     nixpkgs-master.url = "github:nixos/nixpkgs/master";
+    pre-commit-hooks.url = "github:cachix/git-hooks.nix";
     # Home Manager
     home-manager = {
       type = "github";