Skip to content

stylua: drop the stylua wrapper package - #9876

Open
rachitvrma wants to merge 1 commit into
nix-community:masterfrom
rachitvrma:module/stylua
Open

rachitvrma wants to merge 1 commit into
nix-community:masterfrom
rachitvrma:module/stylua

Conversation

@rachitvrma

Copy link
Copy Markdown
Member

Description

Many formatters use default flags (for example conform.nvim uses the --search-parent-directories by default. Using the wrapper package, breaks it, since the flag is being passed twice). Instead of passing the flag in a wrapper, we provide the information on how to use it in the description.

Checklist

  • Change is backwards compatible.

  • Code formatted with nix fmt or
    nix-shell -A dev --run treefmt.

  • Code tested through nix build .#test-all
    or a targeted nix run .#tests -- <pattern>.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.
    • Generate a news entry. See News
    • Basic tests added. See Tests
  • If this PR adds an exciting new feature or contains a breaking change.

    • Generate a news entry. See News

@rachitvrma
rachitvrma requested a review from khaneliman August 29, 2026 20:25

@khaneliman khaneliman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down. I reproduced it with StyLua 2.6.0: passing --search-parent-directories twice exits with an error, and conform.nvim passes the flag by default, so dropping the wrapper makes sense to me.

I left two requests inline, plus an optional suggestion for a news entry. Could you also change the commit subject prefix from module/stylua: to stylua:, to match the commit format?

cfg.package;
in
{
meta.maintainers = [ lib.maintainers.rachitvrma ];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): Removing finalPackage breaks configurations that read it. The option was hidden, but at least one public configuration adds config.programs.stylua.finalPackage to a package list, and with this change that fails with only error: attribute 'finalPackage' missing. I think we should keep the removal and declare it, so those users are told what to change, in line with the backward compatibility guideline:

Suggested change
meta.maintainers = [ lib.maintainers.rachitvrma ];
meta.maintainers = [ lib.maintainers.rachitvrma ];
imports = [
(lib.mkRemovedOptionModule [ "programs" "stylua" "finalPackage" ] ''
Home Manager no longer wraps StyLua. Use `programs.stylua.package`
instead, and pass `--search-parent-directories` if the command should
read the generated configuration file.
'')
];

I tested this on top of your commit with a configuration that reads the old option. Evaluation still stops, but now with "The option programs.stylua.finalPackage' can no longer be used since it's been removed." followed by the text above. stylua-empty-configandstylua-example-config` still pass.

Comment thread modules/programs/stylua.nix Outdated

options.programs.stylua = {
enable = mkEnableOption "stylua, a formatter for lua";
package = mkPackageOption pkgs "stylua" { };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The new cfg.package != null check in home.packages can never be false, because this option still only accepts a package. Setting programs.stylua.package = null fails with "A definition for option programs.stylua.package' is not of type package'". Now that nothing wraps the package, the module works without installing StyLua, so I think making the option nullable is the right way to finish this:

Suggested change
package = mkPackageOption pkgs "stylua" { };
package = mkPackageOption pkgs "stylua" { nullable = true; };

With this applied, I built a configuration that sets package = null together with settings: stylua.toml is still generated and StyLua is not added to home.packages.

description = ''
Configuration options that are written to {file}`XDG_CONFIG_HOME/stylua/stylua.toml`
Configuration options that are written to {file}`XDG_CONFIG_HOME/stylua/stylua.toml`.
To use this configuration file pass the `--search-parent-directories` flag to `stylua`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): This also changes behavior for people who already set settings and run stylua directly, or through a tool that does not add the flag. With StyLua 2.6.0 in a project without its own stylua.toml, stylua - ignores $XDG_CONFIG_HOME/stylua/stylua.toml and formats with the defaults. It only reads that file with --search-parent-directories. Nothing fails, so a rebuild will not tell them. Could we add a news entry for it? nix run .#create-news-entry creates the file, and this condition limits it to the affected users:

condition = config.programs.stylua.enable && config.programs.stylua.settings != { };

I checked that this condition is true with settings set and false with the default empty settings.

Many formatters use default flags (for example `conform.nvim` uses the
`--search-parent-directories` by default. Using the wrapper package,
breaks it, since the flag is being passed twice). Instead of passing the
flag in a wrapper, we provide the information on how to use it in the
description.
@rachitvrma rachitvrma changed the title module/stylua: drop the stylua wrapper package stylua: drop the stylua wrapper package Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants