Skip to content

maintainers/scripts: format with treefmt config - #554512

Merged
wolfgangwalther merged 2 commits into
NixOS:masterfrom
MattSturgeon:haskell-script-inputs
Oct 12, 2026
Merged

wolfgangwalther merged 2 commits into
NixOS:masterfrom
MattSturgeon:haskell-script-inputs

Conversation

@MattSturgeon

@MattSturgeon MattSturgeon commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Followup to #554040 (comment)
Prior art: 37aac0f

Scripts should avoid running formatters directly. If possible, we should always use treefmt as configured by CI.

  1. The nixfmt used may be a different version to the one pinned by CI
  2. Nixpkgs' treefmt applies multiple formatting tools on *.nix files
  3. Nixpkgs' treefmt applies non-default config to some formatting tools

One way to handle this would be to have multiple chained nix-shell shebangs, however that's a little messy and also makes enabling --pure a bit awkward.
A more robust approach, recommended by #425551, is to use an explicit mkShell expression via nix-shell's -E flag.
In addition to allowing arbitrary expressions like (import ../../ci {}).fmt.pkg, another major advantage of -E 'import ../.. {} over -I nixpkgs=. is that paths resolve consistently regardless of where the script is run from; -I resolves relative to the CWD, while -E resolves relative to the script file.

Things done

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: haskell General-purpose, statically typed, purely functional programming language labels Aug 19, 2026

@wolfgangwalther wolfgangwalther left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This SGTM, but I'd like to have @sternenseemann have a look in case I missed something in my earlier reasoning about this change.

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 20, 2026
@MattSturgeon

Copy link
Copy Markdown
Contributor Author

@sternenseemann any chance you can take a look?

@wolfgangwalther

Copy link
Copy Markdown
Contributor

It's annoying enough for me to have to start up a new nix-shell with nixfmt every time I want to regenerate hackage packages ever since nixfmt is not available in the nixpkgs dev shell anymore. So let's do this and if a problem is reported later, we can always fix / switch again.

@wolfgangwalther
wolfgangwalther added this pull request to the merge queue Oct 12, 2026
Merged via the queue into NixOS:master with commit 29cb158 Oct 12, 2026
33 of 35 checks passed
@MattSturgeon
MattSturgeon deleted the haskell-script-inputs branch October 12, 2026 07:15
@maralorn maralorn mentioned this pull request Oct 26, 2026
13 tasks
@wolfgangwalther

Copy link
Copy Markdown
Contributor

As mentioned in #578893 (comment), this broke the script for Lix. So we will have to do this differently...

@wolfgangwalther

Copy link
Copy Markdown
Contributor

As mentioned in #578893 (comment), this broke the script for Lix. So we will have to do this differently...

Fixed in #581707

@maralorn

maralorn commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

My fix does not cover maintainers/scripts/update-ruby-packages which is also affected by this change. We might want to also do that. Not sure who to ping about that.

Shawn8901 pushed a commit to Shawn8901/nixpkgs that referenced this pull request Nov 1, 2026
…nd_ lix

Running these scripts with lix has regressed in NixOS#554512
This is because nix changed the way it resolves relative imports after lix was forked.

This PR uses an import method which behaves identically on nix and lix.

AI Disclaimer: I typed and tested all of this myself but an LLM helped me debug and suggest the solution.
magicquark pushed a commit to magicquark/nixpkgs that referenced this pull request Nov 3, 2026
…nd_ lix

Running these scripts with lix has regressed in NixOS#554512
This is because nix changed the way it resolves relative imports after lix was forked.

This PR uses an import method which behaves identically on nix and lix.

AI Disclaimer: I typed and tested all of this myself but an LLM helped me debug and suggest the solution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: haskell General-purpose, statically typed, purely functional programming language 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants