1
1
{ config , lib , pkgs , ... } :
2
-
3
2
let
4
-
5
3
inherit ( lib )
6
4
attrNames
7
5
concatStringsSep
@@ -21,122 +19,123 @@ let
21
19
hookType =
22
20
types . submodule (
23
21
{ config , name , ... } :
24
- {
25
- options =
26
- {
27
- enable =
28
- mkOption {
29
- type = types . bool ;
30
- description = "Whether to enable this pre-commit hook." ;
31
- default = false ;
32
- } ;
33
- raw =
34
- mkOption {
35
- type = types . attrsOf types . unspecified ;
36
- description =
37
- ''
38
- Raw fields of a pre-commit hook. This is mostly for internal use but
39
- exposed in case you need to work around something.
22
+ {
23
+ options =
24
+ {
25
+ enable =
26
+ mkOption {
27
+ type = types . bool ;
28
+ description = "Whether to enable this pre-commit hook." ;
29
+ default = false ;
30
+ } ;
31
+ raw =
32
+ mkOption {
33
+ type = types . attrsOf types . unspecified ;
34
+ description =
35
+ ''
36
+ Raw fields of a pre-commit hook. This is mostly for internal use but
37
+ exposed in case you need to work around something.
40
38
41
- Default: taken from the other hook options.
42
- '' ;
43
- } ;
44
- name =
45
- mkOption {
46
- type = types . str ;
47
- default = name ;
48
- defaultText = literalExample "internal name, same as id" ;
49
- description =
50
- ''
51
- The name of the hook - shown during hook execution.
52
- '' ;
53
- } ;
54
- entry =
55
- mkOption {
56
- type = types . str ;
57
- description =
58
- ''
59
- The entry point - the executable to run. entry can also contain arguments that will not be overridden such as entry: autopep8 -i.
60
- '' ;
61
- } ;
62
- language =
63
- mkOption {
64
- type = types . str ;
65
- description =
66
- ''
67
- The language of the hook - tells pre-commit how to install the hook.
68
- '' ;
69
- default = "system" ;
70
- } ;
71
- files =
72
- mkOption {
73
- type = types . str ;
74
- description =
75
- ''
76
- The pattern of files to run on.
77
- '' ;
78
- default = "" ;
79
- } ;
80
- types =
81
- mkOption {
82
- type = types . listOf types . str ;
83
- description =
84
- ''
85
- List of file types to run on. See Filtering files with types (https://pre-commit.com/#plugins).
86
- '' ;
87
- default = [ "file" ] ;
88
- } ;
89
- description =
90
- mkOption {
91
- type = types . str ;
92
- description =
93
- ''
94
- Description of the hook. used for metadata purposes only.
95
- '' ;
96
- default = "" ;
97
- } ;
98
- excludes =
99
- mkOption {
100
- type = types . listOf types . str ;
101
- description =
102
- ''
103
- Exclude files that were matched by these patterns.
104
- '' ;
105
- default = [ ] ;
106
- } ;
107
- pass_filenames =
108
- mkOption {
109
- type = types . bool ;
110
- description = "Whether to pass filenames as arguments to the entry point." ;
111
- default = true ;
112
- } ;
113
- } ;
114
- config =
115
- {
116
- raw =
117
- {
118
- inherit ( config ) name entry language files types pass_filenames ;
119
- id = name ;
120
- exclude = mergeExcludes config . excludes ;
121
- } ;
122
- } ;
123
- }
39
+ Default: taken from the other hook options.
40
+ '' ;
41
+ } ;
42
+ name =
43
+ mkOption {
44
+ type = types . str ;
45
+ default = name ;
46
+ defaultText = literalExample "internal name, same as id" ;
47
+ description =
48
+ ''
49
+ The name of the hook - shown during hook execution.
50
+ '' ;
51
+ } ;
52
+ entry =
53
+ mkOption {
54
+ type = types . str ;
55
+ description =
56
+ ''
57
+ The entry point - the executable to run. entry can also contain arguments that will not be overridden such as entry: autopep8 -i.
58
+ '' ;
59
+ } ;
60
+ language =
61
+ mkOption {
62
+ type = types . str ;
63
+ description =
64
+ ''
65
+ The language of the hook - tells pre-commit how to install the hook.
66
+ '' ;
67
+ default = "system" ;
68
+ } ;
69
+ files =
70
+ mkOption {
71
+ type = types . str ;
72
+ description =
73
+ ''
74
+ The pattern of files to run on.
75
+ '' ;
76
+ default = "" ;
77
+ } ;
78
+ types =
79
+ mkOption {
80
+ type = types . listOf types . str ;
81
+ description =
82
+ ''
83
+ List of file types to run on. See Filtering files with types (https://pre-commit.com/#plugins).
84
+ '' ;
85
+ default = [ "file" ] ;
86
+ } ;
87
+ description =
88
+ mkOption {
89
+ type = types . str ;
90
+ description =
91
+ ''
92
+ Description of the hook. used for metadata purposes only.
93
+ '' ;
94
+ default = "" ;
95
+ } ;
96
+ excludes =
97
+ mkOption {
98
+ type = types . listOf types . str ;
99
+ description =
100
+ ''
101
+ Exclude files that were matched by these patterns.
102
+ '' ;
103
+ default = [ ] ;
104
+ } ;
105
+ pass_filenames =
106
+ mkOption {
107
+ type = types . bool ;
108
+ description = "Whether to pass filenames as arguments to the entry point." ;
109
+ default = true ;
110
+ } ;
111
+ } ;
112
+ config =
113
+ {
114
+ raw =
115
+ {
116
+ inherit ( config ) name entry language files types pass_filenames ;
117
+ id = name ;
118
+ exclude = mergeExcludes config . excludes ;
119
+ } ;
120
+ } ;
121
+ }
124
122
) ;
125
123
126
124
mergeExcludes =
127
125
excludes :
128
- if excludes == [ ] then "^$" else "(${ concatStringsSep "|" excludes } )" ;
126
+ if excludes == [ ] then "^$" else "(${ concatStringsSep "|" excludes } )" ;
129
127
130
128
enabledHooks = filterAttrs ( id : value : value . enable ) cfg . hooks ;
131
129
processedHooks =
132
130
mapAttrsToList ( id : value : value . raw // { inherit id ; } ) enabledHooks ;
133
131
134
132
configFile =
135
- runCommand "pre-commit-config.json" {
136
- buildInputs = [ pkgs . jq ] ;
137
- passAsFile = [ "rawJSON" ] ;
138
- rawJSON = builtins . toJSON cfg . rawConfig ;
139
- } ''
133
+ runCommand "pre-commit-config.json"
134
+ {
135
+ buildInputs = [ pkgs . jq ] ;
136
+ passAsFile = [ "rawJSON" ] ;
137
+ rawJSON = builtins . toJSON cfg . rawConfig ;
138
+ } ''
140
139
{
141
140
echo '# DO NOT MODIFY';
142
141
echo '# This file was generated by nix-pre-commit-hooks';
200
199
'' ;
201
200
# This default is for when the module is the entry point rather than
202
201
# /default.nix. /default.nix will override this for efficiency.
203
- default = ( import ../nix { inherit ( pkgs ) system ; } ) . callPackage ../nix/tools.nix { } ;
202
+ default = ( import ../nix { inherit ( pkgs ) system ; } ) . callPackage ../nix/tools.nix { } ;
204
203
defaultText =
205
204
literalExample ''nix-pre-commit-hooks-pkgs.callPackage tools-dot-nix { inherit (pkgs) system; }'' ;
206
205
} ;
212
211
''
213
212
The hook definitions.
214
213
'' ;
215
- default = { } ;
214
+ default = { } ;
216
215
} ;
217
216
218
217
run =
255
254
''
256
255
Exclude files that were matched by these patterns.
257
256
'' ;
258
- default = [ ] ;
257
+ default = [ ] ;
259
258
} ;
260
259
261
260
rawConfig =
284
283
hooks = processedHooks ;
285
284
}
286
285
] ;
287
- } // lib . optionalAttrs ( cfg . excludes != [ ] ) {
286
+ } // lib . optionalAttrs ( cfg . excludes != [ ] ) {
288
287
exclude = mergeExcludes cfg . excludes ;
289
288
} ;
290
289
0 commit comments