Nix  2.93.0-dev
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
local-derivation-goal.hh
Go to the documentation of this file.
1#pragma once
3
7
8namespace nix {
9
11{
12 LocalStore & getLocalStore();
13
17 std::unique_ptr<UserLock> buildUser;
18
23
27 std::optional<Path> cgroup;
28
33
38
44
49
55 AutoCloseFD sandboxUserNamespace;
56
61 bool usingUserNamespace = true;
62
66 bool useChroot = false;
67
68 Path chrootRootDir;
69
73 std::shared_ptr<AutoDelete> autoDelChroot;
74
78 bool privateNetwork = false;
79
83 struct ChrootPath {
84 Path source;
85 bool optional;
86 ChrootPath(Path source = "", bool optional = false)
87 : source(source), optional(optional)
88 { }
89 };
90 typedef map<Path, ChrootPath> PathsInChroot; // maps target path to source path
91 PathsInChroot pathsInChroot;
92
93 typedef map<std::string, std::string> Environment;
94 Environment env;
95
96#if __APPLE__
97 typedef std::string SandboxProfile;
98 SandboxProfile additionalSandboxProfile;
99#endif
100
104 StringMap inputRewrites, outputRewrites;
105 typedef map<StorePath, StorePath> RedirectedOutputs;
106 RedirectedOutputs redirectedOutputs;
107
122 OutputPathMap scratchOutputs;
123
130 std::map<Path, ValidPathInfo> prevInfos;
131
132 uid_t sandboxUid() { return usingUserNamespace ? (!buildUser || buildUser->getUIDCount() == 1 ? 1000 : 0) : buildUser->getUID(); }
133 gid_t sandboxGid() { return usingUserNamespace ? (!buildUser || buildUser->getUIDCount() == 1 ? 100 : 0) : buildUser->getGID(); }
134
135 const static Path homeDir;
136
141
145 std::thread daemonThread;
146
150 std::vector<std::thread> daemonWorkerThreads;
151
155 StorePathSet addedPaths;
156
160 std::set<DrvOutput> addedDrvOutputs;
161
168 bool isAllowed(const StorePath & path)
169 {
170 return inputPaths.count(path) || addedPaths.count(path);
171 }
172 bool isAllowed(const DrvOutput & id)
173 {
174 return addedDrvOutputs.count(id);
175 }
176
177 bool isAllowed(const DerivedPath & req);
178
179 friend struct RestrictedStore;
180
185 static std::unique_ptr<LocalDerivationGoal> makeLocalDerivationGoal(
186 const StorePath & drvPath,
187 const OutputsSpec & wantedOutputs,
188 Worker & worker,
189 bool isDependency,
190 BuildMode buildMode
191 );
192
197 static std::unique_ptr<LocalDerivationGoal> makeLocalDerivationGoal(
198 DrvHasRoot drvRoot,
199 const StorePath & drvPath,
200 const BasicDerivation & drv,
201 const OutputsSpec & wantedOutputs,
202 Worker & worker,
203 bool isDependency,
204 BuildMode buildMode
205 );
206
207 virtual ~LocalDerivationGoal() noexcept(false) override;
208
212 virtual bool needsHashRewrite();
213
217 kj::Promise<Result<WorkResult>> tryLocalBuild() noexcept override;
218
222 kj::Promise<Result<void>> startBuilder();
223
227 void initEnv();
228
232 void initTmpDir();
233
237 kj::Promise<Result<void>> writeStructuredAttrs();
238
239 void startDaemon();
240
241 void stopDaemon();
242
247 void addDependency(const StorePath & path);
248
252 void chownToBuilder(const Path & path);
253
254 int getChildStatus() override;
255
259 void runChild();
260
265 kj::Promise<Result<SingleDrvOutputs>> registerOutputs() override;
266
267 void signRealisation(Realisation &) override;
268
274 kj::Promise<Result<void>> checkOutputs(const std::map<std::string, ValidPathInfo> & outputs, const std::map<std::string, StorePath> & alreadyRegisteredOutputs);
275
279 void closeReadPipes() override;
280
284 void cleanupHookFinally() override;
285 void cleanupPreChildKill() override;
286 void cleanupPostChildKill() override;
287 bool cleanupDecideWhetherDiskFull() override;
288 void cleanupPostOutputsRegisteredModeCheck() override;
289 void cleanupPostOutputsRegisteredModeNonCheck() override;
290
294 void deleteTmpDir(bool force, bool duringDestruction = false);
295
301 void killChild() override final;
302
307 virtual void killSandbox(bool getStats);
308
314 StorePath makeFallbackPath(const StorePath & path);
315
323 StorePath makeFallbackPath(OutputNameView outputName);
324
325protected:
326 using DerivationGoal::DerivationGoal;
327
332 virtual void prepareSandbox()
333 {
334 throw Error("sandboxing builds is not supported on this platform");
335 };
336
341 virtual Pid startChild(std::function<void()> openSlave);
342
347 virtual void setupSyscallFilter() {}
348
353 virtual void execBuilder(std::string builder, Strings args, Strings envStrs);
354
358 virtual bool supportsUidRange()
359 {
360 return false;
361 }
362
363 virtual bool respectsTimeouts() override
364 {
365 return true;
366 }
367};
368
369}
Definition file-descriptor.hh:42
Definition local-store.hh:78
Definition processes.hh:24
Definition file-descriptor.hh:61
Definition path.hh:21
Definition derivation-goal.hh:73
std::unique_ptr< Derivation > drv
Definition derivation-goal.hh:166
OutputsSpec wantedOutputs
Definition derivation-goal.hh:98
StorePathSet inputPaths
Definition derivation-goal.hh:183
StorePath drvPath
Definition derivation-goal.hh:88
Definition realisation.hh:24
const bool isDependency
Definition goal.hh:61
Worker & worker
Definition goal.hh:54
Definition local-derivation-goal.hh:83
Definition local-derivation-goal.hh:11
kj::Promise< Result< void > > writeStructuredAttrs()
Definition local-derivation-goal.cc:950
void chownToBuilder(const Path &path)
Definition local-derivation-goal.cc:1455
std::set< DrvOutput > addedDrvOutputs
Definition local-derivation-goal.hh:160
std::thread daemonThread
Definition local-derivation-goal.hh:145
bool usingUserNamespace
Definition local-derivation-goal.hh:61
virtual Pid startChild(std::function< void()> openSlave)
Definition local-derivation-goal.cc:835
void closeReadPipes() override
Definition local-derivation-goal.cc:308
std::vector< std::thread > daemonWorkerThreads
Definition local-derivation-goal.hh:150
void signRealisation(Realisation &) override
Definition local-derivation-goal.cc:2548
bool privateNetwork
Definition local-derivation-goal.hh:78
void cleanupHookFinally() override
Definition local-derivation-goal.cc:319
bool useChroot
Definition local-derivation-goal.hh:66
kj::Promise< Result< SingleDrvOutputs > > registerOutputs() override
Definition local-derivation-goal.cc:1977
std::map< Path, ValidPathInfo > prevInfos
Definition local-derivation-goal.hh:130
AutoCloseFD daemonSocket
Definition local-derivation-goal.hh:140
kj::Promise< Result< WorkResult > > tryLocalBuild() noexcept override
Definition local-derivation-goal.cc:158
void initTmpDir()
Definition local-derivation-goal.cc:843
virtual bool needsHashRewrite()
Definition local-derivation-goal.cc:115
std::optional< Path > cgroup
Definition local-derivation-goal.hh:27
std::shared_ptr< AutoDelete > autoDelChroot
Definition local-derivation-goal.hh:73
void deleteTmpDir(bool force, bool duringDestruction=false)
Definition local-derivation-goal.cc:2771
void addDependency(const StorePath &path)
Definition local-derivation-goal.cc:1403
Path tmpDir
Definition local-derivation-goal.hh:32
virtual void execBuilder(std::string builder, Strings args, Strings envStrs)
Definition local-derivation-goal.cc:1971
AutoCloseFD builderOutPTY
Definition local-derivation-goal.hh:43
static std::unique_ptr< LocalDerivationGoal > makeLocalDerivationGoal(const StorePath &drvPath, const OutputsSpec &wantedOutputs, Worker &worker, bool isDependency, BuildMode buildMode)
Definition platform.cc:28
virtual void setupSyscallFilter()
Definition local-derivation-goal.hh:347
AutoCloseFD sandboxMountNamespace
Definition local-derivation-goal.hh:54
OutputPathMap scratchOutputs
Definition local-derivation-goal.hh:122
Pipe userNamespaceSync
Definition local-derivation-goal.hh:48
void killChild() override final
Definition local-derivation-goal.cc:129
void runChild()
Definition local-derivation-goal.cc:1463
kj::Promise< Result< void > > checkOutputs(const std::map< std::string, ValidPathInfo > &outputs, const std::map< std::string, StorePath > &alreadyRegisteredOutputs)
Definition local-derivation-goal.cc:2554
virtual void prepareSandbox()
Definition local-derivation-goal.hh:332
std::unique_ptr< UserLock > buildUser
Definition local-derivation-goal.hh:17
StorePath makeFallbackPath(const StorePath &path)
Definition local-derivation-goal.cc:2797
kj::Promise< Result< void > > startBuilder()
Definition local-derivation-goal.cc:407
virtual bool supportsUidRange()
Definition local-derivation-goal.hh:358
Pid pid
Definition local-derivation-goal.hh:22
void initEnv()
Definition local-derivation-goal.cc:892
bool isAllowed(const StorePath &path)
Definition local-derivation-goal.hh:168
StringMap inputRewrites
Definition local-derivation-goal.hh:104
Path tmpDirInSandbox
Definition local-derivation-goal.hh:37
virtual void killSandbox(bool getStats)
Definition local-derivation-goal.cc:148
StorePathSet addedPaths
Definition local-derivation-goal.hh:155
std::string Path
Definition types.hh:28