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: update pre-commit.nix to be "run" customizable #494

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kakkun61
Copy link

@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.

@kakkun61 kakkun61 marked this pull request as ready for review September 4, 2024 03:57
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.

1 participant