Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(run.nix): expose more #512

Merged
merged 1 commit into from
Oct 13, 2024
Merged

Conversation

sivizius
Copy link
Contributor

With this PR, the derivation returned by git-hooks.lib.${system}.run { … } contains the attribute config, which can be used to get the configured pre-commit-hooks. I.e. t is now possible to use the result both in the flake-outputs as e.g. checks = { inherit pre-commit-hooks; }; as well as apps = fooBar pre-commit-hooks.config.hooks, where fooBar extracts all entries of enabled hooks so e.g. nix run clippy would be possible using the same CLI-options as the checks.pre-commit-hooks.

If there already was a way to access these processed hooks, please document it, because I could not find a way myself.

@trueNAHO
Copy link
Contributor

trueNAHO commented Oct 11, 2024

If there already was a way to access these processed hooks, please document it, because I could not find a way myself.

Does a self access resolve this:

checks.git-hooks = inputs.git-hooks.lib.${system}.run {};
apps.default = self.checks.${system}.git-hooks;

However, I agree that being able to access the internal hooks values would be a great feature addition.

For example, my LaTeX flake requires me to wrap hooks.latexindent.package in hooks.latexindent.entry because I need to be able to evaluate the "$(mktemp --directory)" subshell, which is impossible with just entry = "<COMMAND> $(<SUB_COMMAND>)'":

checks.git-hooks = inputs.git-hooks.lib.${system}.run {
  hooks.latexindent = {
    enable = true;

    entry = lib.getExe (
      pkgs.writeShellApplication {
        name = "git-hooks-latexindent-entry";

        text = ''
          ${
            lib.getExe'
            (
              # Re-implement and re-evaluate hooks.latexindent.package.
              pkgs.texlive.combine {
                inherit (pkgs.texlive) latexindent scheme-minimal;
              }
            )
            "latexindent"
          } ${
            lib.cli.toGNUCommandLineShell {} {
              logfile = toString /dev/null;
              overwriteIfDifferent = true;
              silent = true;
            }
          } --cruft "$(mktemp --directory)" "$@"
        '';
      }
    );
  };

  src = ./.;
};

Accessing the package through something like hooks.latexindent.package would be more convenient and would even benefit from the performance optimization from #513.

@sivizius
Copy link
Contributor Author

Does a self access resolve this:

checks.git-hooks = inputs.git-hooks.lib.${system}.run {};
apps.default = self.checks.${system}.git-hooks;

Not really. This would just avoid running all checks and would allow formatters to apply changes, but I like to run certain hooks, e.g. nix run .#clippy, which is not possible with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants