Skip to content

fix: add configFile option #496

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

Merged

Conversation

diefans
Copy link
Contributor

@diefans diefans commented Sep 26, 2024

This fixes #345, by adding a configFile option to change the default (.pre-commit-config.yaml) and so enables the parallel usage of devenv and non-devenv maintained pre-commit hooks.

@sandydoo sandydoo added the enhancement New feature or request label Oct 10, 2024
@sandydoo
Copy link
Member

  1. There are a few more pre-commit calls in run that would need to be adjusted.
    run =
    runCommand "pre-commit-run" { buildInputs = [ git ]; } ''
    set +e
    HOME=$PWD
    # Use `chmod +w` instead of `cp --no-preserve=mode` to be able to write and to
    # preserve the executable bit at the same time
    cp -R ${cfg.rootSrc} src
    chmod -R +w src
    ln -fs ${configFile} src/.pre-commit-config.yaml
    cd src
    rm -rf .git
    git init -q
    git add .
    git config --global user.email "[email protected]"
    git config --global user.name "Your Name"
    git commit -m "init" -q
    if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]]
    then
    echo "Running: $ pre-commit run --hook-stage manual --all-files"
    ${cfg.package}/bin/pre-commit run --hook-stage manual --all-files
    else
    echo "Running: $ pre-commit run --all-files"
    ${cfg.package}/bin/pre-commit run --all-files
    fi
    exitcode=$?
    git --no-pager diff --color
    mkdir $out
    [ $? -eq 0 ] && exit $exitcode
    '';
  2. I'm not sure about the name of the option. We may also need to expose configFile itself in the future, e.g. feat: update pre-commit.nix to be "run" customizable #494. Maybe configPath would be better?

This fixes cachix#345, by adding a `configFile` option to change the default
(`.pre-commit-config.yaml`) and so enables the parallel usage of devenv
and non-devenv maintained pre-commit hooks.
@diefans
Copy link
Contributor Author

diefans commented Jan 15, 2025

@sandydoo ...I am full of work at the moment, but this topic is not forgotten!

@willfish
Copy link
Contributor

This is a make or break option for me at work since I work with pre-existing pre-commit configuration and I can't just delete/.gitignore that. I'm using flakes in about 10 repos that I can just add this tooling for and make my life a bunch easier

@sandydoo sandydoo mentioned this pull request Mar 1, 2025
@sandydoo sandydoo merged commit 37eb734 into cachix:master Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[question] Can I use this to override a hook while leaving pre-commit-hooks.yaml alone for my non-nix-using colleagues?
3 participants