1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-25 19:51:00 +01:00

Derivations can output "text-hashed" data

In particular, this means that derivations can output derivations. But
that ramification isn't (yet!) useful as we would want, since there is
no way to have a dependent derivation that is itself a dependent
derivation.
This commit is contained in:
John Ericson 2020-10-12 23:51:23 +00:00
parent a0f369aa3f
commit a4e5de1b9d
15 changed files with 322 additions and 137 deletions

View file

@ -10,11 +10,45 @@ namespace nix {
* Mini content address
*/
/* We only have one way to hash text with references, so this is a single-value
type, mainly useful with std::variant.
*/
struct TextHashMethod : std::monostate { };
enum struct FileIngestionMethod : uint8_t {
Flat = false,
Recursive = true
};
/* Compute the prefix to the hash algorithm which indicates how the files were
ingested. */
std::string makeFileIngestionPrefix(FileIngestionMethod m);
/* Just the type of a content address. Combine with the hash itself, and we
have a `ContentAddress` as defined below. Combine that, in turn, with info
on references, and we have `ContentAddressWithReferences`, as defined
further below. */
typedef std::variant<
TextHashMethod,
FileIngestionMethod
> ContentAddressMethod;
/* Parse and pretty print the algorithm which indicates how the files
were ingested, with the the fixed output case not prefixed for back
compat. */
std::string makeContentAddressingPrefix(ContentAddressMethod m);
ContentAddressMethod parseContentAddressingPrefix(std::string_view & m);
/* Parse and pretty print a content addressing method and hash in a
nicer way, prefixing both cases. */
std::string renderContentAddressMethodAndHash(ContentAddressMethod cam, HashType ht);
std::pair<ContentAddressMethod, HashType> parseContentAddressMethod(std::string_view caMethod);
struct TextHash {
Hash hash;
@ -27,6 +61,7 @@ struct FixedOutputHash {
std::string printMethodAlgo() const;
};
/*
We've accumulated several types of content-addressed paths over the years;
fixed-output derivations support multiple hash algorithms and serialisation
@ -43,10 +78,6 @@ typedef std::variant<
FixedOutputHash // for path computed by makeFixedOutputPath
> ContentAddress;
/* Compute the prefix to the hash algorithm which indicates how the files were
ingested. */
std::string makeFileIngestionPrefix(const FileIngestionMethod m);
std::string renderContentAddress(ContentAddress ca);
std::string renderContentAddress(std::optional<ContentAddress> ca);
@ -57,24 +88,6 @@ std::optional<ContentAddress> parseContentAddressOpt(std::string_view rawCaOpt);
Hash getContentAddressHash(const ContentAddress & ca);
/*
We only have one way to hash text with references, so this is single-value
type is only useful in std::variant.
*/
struct TextHashMethod { };
struct FixedOutputHashMethod {
FileIngestionMethod fileIngestionMethod;
HashType hashType;
};
typedef std::variant<
TextHashMethod,
FixedOutputHashMethod
> ContentAddressMethod;
ContentAddressMethod parseContentAddressMethod(std::string_view rawCaMethod);
std::string renderContentAddressMethod(ContentAddressMethod caMethod);
/*
* References set
@ -92,6 +105,12 @@ struct PathReferences
&& hasSelfReference == other.hasSelfReference;
}
bool operator != (const PathReferences<Ref> & other) const
{
return references != other.references
|| hasSelfReference != other.hasSelfReference;
}
/* Functions to view references + hasSelfReference as one set, mainly for
compatibility's sake. */
StorePathSet referencesPossiblyToSelf(const Ref & self) const;
@ -151,6 +170,14 @@ typedef std::variant<
ContentAddressWithReferences caWithoutRefs(const ContentAddress &);
ContentAddressWithReferences contentAddressFromMethodHashAndRefs(
ContentAddressMethod method, Hash && hash, PathReferences<StorePath> && refs);
ContentAddressMethod getContentAddressMethod(const ContentAddressWithReferences & ca);
Hash getContentAddressHash(const ContentAddressWithReferences & ca);
std::string printMethodAlgo(const ContentAddressWithReferences &);
struct StorePathDescriptor {
std::string name;
ContentAddressWithReferences info;