mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 16:26:18 +02:00
WIP
This commit is contained in:
parent
0e9438b6d3
commit
da39092a39
5 changed files with 47 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
#include "hash.hh"
|
#include "hash.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -23,6 +24,22 @@ struct FileSystemHash {
|
||||||
std::string printMethodAlgo() const;
|
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
|
||||||
|
methods (flat file vs NAR). Thus, ‘ca’ has one of the following forms:
|
||||||
|
|
||||||
|
* ‘text:sha256:<sha256 hash of file contents>’: For paths
|
||||||
|
computed by makeTextPath() / addTextToStore().
|
||||||
|
|
||||||
|
* ‘fixed:<r?>:<ht>:<h>’: For paths computed by
|
||||||
|
makeFixedOutputPath() / addToStore().
|
||||||
|
*/
|
||||||
|
typedef std::variant<
|
||||||
|
Hash, // for paths computed by makeTextPath() / addTextToStore
|
||||||
|
FileSystemHash // for path computed by makeFixedOutputPath
|
||||||
|
> ContentAddress;
|
||||||
|
|
||||||
/* Compute the prefix to the hash algorithm which indicates how the files were
|
/* Compute the prefix to the hash algorithm which indicates how the files were
|
||||||
ingested. */
|
ingested. */
|
||||||
std::string makeFileIngestionPrefix(const FileIngestionMethod m);
|
std::string makeFileIngestionPrefix(const FileIngestionMethod m);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "rust-ffi.hh"
|
#include "rust-ffi.hh"
|
||||||
|
#include "file-hash.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -87,6 +88,15 @@ const size_t storePathHashLen = 32; // i.e. 160 bits
|
||||||
/* Extension of derivations in the Nix store. */
|
/* Extension of derivations in the Nix store. */
|
||||||
const std::string drvExtension = ".drv";
|
const std::string drvExtension = ".drv";
|
||||||
|
|
||||||
|
std::string to_string(FileIngestionMethod m) {
|
||||||
|
switch(m) {
|
||||||
|
case FileIngestionMethod::Flat:
|
||||||
|
return "false";
|
||||||
|
case FileIngestionMethod::Recursive:
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct StorePathWithOutputs
|
struct StorePathWithOutputs
|
||||||
{
|
{
|
||||||
StorePath path;
|
StorePath path;
|
||||||
|
|
|
@ -467,7 +467,7 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & store
|
||||||
jsonRefs.elem(printStorePath(ref));
|
jsonRefs.elem(printStorePath(ref));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->ca != "")
|
if (info->ca)
|
||||||
jsonPath.attr("ca", info->ca);
|
jsonPath.attr("ca", info->ca);
|
||||||
|
|
||||||
std::pair<uint64_t, uint64_t> closureSizes;
|
std::pair<uint64_t, uint64_t> closureSizes;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -110,6 +111,19 @@ struct SubstitutablePathInfo
|
||||||
|
|
||||||
typedef std::map<StorePath, SubstitutablePathInfo> SubstitutablePathInfos;
|
typedef std::map<StorePath, SubstitutablePathInfo> SubstitutablePathInfos;
|
||||||
|
|
||||||
|
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
|
||||||
|
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
||||||
|
|
||||||
|
std::string renderContentAddress(ContentAddress ca) {
|
||||||
|
return std::visit(overloaded {
|
||||||
|
[](Hash hash) {
|
||||||
|
return "text:" + hash.to_string();
|
||||||
|
},
|
||||||
|
[](FileSystemHash fsh) {
|
||||||
|
return makeFixedOutputCA(fsh.method, fsh.hash);
|
||||||
|
}
|
||||||
|
}, ca);
|
||||||
|
}
|
||||||
|
|
||||||
struct ValidPathInfo
|
struct ValidPathInfo
|
||||||
{
|
{
|
||||||
|
@ -139,21 +153,11 @@ struct ValidPathInfo
|
||||||
that a particular output path was produced by a derivation; the
|
that a particular output path was produced by a derivation; the
|
||||||
path then implies the contents.)
|
path then implies the contents.)
|
||||||
|
|
||||||
Ideally, the content-addressability assertion would just be a
|
Ideally, the content-addressability assertion would just be a Boolean,
|
||||||
Boolean, and the store path would be computed from
|
and the store path would be computed from the name component, ‘narHash’
|
||||||
the name component, ‘narHash’ and ‘references’. However,
|
and ‘references’. However, we support many types of content addresses.
|
||||||
1) we've accumulated several types of content-addressed paths
|
|
||||||
over the years; and 2) fixed-output derivations support
|
|
||||||
multiple hash algorithms and serialisation methods (flat file
|
|
||||||
vs NAR). Thus, ‘ca’ has one of the following forms:
|
|
||||||
|
|
||||||
* ‘text:sha256:<sha256 hash of file contents>’: For paths
|
|
||||||
computed by makeTextPath() / addTextToStore().
|
|
||||||
|
|
||||||
* ‘fixed:<r?>:<ht>:<h>’: For paths computed by
|
|
||||||
makeFixedOutputPath() / addToStore().
|
|
||||||
*/
|
*/
|
||||||
std::string ca;
|
std::optional<ContentAddress> ca;
|
||||||
|
|
||||||
bool operator == (const ValidPathInfo & i) const
|
bool operator == (const ValidPathInfo & i) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -856,7 +856,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
||||||
out << info->narSize // downloadSize
|
out << info->narSize // downloadSize
|
||||||
<< info->narSize;
|
<< info->narSize;
|
||||||
if (GET_PROTOCOL_MINOR(clientVersion) >= 4)
|
if (GET_PROTOCOL_MINOR(clientVersion) >= 4)
|
||||||
out << (info->narHash ? info->narHash.to_string() : "") << info->ca << info->sigs;
|
out << (info->narHash ? info->narHash.to_string() : "") << renderContentAddress(info->ca) << info->sigs;
|
||||||
} catch (InvalidPath &) {
|
} catch (InvalidPath &) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue