summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nix/libstore/build.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 3861a1ffd90..c8b778362ac 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2091,6 +2091,18 @@ void DerivationGoal::runChild()
2091 2091
2092 for (auto & i : ss) dirsInChroot[i] = i; 2092 for (auto & i : ss) dirsInChroot[i] = i;
2093 2093
2094 /* Make new mounts for the store and for /tmp. That way, when
2095 'chrootRootDir' is made read-only below, these two mounts will
2096 remain writable (the store needs to be writable so derivation
2097 outputs can be written to it, and /tmp is writable by
2098 convention). */
2099 auto chrootStoreDir = chrootRootDir + settings.nixStore;
2100 if (mount(chrootStoreDir.c_str(), chrootStoreDir.c_str(), 0, MS_BIND, 0) == -1)
2101 throw SysError(format("read-write mount of store '%1%' failed") % chrootStoreDir);
2102 auto chrootTmpDir = chrootRootDir + "/tmp";
2103 if (mount(chrootTmpDir.c_str(), chrootTmpDir.c_str(), 0, MS_BIND, 0) == -1)
2104 throw SysError(format("read-write mount of temporary directory '%1%' failed") % chrootTmpDir);
2105
2094 /* Bind-mount all the directories from the "host" 2106 /* Bind-mount all the directories from the "host"
2095 filesystem that we want in the chroot 2107 filesystem that we want in the chroot
2096 environment. */ 2108 environment. */
@@ -2164,6 +2176,10 @@ void DerivationGoal::runChild()
2164 2176
2165 if (rmdir("real-root") == -1) 2177 if (rmdir("real-root") == -1)
2166 throw SysError("cannot remove real-root directory"); 2178 throw SysError("cannot remove real-root directory");
2179
2180 /* Remount root as read-only. */
2181 if (mount("/", "/", 0, MS_BIND | MS_REMOUNT | MS_RDONLY, 0) == -1)
2182 throw SysError(format("read-only remount of build root '%1%' failed") % chrootRootDir);
2167 } 2183 }
2168#endif 2184#endif
2169 2185