`nix flake check` failed, couldn't open cache
Describe the bug
error: builder for '/nix/store/ybvrra9ha5b3bb714csld0hwm2j2r9lz-check-formatting.drv' failed with exit code 1;
last 1 log lines:
> Error: failed to open cache: could not resolve local path for the cache: could not create any of the following paths: [/homeless-shelter/.cache/treefmt/eval-cache]
For full logs, run 'nix log /nix/store/ybvrra9ha5b3bb714csld0hwm2j2r9lz-check-formatting.drv'.
To Reproduce
Steps to reproduce the behavior:
- Add
formatting = (inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.checktochecksoutput. - Run
nix flake check.
Expected behavior
nix flake check runs successfully.
System information
NixOS Unstable (25.11)
Additional context
-
@0komo, could you share a full repo with a repro? This isn't enough for me to know how to reproduce the issue.
Full repo with repro:
git clone [email protected]:engmark/root.git
cd root
nix develop --ignore-env --command pre-commit run --all-files nixfmt
Log:
nixfmt...................................................................Failed
- hook id: nixfmt
- exit code: 1
Error: failed to open cache: could not resolve local path for the cache: could not create any of the following paths: [/.cache/treefmt/eval-cache]
Or closer to the metal:
❯ nix develop --ignore-env --command treefmt
Error: failed to open cache: could not resolve local path for the cache: could not create any of the following paths: [/.cache/treefmt/eval-cache]
@l0b0, your repro looks different than @0komo's. In the OP, the failure occurred during a build in the build sandbox running our check derivation, which sets $HOME to a path that exists.
By running nix develop with --ignore-env, you're invoking treefmt with no $HOME environment variable, and we end up trying to put the cache in /.cache. We should probably error out more clearly there (or print out a warning that we're running without a cache).
By running
nix developwith--ignore-env, you're invokingtreefmtwith no$HOMEenvironment variable, […]
~~That seems like a bug in the Nix CLI. --ignore-env is to avoid propagating variables from the environment into the sandbox, but nix develop doesn't do that in any case – it passes HOME=/homeless-shelter. I'll file a bug upstream when I have time.~~
Update: Wait, I'm thinking of nix build.