Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
realisation.hh
Go to the documentation of this file.
1#pragma once
3
4#include <variant>
5
6#include "hash.hh"
7#include "path.hh"
8#include "derived-path.hh"
9#include <nlohmann/json_fwd.hpp>
10#include "comparator.hh"
11#include "signature/signer.hh"
12
13namespace nix {
14
15class Store;
16struct OutputsSpec;
17
24struct DrvOutput {
33
38
39 std::string to_string() const;
40
41 std::string strHash() const
42 { return drvHash.to_string(HashFormat::Base16, true); }
43
44 static DrvOutput parse(const std::string &);
45
46 GENERATE_CMP(DrvOutput, me->drvHash, me->outputName);
47};
48
50 DrvOutput id;
51 StorePath outPath;
52
53 StringSet signatures;
54
61 std::map<DrvOutput, StorePath> dependentRealisations;
62
63 nlohmann::json toJSON() const;
64 static Realisation fromJSON(const nlohmann::json& json, const std::string& whence);
65
66 std::string fingerprint() const;
67 void sign(const Signer &);
68 bool checkSignature(const PublicKeys & publicKeys, const std::string & sig) const;
69 size_t checkSignatures(const PublicKeys & publicKeys) const;
70
71 static std::set<Realisation> closure(Store &, const std::set<Realisation> &);
72 static void closure(Store &, const std::set<Realisation> &, std::set<Realisation> & res);
73
74 bool isCompatibleWith(const Realisation & other) const;
75
76 StorePath getPath() const { return outPath; }
77
78 GENERATE_CMP(Realisation, me->id, me->outPath);
79};
80
87typedef std::map<OutputName, Realisation> SingleDrvOutputs;
88
96typedef std::map<DrvOutput, Realisation> DrvOutputs;
97
103SingleDrvOutputs filterDrvOutputs(const OutputsSpec&, SingleDrvOutputs&&);
104
105
107 StorePath path;
108
109 StorePath getPath() const { return path; }
110
111 GENERATE_CMP(OpaquePath, me->path);
112};
113
114
118struct RealisedPath {
119 /*
120 * A path is either the result of the realisation of a derivation or
121 * an opaque blob that has been directly added to the store
122 */
123 using Raw = std::variant<Realisation, OpaquePath>;
124 Raw raw;
125
126 using Set = std::set<RealisedPath>;
127
128 RealisedPath(StorePath path) : raw(OpaquePath{path}) {}
129 RealisedPath(Realisation r) : raw(r) {}
130
134 StorePath path() const;
135
136 void closure(Store& store, Set& ret) const;
137 static void closure(Store& store, const Set& startPaths, Set& ret);
138 Set closure(Store& store) const;
139
140 GENERATE_CMP(RealisedPath, me->raw);
141};
142
143class MissingRealisation : public Error
144{
145public:
146 MissingRealisation(DrvOutput & outputId)
147 : MissingRealisation(outputId.outputName, outputId.strHash())
148 {}
149 MissingRealisation(std::string_view drv, OutputName outputName)
150 : Error( "cannot operate on output '%s' of the "
151 "unbuilt derivation '%s'",
152 outputName,
153 drv)
154 {}
155};
156
157}
Definition path.hh:27
Definition store-api.hh:169
ChunkedVector< std::string, 8192 > store
Definition lexer.l:1011
Strings res
Definition lexer.l:2566
std::string OutputName
Definition outputs-spec.hh:18
@ Base16
Lowercase hexadecimal encoding.
Definition hash.hh:36
std::map< DrvOutput, Realisation > DrvOutputs
Definition realisation.hh:96
std::map< OutputName, Realisation > SingleDrvOutputs
Definition realisation.hh:87
Definition realisation.hh:24
OutputName outputName
Definition realisation.hh:37
Hash drvHash
Definition realisation.hh:32
Definition hash.hh:45
Definition realisation.hh:106
Definition outputs-spec.hh:26
Definition realisation.hh:49
std::map< DrvOutput, StorePath > dependentRealisations
Definition realisation.hh:61
StorePath path() const
Definition realisation.cc:153