Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
derivations.hh
Go to the documentation of this file.
1#pragma once
3
7#include "lix/libutil/hash.hh"
11#include "lix/libutil/sync.hh"
14
15#include <kj/async.h>
16#include <map>
17#include <variant>
18
19
20namespace nix {
21
22class Store;
23
24/* Abstract syntax of derivations. */
25
30{
35 {
36 StorePath path;
37
39 };
40
45 struct CAFixed
46 {
53
60 StorePath path(const Store & store, std::string_view drvName, OutputNameView outputName) const;
61
63 };
64
71 {
76
80 HashType hashType;
81
82 GENERATE_CMP(CAFloating, me->method, me->hashType);
83 };
84
89 struct Deferred {
91 };
92
97 struct Impure
98 {
103
107 HashType hashType;
108
109 GENERATE_CMP(Impure, me->method, me->hashType);
110 };
111
112 typedef std::variant<
114 CAFixed,
116 Deferred,
117 Impure
118 > Raw;
119
120 Raw raw;
121
123
125
130
137 std::optional<StorePath> path(const Store & store, std::string_view drvName, OutputNameView outputName) const;
138
139 JSON toJSON(
140 const Store & store,
141 std::string_view drvName,
142 OutputNameView outputName) const;
147 const Store & store,
148 std::string_view drvName,
149 OutputNameView outputName,
150 const JSON & json,
151 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
152};
153
154typedef std::map<std::string, DerivationOutput> DerivationOutputs;
155
162typedef std::map<std::string, std::pair<DerivationOutput, std::optional<StorePath>>>
164
169typedef std::map<StorePath, StringSet> DerivationInputs;
170
182
184 };
185
205 bool fixed;
206
207 GENERATE_CMP(ContentAddressed, me->sandboxed, me->fixed);
208 };
209
216 struct Impure {
218 };
219
220 typedef std::variant<
223 Impure
224 > Raw;
225
226 Raw raw;
227
229
231
235 DerivationType() = delete;
236
241 bool isCA() const;
242
247 bool isFixed() const;
248
255 bool isSandboxed() const;
256
263 bool isPure() const;
264
270 bool hasKnownOutputPaths() const;
271};
272
273struct BasicDerivation
274{
278 DerivationOutputs outputs;
282 StorePathSet inputSrcs;
283 std::string platform;
284 Path builder;
285 Strings args;
286 StringPairs env;
287 std::string name;
288
289 BasicDerivation() = default;
290 virtual ~BasicDerivation() { };
291
292 bool isBuiltin() const;
293
297 DerivationType type() const;
298
302 StringSet outputNames() const;
303
310
311 static std::string_view nameFromPath(const StorePath & storePath);
312
314 me->outputs,
315 me->inputSrcs,
316 me->platform,
317 me->builder,
318 me->args,
319 me->env,
320 me->name);
321};
322
323struct Derivation : BasicDerivation
324{
329
333 std::string unparse(const Store & store, bool maskOutputs,
334 DerivedPathMap<StringSet>::ChildNode::Map * actualInputs = nullptr) const;
335
345 kj::Promise<Result<std::optional<BasicDerivation>>>
346 tryResolve(Store & store, Store * evalStore = nullptr) const;
347
353 kj::Promise<Result<std::optional<BasicDerivation>>> tryResolve(
354 Store & store,
355 const std::map<std::pair<StorePath, std::string>, StorePath> & inputDrvOutputs) const;
356
365 kj::Promise<Result<void>> checkInvariants(Store & store, const StorePath & drvPath) const;
366
367 Derivation() = default;
368 Derivation(const BasicDerivation & bd) : BasicDerivation(bd) { }
369 Derivation(BasicDerivation && bd) : BasicDerivation(std::move(bd)) { }
370
371 JSON toJSON(const Store & store) const;
372 static Derivation fromJSON(
373 const Store & store,
374 const JSON & json,
375 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
376
377 GENERATE_CMP(Derivation,
378 static_cast<const BasicDerivation &>(*me),
379 me->inputDrvs);
380};
381
382
383class Store;
384
388kj::Promise<Result<StorePath>> writeDerivation(Store & store,
389 const Derivation & drv,
390 RepairFlag repair = NoRepair,
391 bool readOnly = false);
392
396Derivation parseDerivation(
397 const Store & store,
398 std::string && s,
399 std::string_view name,
400 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
401
407bool isDerivation(std::string_view fileName);
408
416std::string outputPathName(std::string_view drvName, OutputNameView outputName);
417
418
426struct DrvHash {
430 std::map<std::string, Hash> hashes;
431
432 enum struct Kind : bool {
438
443 };
444
450};
451
452void operator |= (DrvHash::Kind & self, const DrvHash::Kind & other) noexcept;
453
478kj::Promise<Result<DrvHash>>
479hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutputs);
480
487kj::Promise<Result<std::map<std::string, Hash>>>
488staticOutputHashes(Store & store, const Derivation & drv);
489
493typedef std::map<StorePath, DrvHash> DrvHashes;
494
495// FIXME: global, though at least thread-safe.
496extern Sync<DrvHashes> drvHashes;
497
498struct Source;
499struct Sink;
500
501Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv, std::string_view name);
502void writeDerivation(Sink & out, const Store & store, const BasicDerivation & drv);
503
512std::string hashPlaceholder(const OutputNameView outputName);
513
514extern const Hash impureOutputHash;
515
516}
Definition path.hh:21
Definition store-api.hh:195
Definition sync.hh:37
#define GENERATE_CMP(args...)
Definition comparator.hh:65
std::map< StorePath, StringSet > DerivationInputs
Definition derivations.hh:169
std::map< std::string, std::pair< DerivationOutput, std::optional< StorePath > > > DerivationOutputsAndOptPaths
Definition derivations.hh:163
std::map< StorePath, DrvHash > DrvHashes
Definition derivations.hh:493
std::string_view OutputNameView
Definition outputs-spec.hh:26
Definition derivations.hh:274
DerivationOutputs outputs
Definition derivations.hh:278
StringSet outputNames() const
Definition derivations.cc:917
DerivationOutputsAndOptPaths outputsAndOptPaths(const Store &store) const
Definition derivations.cc:925
DerivationType type() const
Definition derivations.cc:678
StorePathSet inputSrcs
Definition derivations.hh:282
Definition content-address.hh:65
Definition content-address.hh:126
Definition derivations.hh:46
StorePath path(const Store &store, std::string_view drvName, OutputNameView outputName) const
Definition derivations.cc:41
ContentAddress ca
Definition derivations.hh:52
Definition derivations.hh:71
ContentAddressMethod method
Definition derivations.hh:75
HashType hashType
Definition derivations.hh:80
Definition derivations.hh:89
Definition derivations.hh:98
ContentAddressMethod method
Definition derivations.hh:102
HashType hashType
Definition derivations.hh:107
Definition derivations.hh:35
std::optional< StorePath > path(const Store &store, std::string_view drvName, OutputNameView outputName) const
Definition derivations.cc:17
static DerivationOutput fromJSON(const Store &store, std::string_view drvName, OutputNameView outputName, const JSON &json, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
Definition derivations.cc:1279
Definition derivations.hh:189
bool sandboxed
Definition derivations.hh:193
bool fixed
Definition derivations.hh:205
Definition derivations.hh:216
Definition derivations.hh:175
bool deferred
Definition derivations.hh:181
Definition derivations.hh:171
bool isSandboxed() const
Definition derivations.cc:99
bool hasKnownOutputPaths() const
Definition derivations.cc:83
bool isFixed() const
Definition derivations.cc:68
bool isPure() const
Definition derivations.cc:115
bool isCA() const
Definition derivations.cc:49
Definition derivations.hh:324
kj::Promise< Result< std::optional< BasicDerivation > > > tryResolve(Store &store, Store *evalStore=nullptr) const
Definition derivations.cc:1070
DerivedPathMap< std::set< OutputName > > inputDrvs
Definition derivations.hh:328
std::string unparse(const Store &store, bool maskOutputs, DerivedPathMap< StringSet >::ChildNode::Map *actualInputs=nullptr) const
Definition derivations.cc:566
kj::Promise< Result< void > > checkInvariants(Store &store, const StorePath &drvPath) const
Definition derivations.cc:1173
std::map< OutputName, ChildNode > Map
Definition derived-path-map.hh:43
Definition derived-path-map.hh:28
Definition derivations.hh:426
Kind kind
Definition derivations.hh:449
Kind
Definition derivations.hh:432
@ Deferred
Definition derivations.hh:442
@ Regular
Definition derivations.hh:437
std::map< std::string, Hash > hashes
Definition derivations.hh:430
Definition hash.hh:41
Definition serialise.hh:18
Definition serialise.hh:66
std::string Path
Definition types.hh:28
#define MAKE_WRAPPER_CONSTRUCTOR(CLASS_NAME)
Definition variant-wrapper.hh:27