cachix/git-hooks.nix

Default value for `denofmt` and `denolint` is invalid.

jaredponn opened this issue · 1 comments

The denotfmt and denolint hooks allow one to provide an ostensibly optional path to a configuration file.

If it is not provided, it will default to "" (empty string), which is not a path, so building the nix derivation will fail.

Relevant lines
https://github.com/cachix/pre-commit-hooks.nix/blob/e558068cba67b23b4fbc5537173dbb43748a17e8/modules/hooks.nix#L304-L309

https://github.com/cachix/pre-commit-hooks.nix/blob/e558068cba67b23b4fbc5537173dbb43748a17e8/modules/hooks.nix#L321-L326

A quick fix would be as follows

diff --git a/modules/hooks.nix b/modules/hooks.nix
index e7bba8a..dc0cb9a 100644
--- a/modules/hooks.nix
+++ b/modules/hooks.nix
@@ -302,8 +302,8 @@ in
 
           configPath =
             mkOption {
-              type = types.path;
-              description = lib.mdDoc "path to the configuration JSON file";
+              type = types.str;
+              description = lib.mdDoc "Path to the configuration JSON file";
               # an empty string translates to use default configuration of the
               # underlying deno binary (i.e deno.json or deno.jsonc)
               default = "";
@@ -319,7 +319,7 @@ in
             };
           configPath =
             mkOption {
-              type = types.path;
+              type = types.str;
               description = lib.mdDoc "Path to the configuration JSON file";
               # an empty string translates to use default configuration of the
               # underlying deno binary (i.e deno.json or deno.jsonc)

Minimal non working example

Consider the following project

$ ls
default.nix  Test.ts
$ cat default.nix
 let
   nix-pre-commit-hooks = import (builtins.fetchTarball "https://github.com/cachix/pre-commit-hooks.nix/tarball/master");
 in {
   pre-commit-check = nix-pre-commit-hooks.run {
     src = ./.;
     # If your hooks are intrusive, avoid running on each commit with a default_states like this:
     # default_stages = ["manual" "push"];
     hooks = {
       denolint.enable = true;
       denofmt.enable = true;
     };

     # Some hooks offer custom settings that affect how they execute
     settings = {
     };
   };
 }

$ cat Test.ts
let a   = 0 as any;

Then, run

$ nix-build -A pre-commit-check
error: A definition for option `settings.denofmt.configPath' is not of type `path'. Definition values:
       - In `/nix/store/r3fwfc0mqqzz18z0630dn98c8slwb5vk-source/modules/hooks.nix': ""
(use '--show-trace' to show detailed location information)

and we see that the derivation cannot be built.

Thanks @fufexan for fixing this in #377. I really appreciate it!