You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(nix_flake_fmt): handle flakes with a formatter package
nixpkgs [recently add a `nix fmt` entrypoint](NixOS/nixpkgs@374e6bc),
and I was excited to be able to use `nix_flake_fmt` in the project.
I was disappointed to find that it doesn't actually work in nixpkgs,
though :(
The problem boils down to how `nix eval .#formatter` behaves if your
flake defines a `formatter` package. See:
```console
$ nix eval nixpkgs#formatter
«derivation /nix/store/nadgq8kci2an9d3ddz1lk662gl53d8yz-formatter-0.4.0.drv»
```
This is *not* the `nix fmt` entrypoint, it's a [completely unrelated
package](NixOS/nixpkgs@b99357e).
Here's the `nix fmt` entrypoint:
```console
$ nix repl nixpkgs
nix-repl> formatter.x86_64-linux
«derivation /nix/store/rza8g2jxr1h7nd58qq3ryfz2zdqnggga-treefmt.drv»
```
This simple `nix repl` session is quite challenging to port to `nix eval`,
though. After quite a bit of futzing around, I found that I could accomplish
this with a combination of `nix flake metadata` and `builtins.getFlake`:
```
$ nix flake metadata nixpkgs --json | jq .resolvedUrl
"github:NixOS/nixpkgs/nixpkgs-unstable"
$ nix eval --expr "(builtins.getFlake "github:NixOS/nixpkgs/nixpkgs-unstable").formatter.x86_64-linux" --impure
«derivation /nix/store/rza8g2jxr1h7nd58qq3ryfz2zdqnggga-treefmt.drv»
```
0 commit comments