| 
									
										
										
										
											2024-05-19 23:32:52 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   inputs, | 
					
						
							|  |  |  |   forEachSystem, | 
					
						
							|  |  |  |   formatter, | 
					
						
							|  |  |  |   ... | 
					
						
							|  |  |  | }: | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  | forEachSystem ( | 
					
						
							|  |  |  |   system: | 
					
						
							|  |  |  |   let | 
					
						
							|  |  |  |     pkgs = inputs.nixpkgs.legacyPackages.${system}; | 
					
						
							|  |  |  |   in | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run { | 
					
						
							|  |  |  |       src = ./.; | 
					
						
							|  |  |  |       hooks = { | 
					
						
							|  |  |  |         # nix checks | 
					
						
							|  |  |  |         # Example custom hook for nix formatting | 
					
						
							|  |  |  |         fmt-check = { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							| 
									
										
										
										
											2024-05-19 23:32:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  |           # The command to execute (mandatory): | 
					
						
							|  |  |  |           entry = "${formatter.${system}}/bin/nixfmt --check"; | 
					
						
							| 
									
										
										
										
											2024-05-19 23:32:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  |           # The pattern of files to run on (default: "" (all)) | 
					
						
							|  |  |  |           # see also https://pre-commit.com/#hooks-files | 
					
						
							|  |  |  |           files = "\\.nix$"; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         ## static analysis checks for nix | 
					
						
							|  |  |  |         nil.enable = true; | 
					
						
							|  |  |  |         statix.enable = true; | 
					
						
							|  |  |  |         deadnix = { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							|  |  |  |           settings = { | 
					
						
							|  |  |  |             noUnderscore = true; # ignore variables starting with underscore | 
					
						
							|  |  |  |             # ignore lambda patterns (useful for passing args from ({}@args) | 
					
						
							|  |  |  |             # to other functions) | 
					
						
							|  |  |  |             noLambdaPatternNames = true; | 
					
						
							|  |  |  |           }; | 
					
						
							| 
									
										
										
										
											2024-05-21 19:47:21 -04:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2024-05-19 23:32:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  |         # json hooks | 
					
						
							|  |  |  |         check-json = { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							|  |  |  |           # exclude vscode json files as they allow comments and check-json doesn't | 
					
						
							|  |  |  |           excludes = [ "settings.json$" ]; | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2024-05-19 23:32:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  |         # toml hooks | 
					
						
							|  |  |  |         check-toml.enable = true; | 
					
						
							| 
									
										
										
										
											2024-05-20 00:07:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  |         # markdown hooks | 
					
						
							|  |  |  |         mdl = { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							|  |  |  |           settings.style = | 
					
						
							|  |  |  |             (pkgs.writeText ".mdl_style.rb" ''
 | 
					
						
							|  |  |  |               #!/usr/bin/env ruby | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               all | 
					
						
							|  |  |  |               rule 'MD013', :tables => false | 
					
						
							|  |  |  |             '').outPath;
 | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2024-07-07 19:08:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  |         # git hooks | 
					
						
							|  |  |  |         check-merge-conflicts.enable = true; | 
					
						
							|  |  |  |         ## prevents committing to main | 
					
						
							|  |  |  |         no-commit-to-branch.enable = true; | 
					
						
							| 
									
										
										
										
											2024-05-19 23:32:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  |         # misc hooks | 
					
						
							|  |  |  |         check-added-large-files.enable = true; | 
					
						
							|  |  |  |         ## prevents two similarly named files for case sensitive systems | 
					
						
							|  |  |  |         check-case-conflicts.enable = true; | 
					
						
							|  |  |  |         detect-private-keys.enable = true; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2024-05-19 23:32:52 -04:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2024-07-07 19:57:58 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | ) |