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

Move to new module structure #397

Merged
merged 26 commits into from
Mar 19, 2024
Merged

Move to new module structure #397

merged 26 commits into from
Mar 19, 2024

Conversation

sandydoo
Copy link
Member

@sandydoo sandydoo commented Feb 10, 2024

Tackles #196.

Tasks

  • Move hook settings from options.settings.<name> to options.hooks.<name>.settings
  • Add package to the hook module
  • Add default packages to each hook (see issues)
  • Migrate non-hook settings, i.e. settings.rust.
  • Add a description to every hook setting
  • Use lib.mkDefault on hook definitions to make overrides easier
  • Migrate any hooks.<name>.settings.package to hooks.<name>.package.
  • Verify generated docs. nix build .#checks.<system>.doc-check.

Out of scope

  • Remove tools? Breaking change 🤔
  • Expose helpers to get all active hooks and their packages
  • Add all hooks to options.hooks so that they appear in the docs.

Issues to tackle

  • Some hooks depend on a custom, more complex package. These are difficult to override.

    • rustftm
    • clippy
    • treefmt
      The `treefmt` package to use.
      
      Should include all the formatters configured by treefmt.
      
      For example:
      ```nix
      pkgs.writeShellApplication {
        name = "treefmt";
        runtimeInputs = [
          pkgs.treefmt
          pkgs.nixpkgs-fmt
          pkgs.black
        ];
        text =
          '''
            exec treefmt "$@"
          ''';
      }
      
  • Many hooks have adopted binPath in lieu of package. Should these be deprecated and migrated to package?
    Here's an interesting case: you can provide a path to the local node_modules folder instead.

    "eslint binary path. E.g. if you want to use the eslint in node_modules, use ./node_modules/.bin/eslint.";

    Solved: I've kept binPath around, but set it to null by default. Hooks will use binPath if it's set, but otherwise default to package.

  • There is a special options.settings.rust option that is shared amongst some hooks. It's not a hook itself. We need to define the module type for options.settings.
    Solved: moved to options.settings.rust.

  • Some packages already use package as a setting. Need to migrate these.
    Solved: renamed and deprecated.

  • mkRenamedOptionModule isn't showing any warnings. Is it because of the submodules?
    Solved: added assertions/warnings handling

Misc fixes

  • credo: pass the strict flag when credo.settings.strict is enabled.

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

sandydoo commented Feb 11, 2024

cc @domenkozar @roberth

Here's where we're currently at:

{
  hooks.ormolu.enable = true;
  hooks.ormolu.package = pkgs.ormolu.override { ... }; # still need to add lib.mkDefault everywhere
  hooks.ormolu.settings.defaultExtensions = [ "lhs" "hs" ];
}

What else do we want to include here? I've outlined what needs to get done above, but there are some bits I don't fully understand, like the non-pre-commit hook stuff.

@domenkozar
Copy link
Member

Many hooks have adopted binPath in lieu of package. Should these be deprecated and migrated to package?

There's lib.getExe that should be used instead.

@domenkozar
Copy link
Member

There is a special options.settings.rust option that is shared amongst some hooks. It's not a hook itself. We need to define the module type for options.settings.

These should be reused by all the hooks that use rust bits.

@sandydoo
Copy link
Member Author

Many hooks have adopted binPath in lieu of package. Should these be deprecated and migrated to package?

There's lib.getExe that should be used instead.

Nice! Does that always work?

What should we do with hooks like this? It's suggesting to set a local path. Should all hooks be able to override the path to the binary? Is package perhaps not a good enough abstraction for some hooks?

"eslint binary path. E.g. if you want to use the eslint in node_modules, use ./node_modules/.bin/eslint.";

@domenkozar
Copy link
Member

🥳 🥳 🥳

@domenkozar
Copy link
Member

NixOS/nixpkgs#96006

@domenkozar
Copy link
Member

Looks good to me. Do we need some kind of migration guide or will the warnings system take care of it all (minus the bugs)?

@sandydoo
Copy link
Member Author

Do we need some kind of migration guide or will the warnings system take care of it all (minus the bugs)?

A good idea either way!

@domenkozar, what do you think of this fee04a7?
The clippy and rustfmt hooks fit this pattern, but the treefmt one feels a little weird. Maybe we should define hooks.treefmt.settings.formatters = [ pkgs.nixfmt ]?

@domenkozar
Copy link
Member

Nice :) let's ship this.

@sandydoo sandydoo marked this pull request as ready for review March 18, 2024 22:51
@nifoc
Copy link

nifoc commented Mar 19, 2024

I think this PR is causing the following issue (specifically with the flake.parts module?):

trace: warning: The option `settings.treefmt.package' defined in `/nix/store/wgw700x1vzpjxak25kkd3s2fk3k6x5m7-source/flake-module.nix' has been renamed to `hooks.treefmt.package'.
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'dotfiles'
         whose name attribute is located at /nix/store/89f8hv2f5yw79zjnbrvibsdmqsnndl97-source/pkgs/stdenv/generic/make-derivation.nix:331:7

       … while evaluating attribute '__impureHostDeps' of derivation 'dotfiles'

         at /nix/store/89f8hv2f5yw79zjnbrvibsdmqsnndl97-source/pkgs/stdenv/generic/make-derivation.nix:443:7:

          442|       __propagatedSandboxProfile = unique (computedPropagatedSandboxProfile ++ [ propagatedSandboxProfile ]);
          443|       __impureHostDeps = computedImpureHostDeps ++ computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps ++ __impureHostDeps ++ stdenv.__extraImpureHostDeps ++ [
             |       ^
          444|         "/dev/zero"

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: The option `perSystem.aarch64-darwin.pre-commit.settings.hooks.treefmt.package' is defined multiple times while it's expected to be unique.

       Definition values:
       - In `/nix/store/wgw700x1vzpjxak25kkd3s2fk3k6x5m7-source/modules/hooks.nix': <derivation treefmt>
       - In `/nix/store/wgw700x1vzpjxak25kkd3s2fk3k6x5m7-source/modules/hooks.nix': <derivation treefmt>
       Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.

