2020-10-08 15:36:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "path.hh"
|
2020-12-08 20:07:52 +00:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2021-02-04 14:11:05 +00:00
|
|
|
#include "comparator.hh"
|
2021-03-08 10:56:33 +00:00
|
|
|
#include "crypto.hh"
|
2020-12-14 16:24:30 +00:00
|
|
|
|
2020-10-08 15:36:51 +00:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
struct DrvOutput {
|
2020-12-09 15:56:56 +00:00
|
|
|
// The hash modulo of the derivation
|
|
|
|
Hash drvHash;
|
2020-10-08 15:36:51 +00:00
|
|
|
std::string outputName;
|
|
|
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
2020-12-09 15:56:56 +00:00
|
|
|
std::string strHash() const
|
|
|
|
{ return drvHash.to_string(Base16, true); }
|
|
|
|
|
2020-10-08 15:36:51 +00:00
|
|
|
static DrvOutput parse(const std::string &);
|
|
|
|
|
2020-12-14 16:24:30 +00:00
|
|
|
GENERATE_CMP(DrvOutput, me->drvHash, me->outputName);
|
2020-10-08 15:36:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Realisation {
|
|
|
|
DrvOutput id;
|
|
|
|
StorePath outPath;
|
|
|
|
|
2021-03-08 10:56:33 +00:00
|
|
|
StringSet signatures;
|
|
|
|
|
2021-05-26 14:09:02 +00:00
|
|
|
/**
|
|
|
|
* The realisations that are required for the current one to be valid.
|
|
|
|
*
|
|
|
|
* When importing this realisation, the store will first check that all its
|
|
|
|
* dependencies exist, and map to the correct output path
|
|
|
|
*/
|
|
|
|
std::map<DrvOutput, StorePath> dependentRealisations;
|
2020-11-10 13:49:25 +00:00
|
|
|
|
2020-12-08 20:07:52 +00:00
|
|
|
nlohmann::json toJSON() const;
|
|
|
|
static Realisation fromJSON(const nlohmann::json& json, const std::string& whence);
|
2020-12-14 16:24:30 +00:00
|
|
|
|
2021-03-08 10:56:33 +00:00
|
|
|
std::string fingerprint() const;
|
|
|
|
void sign(const SecretKey &);
|
|
|
|
bool checkSignature(const PublicKeys & publicKeys, const std::string & sig) const;
|
|
|
|
size_t checkSignatures(const PublicKeys & publicKeys) const;
|
|
|
|
|
2021-06-21 14:37:45 +00:00
|
|
|
static std::set<Realisation> closure(Store &, const std::set<Realisation> &);
|
2021-07-19 13:43:08 +00:00
|
|
|
static void closure(Store &, const std::set<Realisation> &, std::set<Realisation> & res);
|
2021-05-19 08:26:58 +00:00
|
|
|
|
2021-05-19 14:19:46 +00:00
|
|
|
bool isCompatibleWith(const Realisation & other) const;
|
|
|
|
|
2020-12-14 16:24:30 +00:00
|
|
|
StorePath getPath() const { return outPath; }
|
|
|
|
|
|
|
|
GENERATE_CMP(Realisation, me->id, me->outPath);
|
|
|
|
};
|
|
|
|
|
2021-01-26 09:48:41 +00:00
|
|
|
typedef std::map<DrvOutput, Realisation> DrvOutputs;
|
|
|
|
|
2020-12-14 16:24:30 +00:00
|
|
|
struct OpaquePath {
|
|
|
|
StorePath path;
|
|
|
|
|
|
|
|
StorePath getPath() const { return path; }
|
|
|
|
|
|
|
|
GENERATE_CMP(OpaquePath, me->path);
|
2020-10-08 15:36:51 +00:00
|
|
|
};
|
|
|
|
|
2020-12-14 16:24:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A store path with all the history of how it went into the store
|
|
|
|
*/
|
|
|
|
struct RealisedPath {
|
|
|
|
/*
|
|
|
|
* A path is either the result of the realisation of a derivation or
|
|
|
|
* an opaque blob that has been directly added to the store
|
|
|
|
*/
|
|
|
|
using Raw = std::variant<Realisation, OpaquePath>;
|
|
|
|
Raw raw;
|
|
|
|
|
|
|
|
using Set = std::set<RealisedPath>;
|
|
|
|
|
|
|
|
RealisedPath(StorePath path) : raw(OpaquePath{path}) {}
|
|
|
|
RealisedPath(Realisation r) : raw(r) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the raw store path associated to this
|
|
|
|
*/
|
|
|
|
StorePath path() const;
|
|
|
|
|
|
|
|
void closure(Store& store, Set& ret) const;
|
|
|
|
static void closure(Store& store, const Set& startPaths, Set& ret);
|
|
|
|
Set closure(Store& store) const;
|
|
|
|
|
|
|
|
GENERATE_CMP(RealisedPath, me->raw);
|
|
|
|
};
|
2020-10-08 15:36:51 +00:00
|
|
|
|
2023-01-02 16:35:48 +00:00
|
|
|
class MissingRealisation : public Error
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MissingRealisation(DrvOutput & outputId)
|
|
|
|
: Error( "cannot operate on an output of the "
|
|
|
|
"unbuilt derivation '%s'",
|
|
|
|
outputId.to_string())
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2020-10-08 15:36:51 +00:00
|
|
|
}
|