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

Add docs, examples for overriding provided hooks #2

Closed
domenkozar opened this issue Aug 16, 2019 · 10 comments · Fixed by #19
Closed

Add docs, examples for overriding provided hooks #2

domenkozar opened this issue Aug 16, 2019 · 10 comments · Fixed by #19
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@domenkozar
Copy link
Member

domenkozar commented Aug 16, 2019

Something like:

nix-pre-commit-hooks.run {
  src = gitignoreSource ./.;
  hooks = ["shellcheck"];
}
@roberth
Copy link
Contributor

roberth commented Aug 16, 2019

I'd be perfectly happy to require the YAML to be JSON and DRY it with builtins.fromJSON.
(as an alternative, not everyone likes JSON)

@roberth
Copy link
Contributor

roberth commented Aug 16, 2019

Even better: generate a YAML from with builtins.toJSON. Best: use the module system.

@domenkozar domenkozar changed the title Allow filtering which hooks to provide Allow filtering and overriding which hooks to provide Aug 19, 2019
@roberth roberth added the enhancement New feature or request label Sep 3, 2019
@domenkozar domenkozar changed the title Allow filtering and overriding which hooks to provide Allow filtering and overriding provided hooks Sep 3, 2019
@roberth
Copy link
Contributor

roberth commented Sep 8, 2019

If this is about download size, I wrote a thing https://github.com/roberth/nix-lazy-env

@domenkozar
Copy link
Member Author

Nice! Yes, partially it's about the download size and partially it's for providing additional hooks.

@domenkozar
Copy link
Member Author

This seems nice and simple: https://github.com/kampka/pre-commit-hooks

roberth added a commit that referenced this issue Sep 25, 2019
New
 - Selectively enable tools (#2)
 - Make choice of tool versions overridable
 - User-definable hooks
 - Input validation at the Nix level

Fixes
 - Stop installing files all over the place when doing nix-shell ../some-project to borrow a tool

Cleanup
 - Get rid of installation code
roberth added a commit that referenced this issue Sep 25, 2019
New
 - Selectively enable tools (#2)
 - Make choice of tool versions overridable
 - User-definable hooks
 - Input validation at the Nix level

Fixes
 - Stop installing files all over the place when doing nix-shell ../some-project to borrow a tool
 - Lorri support

Cleanup
 - Get rid of installation code
@roberth roberth mentioned this issue Sep 25, 2019
5 tasks
bors bot added a commit that referenced this issue Oct 2, 2019
19: Use the module system r=roberth a=roberth

Closes #2
Closes #17 

TODO
 - [x] ~expose and test "core" module set from project.nix~
 - [x] ~niv update -b master project.nix when that's done (hercules-ci/project.nix#10
 - [x] changelog entry: (elaborate on) translate `.pre-commit-config.yaml` to hooks argument
 - [x] update README
 - [x] add how to add a hook to README

New
 - Selectively enable tools (#2)
 - Make choice of tool versions overridable
 - User-definable hooks
 - Input validation at the Nix level
 - Use gitignore by default

Fixes
 - Stop installing files all over the place when doing nix-shell ../some-project to borrow a tool
 - Lorri support

Cleanup
 - Get rid of some installation code

Co-authored-by: Robert Hensing <[email protected]>
@domenkozar domenkozar reopened this Oct 2, 2019
@domenkozar
Copy link
Member Author

Let's leave this one open as it needs some examples in the docs.

@roberth roberth changed the title Allow filtering and overriding provided hooks Add docs, examples for overriding provided hooks Oct 2, 2019
@timokau
Copy link

timokau commented Mar 20, 2020

For what it's worth, I came up with this config to run the black python code formatter:

let
  nix-pre-commit-hooks = import (builtins.fetchTarball "https://github.com/cachix/pre-commit-hooks.nix/tarball/master");
  pkgs = import <nixpkgs> {};
in {
  pre-commit-check = nix-pre-commit-hooks.run {
    src = ./.;
    hooks = {
      shellcheck.enable = true;
      black = {
        enable = true;
        name = "black";
        description = "Format Python files";
        entry = "${pkgs.python3.pkgs.black}/bin/black --check";
        types = ["python"];
      };
    };
  };
}

That could probably be used as an example. I'm wondering: Why do you use the module-system here? Wouldn't it be easier and more convenient to just use a list of attrsets, with some attrsets pre defined?

@domenkozar
Copy link
Member Author

I'll let that @roberth answer, I was also more for simple design of attrsets and defaults.

@roberth
Copy link
Contributor

roberth commented Mar 20, 2020

With the module system you get

  • type checking, improving error messages
  • a framework for documentation
  • configurations merging and overrides, so you can have defaults for your team for example

@domenkozar
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants