forked from lix-project/lix
8e0d0689be
we don’t need a full storepath for a fixedoutput derivation. So just putting the ingestion method + the hash is sufficient.
113 lines
2.9 KiB
C++
113 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include "path.hh"
|
|
#include "types.hh"
|
|
#include "hash.hh"
|
|
#include "content-address.hh"
|
|
|
|
#include <map>
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
/* Abstract syntax of derivations. */
|
|
|
|
struct DerivationOutputIntensional
|
|
{
|
|
StorePath path;
|
|
};
|
|
|
|
struct DerivationOutputFixed
|
|
{
|
|
FixedOutputHash hash; /* hash used for expected hash computation */
|
|
};
|
|
|
|
struct DerivationOutput
|
|
{
|
|
std::variant<DerivationOutputIntensional, DerivationOutputFixed> output;
|
|
StorePath path(const Store & store, string drvName) const;
|
|
};
|
|
|
|
typedef std::map<string, DerivationOutput> DerivationOutputs;
|
|
|
|
/* For inputs that are sub-derivations, we specify exactly which
|
|
output IDs we are interested in. */
|
|
typedef std::map<StorePath, StringSet> DerivationInputs;
|
|
|
|
typedef std::map<string, string> StringPairs;
|
|
|
|
struct BasicDerivation
|
|
{
|
|
DerivationOutputs outputs; /* keyed on symbolic IDs */
|
|
StorePathSet inputSrcs; /* inputs that are sources */
|
|
string platform;
|
|
Path builder;
|
|
Strings args;
|
|
StringPairs env;
|
|
string name;
|
|
|
|
BasicDerivation() { }
|
|
virtual ~BasicDerivation() { };
|
|
|
|
/* Return the path corresponding to the output identifier `id' in
|
|
the given derivation. */
|
|
const StorePath & findOutput(const Store & store, const std::string & id) const;
|
|
|
|
bool isBuiltin() const;
|
|
|
|
/* Return true iff this is a fixed-output derivation. */
|
|
bool isFixedOutput() const;
|
|
|
|
/* Return the output paths of a derivation. */
|
|
StorePathSet outputPaths(const Store & store) const;
|
|
|
|
/* Return the output names of a derivation. */
|
|
StringSet outputNames() const;
|
|
};
|
|
|
|
struct Derivation : BasicDerivation
|
|
{
|
|
DerivationInputs inputDrvs; /* inputs that are sub-derivations */
|
|
|
|
/* Print a derivation. */
|
|
std::string unparse(const Store & store, bool maskOutputs,
|
|
std::map<std::string, StringSet> * actualInputs = nullptr) const;
|
|
|
|
Derivation() { }
|
|
};
|
|
|
|
|
|
class Store;
|
|
|
|
enum RepairFlag : bool { NoRepair = false, Repair = true };
|
|
|
|
/* Write a derivation to the Nix store, and return its path. */
|
|
StorePath writeDerivation(ref<Store> store,
|
|
const Derivation & drv, std::string_view name, RepairFlag repair = NoRepair);
|
|
|
|
/* Read a derivation from a file. */
|
|
Derivation readDerivation(const Store & store, const Path & drvPath, string name);
|
|
|
|
// FIXME: remove
|
|
bool isDerivation(const string & fileName);
|
|
|
|
Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutputs);
|
|
|
|
/* Memoisation of hashDerivationModulo(). */
|
|
typedef std::map<StorePath, Hash> DrvHashes;
|
|
|
|
extern DrvHashes drvHashes; // FIXME: global, not thread-safe
|
|
|
|
bool wantOutput(const string & output, const std::set<string> & wanted);
|
|
|
|
struct Source;
|
|
struct Sink;
|
|
|
|
Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv, string name);
|
|
void writeDerivation(Sink & out, const Store & store, const BasicDerivation & drv);
|
|
|
|
std::string hashPlaceholder(const std::string & outputName);
|
|
|
|
}
|