diff options
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/libstore/local-store.cc | 18 | ||||
| -rw-r--r-- | nix/libstore/local-store.hh | 2 |
2 files changed, 14 insertions, 6 deletions
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc index 161c8d81bda..43f3c1770a8 100644 --- a/nix/libstore/local-store.cc +++ b/nix/libstore/local-store.cc | |||
| @@ -67,7 +67,7 @@ LocalStore::LocalStore(bool reserveSpace) | |||
| 67 | 67 | ||
| 68 | /* Create missing state directories if they don't already exist. */ | 68 | /* Create missing state directories if they don't already exist. */ |
| 69 | createDirs(settings.nixStore); | 69 | createDirs(settings.nixStore); |
| 70 | makeStoreWritable(); | 70 | ensureStoreWritable(); |
| 71 | createDirs(linksDir = settings.nixStore + "/.links"); | 71 | createDirs(linksDir = settings.nixStore + "/.links"); |
| 72 | Path profilesDir = settings.nixStateDir + "/profiles"; | 72 | Path profilesDir = settings.nixStateDir + "/profiles"; |
| 73 | createDirs(profilesDir); | 73 | createDirs(profilesDir); |
| @@ -300,18 +300,26 @@ void LocalStore::openDB(bool create) | |||
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | 302 | ||
| 303 | /* To improve purity, users may want to make the store a read-only | 303 | /* To improve purity, users may want to make the store a read-only bind mount. |
| 304 | bind mount. So make the store writable for this process. */ | 304 | So make the store writable for this process. In case the store is read-only |
| 305 | void LocalStore::makeStoreWritable() | 305 | and cannot be made writable, throw an error. */ |
| 306 | void LocalStore::ensureStoreWritable() | ||
| 306 | { | 307 | { |
| 307 | #if HAVE_UNSHARE && HAVE_STATVFS && HAVE_SYS_MOUNT_H && defined(MS_BIND) && defined(MS_REMOUNT) | 308 | #if HAVE_UNSHARE && HAVE_STATVFS && HAVE_SYS_MOUNT_H && defined(MS_BIND) && defined(MS_REMOUNT) |
| 308 | if (getuid() != 0) return; | ||
| 309 | /* Check if /nix/store is on a read-only mount. */ | 309 | /* Check if /nix/store is on a read-only mount. */ |
| 310 | struct statvfs stat; | 310 | struct statvfs stat; |
| 311 | if (statvfs(settings.nixStore.c_str(), &stat) != 0) | 311 | if (statvfs(settings.nixStore.c_str(), &stat) != 0) |
| 312 | throw SysError("getting info about the store mount point"); | 312 | throw SysError("getting info about the store mount point"); |
| 313 | 313 | ||
| 314 | if (stat.f_flag & ST_RDONLY) { | 314 | if (stat.f_flag & ST_RDONLY) { |
| 315 | if (getuid() != 0) { | ||
| 316 | throw Error( | ||
| 317 | std::format( | ||
| 318 | "'{}' is read-only; make sure to mount it read-write " | ||
| 319 | "for proper guix-daemon operation", | ||
| 320 | settings.nixStore)); | ||
| 321 | } | ||
| 322 | |||
| 315 | if (unshare(CLONE_NEWNS) == -1) | 323 | if (unshare(CLONE_NEWNS) == -1) |
| 316 | throw SysError("setting up a private mount namespace"); | 324 | throw SysError("setting up a private mount namespace"); |
| 317 | 325 | ||
diff --git a/nix/libstore/local-store.hh b/nix/libstore/local-store.hh index 4d529b37a44..23af8c3f029 100644 --- a/nix/libstore/local-store.hh +++ b/nix/libstore/local-store.hh | |||
| @@ -212,7 +212,7 @@ private: | |||
| 212 | 212 | ||
| 213 | void openDB(bool create); | 213 | void openDB(bool create); |
| 214 | 214 | ||
| 215 | void makeStoreWritable(); | 215 | void ensureStoreWritable(); |
| 216 | 216 | ||
| 217 | uint64_t queryValidPathId(const Path & path); | 217 | uint64_t queryValidPathId(const Path & path); |
| 218 | 218 | ||
