Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied when trying to update flake.lock #79

Open
Yucklys opened this issue Apr 2, 2024 · 14 comments
Open

Permission denied when trying to update flake.lock #79

Yucklys opened this issue Apr 2, 2024 · 14 comments

Comments

@Yucklys
Copy link

Yucklys commented Apr 2, 2024

I put my flake.nix under /etc/nixos, as this is where the sudo nixos-rebuild switch default to. However, when I try to update the flake inputs by nh os switch --update, it successfully pulls the updates, but failed to update the flake.lock file due to permission denied. I have to manually update the flake inputs before I run this command. I think nh should ask for sudo permission to update the lock, as /etc/nixos/flake.nix is a common place that people will store their flake files.
image

@viperML
Copy link
Owner

viperML commented Apr 2, 2024

nh doesn't run nix as root, only the activation scripts

@Yucklys
Copy link
Author

Yucklys commented Apr 9, 2024

I just want to know if this is the intended behavior, as it requires another command to upgrade. I write a wrapper for the commands and now it work perfectly.

@Yucklys Yucklys closed this as completed Apr 9, 2024
@viperML
Copy link
Owner

viperML commented Apr 9, 2024

It's weird behaviour nonetheless

@viperML viperML reopened this Apr 9, 2024
@painsucker6k
Copy link

Screenshot_20240419_125001
Same issue.

@painsucker6k
Copy link

painsucker6k commented Apr 19, 2024

nh doesn't run nix as root, only the activation scripts

I'm guessing that's the issue, as flakes are updated by the nix command?
I'm not that experienced in nix, so excuse me if I'm wrong.

@viperML
Copy link
Owner

viperML commented Apr 19, 2024

I know the issue but not the cleanest way to handle it. And my NixOS flake is not owned by root, so I don't need to fix this immediately

@painsucker6k
Copy link

So the temporary fix is changing the ownership of flake.nix and flake.lock?

@viperML
Copy link
Owner

viperML commented Apr 19, 2024

I'd say not using nh's --update is the correct way

@different-name
Copy link

different-name commented Jun 12, 2024

I am also struggling with this, nh os switch fails whenever I update my flake inputs, shouldn't nh ask for sudo like it does at other times it is required?

@viperML
Copy link
Owner

viperML commented Jun 12, 2024

No, because I want to keep the evaluation apart from root

@different-name
Copy link

Do you suggest permanently changing ownership then?

@viperML
Copy link
Owner

viperML commented Jun 14, 2024

Running nix flake update as the same user that owns the flake

@gepbird
Copy link

gepbird commented Jul 1, 2024

I have a similar issue: using agenix the quick and dirty way and putting a builtins.readFile config.age.secrets.foo.path in the config, I get a permission error: error: opening file '/run/agenix/foo': Permission denied

And sudo -E nh os switch doesn't work: Don't run nh os as root. I will call sudo internally as needed. Whats the reason for this sudo check?

@viperML
Copy link
Owner

viperML commented Jul 1, 2024

Well readFile secret is certainly a usecase I want to block, so nh was working as intended.

Edit: + if anything, nix would not let you read files outside the flake because of the evaluation-time sandbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants