Skip to content

Fix formatter laziness and add touchups module#289

Open
roberth wants to merge 3 commits intomainfrom
formatter-and-touchups
Open

Fix formatter laziness and add touchups module#289
roberth wants to merge 3 commits intomainfrom
formatter-and-touchups

Conversation

@roberth
Copy link
Copy Markdown
Member

@roberth roberth commented May 27, 2025

This PR is a two-parter by necessity, as the goal is to address

Unfortunately Nix puts us between a rock and a hard place, and we need more flexibility to deal with possible fallout, hence the new touchup feature.

1. Strictness problem

To put it briefly, filterAttrs induces strictness, but we need it to remove nulls which nix flake check does not allow.
Analyzing perSystem is tricky, but doesn't seem to be much of a problem in this particular case, at least in my testing.

2. touchup module

This might be kind of exciting actually.

It adds a little attribute-based DSL that makes it easy to make alterations to the flake outputs.
A presentation layer of sorts, bridging the normally small gap between Nix-as-programming and Nix-as-data.

Actually it's not attribute-based but (deferred) module based, as illustrated by the last example in extras/touchup.nix, which is the file that serves as the introduction (will be published on flake.parts of course).

... avoid broken attributes in cases where we can predict that
we don't have any.

This is far from ideal, but it's the best we can do.
If it becomes a shit show, flake authors can opt out.
@roberth
Copy link
Copy Markdown
Member Author

roberth commented May 27, 2025

Fortunately this solves the last occurrence of filterAttrs that actually processes any kind of input data, indicating it's the last strictness problem of its kind 🎉

The last remaining filterAttrs processes an option whose value belongs to the types / schema / metadata realm.

@roberth roberth force-pushed the formatter-and-touchups branch from 0b1016f to ac5c43f Compare May 27, 2025 14:01
@roberth
Copy link
Copy Markdown
Member Author

roberth commented May 27, 2025

Rendered docs

@srid
Copy link
Copy Markdown
Contributor

srid commented May 27, 2025

While doesn't seem identical, this reminds me of #114

image

@roberth
Copy link
Copy Markdown
Member Author

roberth commented May 28, 2025

@srid I see. Auto-wiring controls can have a similar effect, but their effect is on the internal option values, whereas this is specifically for flake outputs.
They also have unique capabilities:

Auto-wiring:

  • resolve conflicts between modules that e.g. both want to set devShell.default
  • keep it simple by doing less

Touchup:

  • set or remove arbitrary output attributes without affecting the internals
  • drop unused attributes caused by built-in options or transitive dependencies (without making the internals fail)

Auto-wiring controls are a preferable solution, but touchups can solve some long-tail issues without having to model each and every quirk with more flags.
Added a little note: hercules-ci/flake.parts-website@560c031

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