1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00
This commit is contained in:
Matthew Kenigsberg 2025-06-24 08:42:58 -06:00 committed by GitHub
commit af29b98509
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -231,7 +231,16 @@ LocalStore::LocalStore(ref<const Config> config)
schema upgrade is in progress. */ schema upgrade is in progress. */
if (!config->readOnly) { if (!config->readOnly) {
Path globalLockPath = dbDir + "/big-lock"; Path globalLockPath = dbDir + "/big-lock";
globalLock = openLockFile(globalLockPath.c_str(), true); try {
globalLock = openLockFile(globalLockPath.c_str(), true);
} catch (SysError & e) {
if (e.errNo == EACCES || e.errNo == EPERM) {
e.addTrace({},
"This command may have been run as non-root in a single-user Nix installation,\n"
"or the Nix daemon may have crashed.");
}
throw;
}
} }
if (!config->readOnly && !lockFile(globalLock.get(), ltRead, false)) { if (!config->readOnly && !lockFile(globalLock.get(), ltRead, false)) {

View file

@ -42,7 +42,8 @@ chmod -R -w $TEST_ROOT/var
# Make sure we fail on add operations on the read-only store # Make sure we fail on add operations on the read-only store
# This is only for adding files that are not *already* in the store # This is only for adding files that are not *already* in the store
expectStderr 1 nix-store --add eval.nix | grepQuiet "error: opening lock file '$(readlink -e $TEST_ROOT)/var/nix/db/big-lock'" # Should show enhanced error message with helpful context
expectStderr 1 nix-store --add eval.nix | grepQuiet "This command may have been run as non-root in a single-user Nix installation"
expectStderr 1 nix-store --store local?read-only=true --add eval.nix | grepQuiet "Permission denied" expectStderr 1 nix-store --store local?read-only=true --add eval.nix | grepQuiet "Permission denied"
# Test the same operations from before should again succeed # Test the same operations from before should again succeed