diff --git a/flake.nix b/flake.nix
index abbf47d0..fa4ce508 100644
--- a/flake.nix
+++ b/flake.nix
@@ -33,6 +33,7 @@
         {
           config,
           pkgs,
+          lib,
           inputs',
           ...
         }:
@@ -44,20 +45,12 @@
               ## Add a directory here if pre-commit hooks shouldn't apply to it.
               optout = [ "npins" ];
               excludes = map (dir: "^${dir}/") optout;
+              addExcludes = lib.mapAttrs (_: c: c // { inherit excludes; });
             in
-            {
-              nixfmt-rfc-style = {
-                enable = true;
-                inherit excludes;
-              };
-              deadnix = {
-                enable = true;
-                inherit excludes;
-              };
-              trim-trailing-whitespace = {
-                enable = true;
-                inherit excludes;
-              };
+            addExcludes {
+              nixfmt-rfc-style.enable = true;
+              deadnix.enable = true;
+              trim-trailing-whitespace.enable = true;
             };
 
           devShells.default = pkgs.mkShell {