`nix fmt` does not work `Error: path . not inside the tree root`
Describe the bug
nix fmt suddenly causes the following response:
Error: path . not inside the tree root /path/to/datalad-nix
Last time formatting worked was this commit.
To Reproduce
After adding these changes the nix fmt command suddenly does not terminate succesfull
Expected behavior
It working like in https://github.com/malikwirin/datalad-nix/commit/dc9630acdda236cbea64c4f52967aceeec8f5604
System information
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs-unstable"
]
},
"locked": {
"lastModified": 1744707583,
"narHash": "sha256-IPFcShGro/UUp8BmwMBkq+6KscPlWQevZi9qqIwVUWg=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "49d05555ccdd2592300099d6a657cc33571f4fe0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
- system:
"x86_64-linux" - host os:
Linux 6.6.86, NixOS, 24.11 (Vicuna), 24.11.20250409.60e405b - multi-user?:
yes - sandbox:
yes - version:
nix-env (Nix) 2.24.14 - nixpkgs:
/nix/store/97hykhxj3miqqhfnf55b1rphiwcpxlcr-source
Using zsh
Is this the branch where you're having issues? https://github.com/malikwirin/datalad-nix/tree/forgejo-aneksajo
I've checked it out and nix fmt is working for me:
❯ nix fmt
traversed 38 files
emitted 20 files for processing
formatted 20 files (1 changed) in 25ms
I am using a later nix version, 2.28.3. There was an this issue with older versions of nix https://github.com/NixOS/nix/pull/11438, I'm not sure at what version number this PR was included though.
When I downgrade to nix 2.24.14 I still don't see the issue:
❯ nix fmt
traversed 38 files
emitted 20 files for processing
formatted 1 files (1 changed) in 16ms
❯ nix --version
nix (Nix) 2.24.14
It looks like https://github.com/NixOS/nix/commit/c60e1be62cc28494cc969f2d84151367c3db2220 first landed in nix 2.25.0, so I believe @malikwirin is using a version of nix fmt that invokes treefmt ..
I am able to reproduce this issue with if I clone the project, create a symlink to it, and try to run nix fmt inside the symlink-ed project root:
./ $ git clone [email protected]:malikwirin/datalad-nix.git
Cloning into 'datalad-nix'...
remote: Enumerating objects: 601, done.
remote: Counting objects: 100% (191/191), done.
remote: Compressing objects: 100% (80/80), done.
remote: Total 601 (delta 140), reused 142 (delta 105), pack-reused 410 (from 1)
Receiving objects: 100% (601/601), 106.95 KiB | 793.00 KiB/s, done.
Resolving deltas: 100% (326/326), done.
./ $ ln -s datalad-nix datalad-nix-link
./ $ cd datalad-nix-link
datalad-nix-link/ $ nix run nixpkgs#nixVersions.nix_2_24 fmt
Error: path . not inside the tree root /tmp/tmp.F51y6Yqv6x/datalad-nix-link
It works with a newer version of nix with https://github.com/NixOS/nix/commit/c60e1be62cc28494cc969f2d84151367c3db2220:
datalad-nix-link/ $ nix run nixpkgs#nixVersions.nix_2_28 fmt
traversed 34 files
emitted 18 files for processing
formatted 18 files (0 changed) in 29ms
But fails again if I explicitly specify .:
datalad-nix-link/ $ nix run nixpkgs#nixVersions.nix_2_28 fmt .
Error: path . not inside the tree root /tmp/tmp.F51y6Yqv6x/datalad-nix-link
This is all with treefmt v2.2.1. I was curious if this is fixed in the latest version of treefmt (I know we made some changes recently with symlinks), and I ran into a segfault (!), which I reported in https://github.com/numtide/treefmt/issues/594. I'll work on fixing that one right now.
I don't think there's anything actionable here, especially not in the treefmt-nix repo. @malikwirin, you should upgrade nix or treefmt and this specific problem will go away.
@brianmcgee, I suggest that we close this issue (I would, but it looks like I don't have the power to).