Skip to content

implement granular style formatting#85

Merged
vic merged 4 commits intovic:mainfrom
musjj:formatting
Mar 10, 2026
Merged

implement granular style formatting#85
vic merged 4 commits intovic:mainfrom
musjj:formatting

Conversation

@musjj
Copy link
Contributor

@musjj musjj commented Mar 10, 2026

Implement granular style formatting options, giving users the level of editorial control close to what they'd get with handwritten Nix.

This PR introduces two new styling options:

  • Separator between attributes:

    With a standard \n:

    {
      inputs = ...;
      outputs = ...;
    }

    With \n\n:

    {
      inputs = ...;
    
      outputs = ...;
    }
  • Sorting priority of attributes

    This allows certain attribute names to be prioritized when they are sorted. For example, let's say we have the following list:

    [
      "dog"
      "cat"
      "zebra"
      "ant"
      "walrus"
    ]

    We want to alphabetically sort it, but we want to prioritize the following names and make sure they stay at the top: [ "zebra" "moose" "dog" ] (not all names have to be present). The rest should just be alphabetically sorted.

    When that rule is applied to the list, we will get:

    [
      "zebra"
      "dog"
      "ant"
      "cat"
      "walrus"
    ]

To support these new styling options, the nixCode function now accepts a list of style options, each of which will be applied to each corresponding recursive call. This gives us the ability to apply different styles on each each level of depth within an expression.

The power of this feature is best seen when styling inputs attributes, because we want to be able to apply different styles on the top-level inputs attributes (e.g. inputs = { nixpkgs = ...; }) and the attributes inside each input (e.g. nixpkgs = { url = ...; }).

These styling rules can be user-customized on the level of:

  • Flake attributes
  • inputs attributes
  • Schema attributes inside each input
  • nixConfig attributes

The former default style is mostly preserved, with the exception of the way input schema attributes are sorted.

Fix: #80

@musjj musjj force-pushed the formatting branch 2 times, most recently from e82b870 to 4a94126 Compare March 10, 2026 20:13
@vic
Copy link
Owner

vic commented Mar 10, 2026

Hey @musjj, thanks a lot for implementing this :) we have CI failures.

@vic
Copy link
Owner

vic commented Mar 10, 2026

@musjj let's do something, send another PR touching docs/README.md add a new line or anything, so that you are contributor to the repo and then any other push you make to this gets automatically picker without me approving CI pipelines. This for not slowing you down.

@musjj
Copy link
Contributor Author

musjj commented Mar 10, 2026

Here: #86

@vic
Copy link
Owner

vic commented Mar 10, 2026

On you might need to run nix develop ./dev -c regen

@vic
Copy link
Owner

vic commented Mar 10, 2026

Added an issue for a Justfile #87 like we have in Den but here we should be running those ./dev apps.

@vic
Copy link
Owner

vic commented Mar 10, 2026

Awesome! CI is green, can you just update docs/ for new options and I think we are good

EDIT: It is ok if you only mention the options and provide a link to the nix file defining them. Or document what each option is for, as you choose. We need documentation for feature visibility.

@vic
Copy link
Owner

vic commented Mar 10, 2026

Wonderful! thanks so much for all this, @musjj 👏

I'm merging this.

@vic vic merged commit 1f95f96 into vic:main Mar 10, 2026
11 checks passed
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.

Add options to control the formatting

2 participants