Nix 2.93.3
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
10struct LocalDerivationGoal : public DerivationGoal
11{
12 LocalStore & getLocalStore();
13
17 std::unique_ptr<UserLock> buildUser;
18
23
27 std::optional<Path> cgroup;
28
33
38
43
49
54
59 bool usingUserNamespace = true;
60
64 bool useChroot = false;
65
66 Path chrootRootDir;
67
71 std::shared_ptr<AutoDelete> autoDelChroot;
72
76 bool privateNetwork = false;
77
81 struct ChrootPath {
82 Path source;
83 bool optional;
84 ChrootPath(Path source = "", bool optional = false)
85 : source(source), optional(optional)
86 { }
87 };
88 typedef map<Path, ChrootPath> PathsInChroot; // maps target path to source path
89 PathsInChroot pathsInChroot;
90
91 typedef map<std::string, std::string> Environment;
92 Environment env;
93
94#if __APPLE__
95 typedef std::string SandboxProfile;
96 SandboxProfile additionalSandboxProfile;
97#endif
98
102 StringMap inputRewrites, outputRewrites;
103 typedef map<StorePath, StorePath> RedirectedOutputs;
104 RedirectedOutputs redirectedOutputs;
105
120 OutputPathMap scratchOutputs;
121
128 std::map<Path, ValidPathInfo> prevInfos;
129
130 uid_t sandboxUid() { return usingUserNamespace ? (!buildUser || buildUser->getUIDCount() == 1 ? 1000 : 0) : buildUser->getUID(); }
131 gid_t sandboxGid() { return usingUserNamespace ? (!buildUser || buildUser->getUIDCount() == 1 ? 100 : 0) : buildUser->getGID(); }
132
133 const static Path homeDir;
134
138 std::vector<std::thread> daemonWorkerThreads;
139
144 static std::unique_ptr<LocalDerivationGoal> makeLocalDerivationGoal(
145 const StorePath & drvPath,
147 Worker & worker,
148 bool isDependency,
149 BuildMode buildMode
150 );
151
156 static std::unique_ptr<LocalDerivationGoal> makeLocalDerivationGoal(
157 DrvHasRoot drvRoot,
158 const StorePath & drvPath,
159 const BasicDerivation & drv,
161 Worker & worker,
162 bool isDependency,
163 BuildMode buildMode
164 );
165
166 virtual ~LocalDerivationGoal() noexcept(false) override;
167
171 virtual bool needsHashRewrite();
172
176 kj::Promise<Result<WorkResult>> tryLocalBuild() noexcept override;
177
181 kj::Promise<Result<void>> startBuilder();
182
186 void initEnv();
187
191 void initTmpDir();
192
196 kj::Promise<Result<void>> writeStructuredAttrs();
197
204 void chownToBuilder(const Path & path);
205
209 void chownToBuilder(const AutoCloseFD & fd);
210
211 int getChildStatus() override;
212
216 void runChild();
217
222 kj::Promise<Result<SingleDrvOutputs>> registerOutputs() override;
223
224 void signRealisation(Realisation &) override;
225
231 kj::Promise<Result<void>> checkOutputs(const std::map<std::string, ValidPathInfo> & outputs, const std::map<std::string, StorePath> & alreadyRegisteredOutputs);
232
236 void closeReadPipes() override;
237
241 void cleanupHookFinally() override;
242 void cleanupPreChildKill() override;
243 void cleanupPostChildKill() override;
244 bool cleanupDecideWhetherDiskFull() override;
245 void cleanupPostOutputsRegisteredModeCheck() override;
246 void cleanupPostOutputsRegisteredModeNonCheck() override;
247
254 void finalizeTmpDir(bool force, bool duringDestruction = false);
255
261 void killChild() override final;
262
267 virtual void killSandbox(bool getStats);
268
275
284
285protected:
286 using DerivationGoal::DerivationGoal;
287
292 bool runPasta = false;
293
298 virtual void prepareSandbox()
299 {
300 throw Error("sandboxing builds is not supported on this platform");
301 };
302
307 virtual std::string rewriteResolvConf(std::string fromHost)
308 {
309 return fromHost;
310 }
311
316 virtual Pid startChild(std::function<void()> openSlave);
317
322 virtual void setupSyscallFilter() {}
323
328 virtual void execBuilder(std::string builder, Strings args, Strings envStrs);
329
333 virtual bool supportsUidRange()
334 {
335 return false;
336 }
337
338 virtual bool respectsTimeouts() override
339 {
340 return true;
341 }
342};
343
344}
Definition file-descriptor.hh:51
Definition local-store.hh:78
Definition processes.hh:24
Definition file-descriptor.hh:79
Definition path.hh:21
Definition worker.hh:89
std::map< OutputName, Realisation > SingleDrvOutputs
Definition realisation.hh:89
std::string_view OutputNameView
Definition outputs-spec.hh:26
Definition derivations.hh:274
Definition derivation-goal.hh:249
std::unique_ptr< Derivation > drv
Definition derivation-goal.hh:166
OutputsSpec wantedOutputs
Definition derivation-goal.hh:98
StorePath drvPath
Definition derivation-goal.hh:88
Definition goal.hh:89
const bool isDependency
Definition goal.hh:61
Worker & worker
Definition goal.hh:54
Definition local-derivation-goal.hh:11
kj::Promise< Result< void > > writeStructuredAttrs()
Definition local-derivation-goal.cc:1027
void chownToBuilder(const Path &path)
Definition local-derivation-goal.cc:1056
Path tmpDirRoot
Definition local-derivation-goal.hh:32
bool usingUserNamespace
Definition local-derivation-goal.hh:59
virtual Pid startChild(std::function< void()> openSlave)
Definition local-derivation-goal.cc:907
void closeReadPipes() override
Definition local-derivation-goal.cc:319
std::vector< std::thread > daemonWorkerThreads
Definition local-derivation-goal.hh:138
void signRealisation(Realisation &) override
Definition local-derivation-goal.cc:2207
bool privateNetwork
Definition local-derivation-goal.hh:76
void finalizeTmpDir(bool force, bool duringDestruction=false)
Definition local-derivation-goal.cc:2477
void cleanupHookFinally() override
Definition local-derivation-goal.cc:330
bool useChroot
Definition local-derivation-goal.hh:64
kj::Promise< Result< SingleDrvOutputs > > registerOutputs() override
Definition local-derivation-goal.cc:1626
std::map< Path, ValidPathInfo > prevInfos
Definition local-derivation-goal.hh:128
kj::Promise< Result< WorkResult > > tryLocalBuild() noexcept override
Definition local-derivation-goal.cc:169
void initTmpDir()
Definition local-derivation-goal.cc:915
virtual bool needsHashRewrite()
Definition local-derivation-goal.cc:126
std::optional< Path > cgroup
Definition local-derivation-goal.hh:27
std::shared_ptr< AutoDelete > autoDelChroot
Definition local-derivation-goal.hh:71
virtual void execBuilder(std::string builder, Strings args, Strings envStrs)
Definition local-derivation-goal.cc:1620
AutoCloseFD builderOutPTY
Definition local-derivation-goal.hh:48
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:322
bool runPasta
Definition local-derivation-goal.hh:292
OutputPathMap scratchOutputs
Definition local-derivation-goal.hh:120
Pipe userNamespaceSync
Definition local-derivation-goal.hh:53
void killChild() override final
Definition local-derivation-goal.cc:140
void runChild()
Definition local-derivation-goal.cc:1071
kj::Promise< Result< void > > checkOutputs(const std::map< std::string, ValidPathInfo > &outputs, const std::map< std::string, StorePath > &alreadyRegisteredOutputs)
Definition local-derivation-goal.cc:2213
virtual void prepareSandbox()
Definition local-derivation-goal.hh:298
std::unique_ptr< UserLock > buildUser
Definition local-derivation-goal.hh:17
StorePath makeFallbackPath(const StorePath &path)
Definition local-derivation-goal.cc:2513
AutoCloseFD tmpDirRootFd
Definition local-derivation-goal.hh:37
kj::Promise< Result< void > > startBuilder()
Definition local-derivation-goal.cc:414
virtual bool supportsUidRange()
Definition local-derivation-goal.hh:333
Pid pid
Definition local-derivation-goal.hh:22
void initEnv()
Definition local-derivation-goal.cc:969
StringMap inputRewrites
Definition local-derivation-goal.hh:102
Path tmpDirInSandbox
Definition local-derivation-goal.hh:42
virtual std::string rewriteResolvConf(std::string fromHost)
Definition local-derivation-goal.hh:307
virtual void killSandbox(bool getStats)
Definition local-derivation-goal.cc:159
Definition outputs-spec.hh:28
Definition realisation.hh:49
Definition path-info.hh:83
std::string Path
Definition types.hh:28