cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
4.04k stars 303 forks source link

Failed to write cachix caches to file #1384

Open jurab opened 1 month ago

jurab commented 1 month ago

Describe the bug

I'm getting permission issues macOS, the file ownerships seem to be correctly set

❯ devenv up
• Building processes ...
• Using Cachix: devenv
thread 'main' panicked at devenv/src/command.rs:328:22:
Failed to write cachix caches to file: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: core::result::Result<T,E>::expect
   4: devenv::command::<impl devenv::devenv::Devenv>::prepare_command
   5: devenv::command::<impl devenv::devenv::Devenv>::run_nix
   6: devenv::devenv::Devenv::up
   7: devenv::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
✔ Building processes in 0.4s.

Version devenv 1.0.8 (aarch64-darwin)

domenkozar commented 1 month ago

do you have write permissions to $XDG_DATA_HOME?

mpscholten commented 1 month ago

we've just run into the same issue on v1.0.8

zeydtc commented 1 month ago

same issue here

domenkozar commented 1 month ago

We'll need help diagnosing under which conditions this happens, most likely something with the path and permissions mismatch.

mpscholten commented 1 month ago

The issue happens on a freshly installed macbook with a freshly installed nix (with the det installer).

As an initial workaround we tried to install cachix and then do cachix use devenv. That command worked. After the devenv cachix was enabled, the error still happens.

We worked around the issue now by dropping a flake.nix in the project and then running devenv through flakes. This works without any permission issues.

Is there any commands we can run that would be helpful to better understand the problem?

sandydoo commented 4 weeks ago

I did not manage to replicate this in a fresh VM. Fresh install, devenv init, devenv shell, devenv up, with and without cachix.enable — no dice.

At the failure point, devenv tries to write to the following directory: ~/.local/share/devenv We'd be grateful if someone could ls -l this directory and share the permissions.

jurab commented 4 weeks ago

here's the ls of my ~/.local/share/devenv

.rw-r--r-- 77 root  6 Aug 13:52 cachix_trusted_keys.json
drwxr-xr-x  - foo  6 Aug 12:36 devenv
drwxr-xr-x  - foo  6 Aug 12:36 gc
jurab commented 4 weeks ago

do you have write permissions to $XDG_DATA_HOME?

yes, no permission issues there

sandydoo commented 4 weeks ago

.rw-r--r-- 77 root 6 Aug 13:52 cachix_trusted_keys.json

Oh, well, here's the problem. How did this end up being owned by root? Did you happen to run sudo devenv at some point?

jurab commented 3 weeks ago

ah yes, changing the ownership solved the issue

I ran the non-mac installation first which ran into a permission issue, so I ran it with sudo, found out that's not the way either and then noticed there's a specific mac version, so I tried to remove everything and start over and apparently missed something

would be amazing to have an uninstall script, but thanks a lot for the assistance 👍

sandydoo commented 3 weeks ago

At the failure point, devenv tries to write to the following directory: ~/.local/share/devenv We'd be grateful if someone could ls -l this directory and share the permissions.

@mpscholten @zeydtc could you also check the permissions in this directory? Did you also run devenv with sudo at some point?

zeydtc commented 3 weeks ago

we did run devenv with sudo because we had a permission issue as well. however, unfortunately I can't recall if it was due to what @jurab said or if it was something else.

-rw-r--r--@ 1 root   staff   77 Aug 14 14:53 cachix_trusted_keys.json
drwxr-xr-x  2 em  staff   64 Aug 14 13:13 devenv
drwxr-xr-x  5 em  staff  160 Aug 14 14:53 gc