@sandydoo
Copy link
Member Author

I think this PR is causing the following issue (specifically with the flake.parts module?):

@nifoc, thanks, will fix

@roberth
Copy link
Contributor

roberth commented Mar 27, 2024

Damn, I didn't see the ping.

What happened to enable?

I'm getting error: The option `enable' does not exist. on https://hercules-ci.com/github/hercules-ci/hercules-ci-agent/jobs/2871

@domenkozar
Copy link
Member

@sandydoo do you know?

@sandydoo
Copy link
Member Author

sandydoo commented Apr 1, 2024

Not sure I understand where the error is coming from. Like the per-hook enable? It should be there 🤷

@roberth
Copy link
Contributor

roberth commented Apr 1, 2024

@sandydoo I figured it out yesterday: I forgot that I was merging some code of my own into the hook module.
With this I can make it work again: #422

sandydoo added a commit that referenced this pull request Dec 15, 2024
- Remove `before` and `after` from the `raw` config. These are not valid
  pre-commit configuration options and should not be here.
- Remove code to filter out `before` and `after` from the `raw` config.
- Expose the `id` inside the hook to make it easier to reference and
  sort.
- Set `id` to the attr name of the hook, instead of the `name`. This
  corrects a mistake make in the module transition (#397). Technically,
  a breaking change, but we haven't seen feedback on the initial
  mistake.
sandydoo added a commit that referenced this pull request Dec 15, 2024
- Remove `before` and `after` from the `raw` config. These are not valid
  pre-commit configuration options and should not be here.
- Remove code to filter out `before` and `after` from the `raw` config.
  This is not needed if they're not in the config in the first place.
- Expose the `id` inside the hook to make it easier to reference and
  sort.
- Set `id` to the attr name of the hook, instead of the `name`. This
  corrects a mistake made in the module transition (#397). Technically,
  a breaking change, but we haven't had feedback from the initial
  mistake.
sandydoo added a commit that referenced this pull request Dec 15, 2024
Consolidates previous work from #533 and #536.

- Removes `before` and `after` from the `raw` config. These are not valid
  pre-commit configuration options and should not be here.
- Removes code to filter out `before` and `after` from the `raw` config.
  There's nothing to filter out if they're not in the config in the
  first place.
- Set `id` to the attr name of the hook, instead of the `name`. This
  corrects a mistake made in the module transition (#397). Technically,
  a breaking change, but we haven't had feedback from the initial
  mistake.
- Expose `id` in options.
sandydoo added a commit that referenced this pull request Dec 15, 2024
Consolidates previous work from #533 and #536.

- Removes `before` and `after` from the `raw` config. These are not valid
  pre-commit configuration options and should not be here.
- Removes code to filter out `before` and `after` from the `raw` config.
  There's nothing to filter out if they're not in the config in the
  first place.
- Set `id` to the attr name of the hook, instead of the `name`. This
  corrects a mistake made in the module transition (#397). Technically,
  a breaking change, but we haven't had feedback from the initial
  mistake.
- Expose `id` in options.
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.

4 participants