Skip to content

Only try to chmod /nix/var/nix/profiles/per-user when necessary#12391

Merged
roberth merged 1 commit intoNixOS:masterfrom
SuperSandro2000:per-user-stat-chmod
Feb 20, 2025
Merged

Only try to chmod /nix/var/nix/profiles/per-user when necessary#12391
roberth merged 1 commit intoNixOS:masterfrom
SuperSandro2000:per-user-stat-chmod

Conversation

@SuperSandro2000
Copy link
Member

@SuperSandro2000 SuperSandro2000 commented Feb 1, 2025

Motivation

Try to get the current version working in renovate.

Context

#8074

in short: nix always chmod's /nix/var/nix/profiles/per-user when not using the daemon even if the permissions are already correct. By first checking if the chmod is necessary we can avoid requiring more permissions then necessary.

The error before was:

error: could not set permissions on '/nix/var/nix/profiles/per-user' to 755: Operation not permitted

and now is avoided if the permissons are already correct.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Feb 1, 2025
Copy link

@viceice viceice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@SuperSandro2000 SuperSandro2000 force-pushed the per-user-stat-chmod branch 2 times, most recently from 206cb37 to aedfb1a Compare February 4, 2025 21:49
@SuperSandro2000 SuperSandro2000 marked this pull request as draft February 11, 2025 16:39
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
@SuperSandro2000 SuperSandro2000 marked this pull request as ready for review February 11, 2025 17:23
@Ericson2314
Copy link
Member

I would factor out a chmodIfNeeded function. It will be clearer, and there are probably many more places which could benefit from this.

@SuperSandro2000
Copy link
Member Author

Can I push that over to someone else? I barely knew enough c++ to write this change and doing bigger refactors will probably be a shit show.

@Ericson2314
Copy link
Member

#10991 (comment) I know I was having some deja vu :)

@SuperSandro2000
Copy link
Member Author

Overriding the nix version to a really old one fixed the issue for renovate (renovatebot/github-action#713 (comment)) so I think it should work after this but I couldn't e2e test it.

mergify bot added a commit that referenced this pull request Feb 20, 2025
…2391

Only try to chmod /nix/var/nix/profiles/per-user when necessary (backport #12391)
mergify bot added a commit that referenced this pull request Feb 20, 2025
…2391

Only try to chmod /nix/var/nix/profiles/per-user when necessary (backport #12391)
mergify bot added a commit that referenced this pull request Feb 20, 2025
…2391

Only try to chmod /nix/var/nix/profiles/per-user when necessary (backport #12391)
@SuperSandro2000 SuperSandro2000 deleted the per-user-stat-chmod branch February 20, 2025 18:32
@heimalne
Copy link

Many thanks @SuperSandro2000 and @roberth. I'll try to find time to test it with the next patch release of https://hub.docker.com/r/nixos/nix/tags.

mkenigs added a commit to mkenigs/nix that referenced this pull request Jun 9, 2025
Give some hints about what could be going wrong when Nix can't acquire
the db lock.

Currently running Nix as a non-root user on a single-user install
prints the error:
```
error: opening lock file '/nix/var/nix/db/big-lock': Permission denied
```

The error was recently changed
(NixOS#12391),
but people have frequently run into the prior error:
```
error: could not set permissions on '/nix/var/nix/profiles/per-user' to 755: Operation not permitted
```

There seems to be a lot of confusion about the prior error, and the
current error doesn't seem to give much more of a hint about how to
resolve the problem. Modify the error to provide some hints at what
could be going wrong, instead erroring with:
```
error: don't have permission to lock Nix database in '/nix/var/nix/db'.
This command may have been run as non-root in a single-user Nix installation,
or the Nix daemon may have crashed.
```
mkenigs added a commit to mkenigs/nix that referenced this pull request Jun 9, 2025
Give some hints about what could be going wrong when Nix can't acquire
the db lock.

Currently running Nix as a non-root user on a single-user install
prints the error:
```
error: opening lock file '/nix/var/nix/db/big-lock': Permission denied
```

The error printed in this situation was indirectly changed recently by
NixOS#12391,
but people have frequently run into the prior error:
```
error: could not set permissions on '/nix/var/nix/profiles/per-user' to 755: Operation not permitted
```

There seems to be a lot of confusion about the prior error, and the
current error doesn't seem to give much more of a hint about how to
resolve the problem. Modify the error to provide some hints at what
could be going wrong, instead erroring with:
```
error: don't have permission to lock Nix database in '/nix/var/nix/db'.
This command may have been run as non-root in a single-user Nix installation,
or the Nix daemon may have crashed.
```
mkenigs added a commit to mkenigs/nix that referenced this pull request Jun 10, 2025
Give some hints about what could be going wrong when Nix can't acquire
the db lock.

Currently running Nix as a non-root user on a single-user install
prints the error:
```
error: opening lock file '/nix/var/nix/db/big-lock': Permission denied
```

The error printed in this situation was indirectly changed recently by
NixOS#12391,
but people have frequently run into the prior error:
```
error: could not set permissions on '/nix/var/nix/profiles/per-user' to 755: Operation not permitted
```

There seems to be a lot of confusion about the prior error, and the
current error doesn't seem to give much more of a hint about how to
resolve the problem. Modify the error to provide some hints at what
could be going wrong, instead erroring with:
```
error: don't have permission to lock Nix database in '/nix/var/nix/db'.
       This command may have been run as non-root in a single-user Nix installation,
       or the Nix daemon may have crashed.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants