|
| 1 | +{ config, name, lib, ... }: |
| 2 | + |
| 3 | + |
| 4 | +let |
| 5 | + inherit (lib) mkOption types; |
| 6 | + cfg = config.options; |
| 7 | +in |
| 8 | +{ |
| 9 | + options = { |
| 10 | + enable = mkOption { |
| 11 | + type = types.bool; |
| 12 | + description = lib.mdDoc "Whether to enable this pre-commit hook."; |
| 13 | + default = false; |
| 14 | + }; |
| 15 | + |
| 16 | + raw = mkOption { |
| 17 | + type = types.attrsOf types.unspecified; |
| 18 | + description = lib.mdDoc |
| 19 | + '' |
| 20 | + Raw fields of a pre-commit hook. This is mostly for internal use but |
| 21 | + exposed in case you need to work around something. |
| 22 | +
|
| 23 | + Default: taken from the other hook options. |
| 24 | + ''; |
| 25 | + }; |
| 26 | + |
| 27 | + name = mkOption { |
| 28 | + type = types.str; |
| 29 | + defaultText = lib.literalMD "internal name, same as `id`"; |
| 30 | + default = name; |
| 31 | + description = lib.mdDoc |
| 32 | + '' |
| 33 | + The name of the hook - shown during hook execution. |
| 34 | + ''; |
| 35 | + }; |
| 36 | + |
| 37 | + description = mkOption { |
| 38 | + type = types.str; |
| 39 | + description = lib.mdDoc |
| 40 | + '' |
| 41 | + Description of the hook. used for metadata purposes only. |
| 42 | + ''; |
| 43 | + default = ""; |
| 44 | + }; |
| 45 | + |
| 46 | + package = mkOption { |
| 47 | + type = types.package; |
| 48 | + description = lib.mdDoc |
| 49 | + '' |
| 50 | + The package that provides the hook. |
| 51 | + ''; |
| 52 | + }; |
| 53 | + |
| 54 | + entry = mkOption { |
| 55 | + type = types.str; |
| 56 | + description = lib.mdDoc |
| 57 | + '' |
| 58 | + The entry point - the executable to run. {option}`entry` can also contain arguments that will not be overridden, such as `entry = "autopep8 -i";`. |
| 59 | + ''; |
| 60 | + }; |
| 61 | + |
| 62 | + language = mkOption { |
| 63 | + type = types.str; |
| 64 | + description = lib.mdDoc |
| 65 | + '' |
| 66 | + The language of the hook - tells pre-commit how to install the hook. |
| 67 | + ''; |
| 68 | + default = "system"; |
| 69 | + }; |
| 70 | + |
| 71 | + files = mkOption { |
| 72 | + type = types.str; |
| 73 | + description = lib.mdDoc |
| 74 | + '' |
| 75 | + The pattern of files to run on. |
| 76 | + ''; |
| 77 | + default = ""; |
| 78 | + }; |
| 79 | + |
| 80 | + types = mkOption { |
| 81 | + type = types.listOf types.str; |
| 82 | + description = lib.mdDoc |
| 83 | + '' |
| 84 | + List of file types to run on. See [Filtering files with types](https://pre-commit.com/#plugins). |
| 85 | + ''; |
| 86 | + default = [ "file" ]; |
| 87 | + }; |
| 88 | + |
| 89 | + types_or = mkOption { |
| 90 | + type = types.listOf types.str; |
| 91 | + description = lib.mdDoc |
| 92 | + '' |
| 93 | + List of file types to run on, where only a single type needs to match. |
| 94 | + ''; |
| 95 | + default = [ ]; |
| 96 | + }; |
| 97 | + |
| 98 | + excludes = mkOption { |
| 99 | + type = types.listOf types.str; |
| 100 | + description = lib.mdDoc |
| 101 | + '' |
| 102 | + Exclude files that were matched by these patterns. |
| 103 | + ''; |
| 104 | + default = [ ]; |
| 105 | + }; |
| 106 | + |
| 107 | + pass_filenames = mkOption { |
| 108 | + type = types.bool; |
| 109 | + description = lib.mdDoc '' |
| 110 | + Whether to pass filenames as arguments to the entry point. |
| 111 | + ''; |
| 112 | + default = true; |
| 113 | + }; |
| 114 | + |
| 115 | + fail_fast = mkOption { |
| 116 | + type = types.bool; |
| 117 | + description = lib.mdDoc '' |
| 118 | + if true pre-commit will stop running hooks if this hook fails. |
| 119 | + ''; |
| 120 | + default = false; |
| 121 | + }; |
| 122 | + |
| 123 | + require_serial = mkOption { |
| 124 | + type = types.bool; |
| 125 | + description = lib.mdDoc '' |
| 126 | + if true this hook will execute using a single process instead of in parallel. |
| 127 | + ''; |
| 128 | + default = false; |
| 129 | + }; |
| 130 | + |
| 131 | + stages = mkOption { |
| 132 | + type = types.listOf types.str; |
| 133 | + description = lib.mdDoc '' |
| 134 | + Confines the hook to run at a particular stage. |
| 135 | + ''; |
| 136 | + default = cfg.default_stages; |
| 137 | + defaultText = (lib.literalExpression or lib.literalExample) "default_stages"; |
| 138 | + }; |
| 139 | + |
| 140 | + verbose = mkOption { |
| 141 | + type = types.bool; |
| 142 | + default = false; |
| 143 | + description = lib.mdDoc '' |
| 144 | + forces the output of the hook to be printed even when the hook passes. |
| 145 | + ''; |
| 146 | + }; |
| 147 | + |
| 148 | + always_run = mkOption { |
| 149 | + type = types.bool; |
| 150 | + default = false; |
| 151 | + description = lib.mdDoc '' |
| 152 | + if true this hook will run even if there are no matching files. |
| 153 | + ''; |
| 154 | + }; |
| 155 | + }; |
| 156 | +} |
0 commit comments