nix-env: remove lockProfile() when calling --list-generations - #16523
Conversation
`--list-generations` is a read-only call, so it shouldn't need root. Fix NixOS#5144.
xokdvium
left a comment
There was a problem hiding this comment.
Seems like this originates from 2006! 86cbd93
The only potential issue I see is trying to list generations while the profile is being modified.
There's probably pre-existing issues with us using std::filesystem for directory iterator:
[Note 4 : If a file is removed from or added to a directory after the construction of a directory_iterator for the
directory, it is unspecified whether or not subsequently incrementing the iterator will ever result in an iterator
referencing the removed or added directory entry. See POSIX readdir. — end note]
And findGenerations could stand to tolerate disappearing files instead barfing on lstat but it doesn't seem all that bad IMO compared to failing outright. Lemme push an update for that.
|
Hm, alternatively: maybe behavior of |
xokdvium
left a comment
There was a problem hiding this comment.
I'll approve optimistically here seeing that probably the racy listing isn't that big of a deal, but it would be nice if someone could think of a way to check how we'd behave when racing the same profile dir.
|
Just one more argument in favor of this change: Sadly we can't use |
|
Indeed that's what I meant by:
|
|
Filed #16524. Let's proceed here. |
--list-generationsis a read-only call, so it shouldn't need root.Fix #5144.
Motivation
nix-env --list-generationsneed a profile lock, that in multi-user installs means it needs root to succeed. Howevernix-env --list-generationsis a read-only operation, so it should not need root.Context
This is a long standing issue for
nixos-rebuild-ng, since users want to runnixos-rebuild list-generationswithout needing root. Right now we have 2 different code paths to list generations, one where we manually scrap the/nix/storefor the data we need (used bynixos-rebuild list-generations) and another usingnix-env --list-generations(used fornixos-rebuild switch --rollback, since this needs root anyway).Getting this PR merged would mean we can unify both code paths and also means we could avoid unholy hacks like this one, that reimplements the
nix-env --list-profilesas a shell script to get both non-root+remote usage at the cost of my sanity: NixOS/nixpkgs#560972.I am not a specialist in C++ or CppNix codebase, but the removal of this lock seems safe:
opListGenerationsis only called whennix-env --list-generationsis used.As part of the Automation/AI policy, I used Codex with gpt-5.6-terra model to understand the issue, but the coding part was done for me.
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.