1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-17 16:02:43 +01:00

Improve database lock permission error context

Add helpful context when opening the Nix database lock fails due to
permission errors. Instead of just showing "Permission denied", now
provides guidance about possible causes:
- Running as non-root in a single-user Nix installation
- Nix daemon may have crashed
This commit is contained in:
Matthew Kenigsberg 2025-06-09 16:46:20 -06:00 committed by Jörg Thalheim
parent c5b1be46b4
commit d60a8ee8b0
2 changed files with 12 additions and 2 deletions

View file

@ -221,7 +221,16 @@ LocalStore::LocalStore(ref<const Config> config)
schema upgrade is in progress. */
if (!config->readOnly) {
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)) {