Skip to content

feat: update pre-commit.nix to be "run" customizable #494

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
merged 2 commits into from
Mar 1, 2025

Conversation

kakkun61
Copy link
Contributor

@kakkun61 kakkun61 commented Sep 3, 2024

What is this

This make options.run's readOnly true.

And configFile and installStages will be public so that a customized run may use them.

Why is this

For instance a repository having Git submodules will use additional flake inputs which is the same with the submodules.

$ git submodule add … foo
{ inputs.foo.url = "…";;
  outputs = { self, foo, ... }: {
    # build or do something after storing foo contents to ./foo
    # like: preBuild = "ln -s ${submodules.otlp-protobufs}/* -t proto";
  };
}

In this case we want to customize run to store foo before running pre-commit command similarly like:

git-hooks.lib.${system}.run {
  src = ./.;
  hooks = pre-commit-hooks;
  imports = [
    ({ config, lib, pkgs, ... }: {
      run = pkgs.runCommand "pre-commit-run" {buildInputs = [pkgs.git config.package];} ''
        set +e
        HOME=$PWD
        cp -R ${config.rootSrc} src
        chmod -R +w src
        ln -fs ${config.configFile} src/.pre-commit-config.yaml
        # 👇 Inserted
        mkdir src/foo
        ln -s ${foo}/* -t src/foo
        # 👆
        cd src

      '';
    })
  ];
};

This change supports more complex use cases.

@sandydoo sandydoo merged commit b6ee9db into cachix:master Mar 1, 2025
6 checks passed
@kakkun61 kakkun61 deleted the customizable-run branch March 1, 2025 17:06
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.

2 participants