feat(3p/nix): Implement AddToStore proto handler

Implement the proto handler for AddToStore, which adds a nix path to the
store. This is implemented by adding a new (probably
soon-to-be-generalized) Source concretion that wraps a grpc ServerReader
for the stream of data we're receiving from the client - this is less
than ideal, as it's perpetuating the source/sink thing that's going on
and storing entire nars in memory, but is at the very worst an
incremental step towards a functioning nix that we can refactor in the
future.

Paired-With: Perry Lorier <isomer@tvl.fyi>
Paired-With: Vincent Ambo <mail@tazj.in>
Change-Id: I48db734e7460a47aee4a85dd5137b690980859e3
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1441
Tested-by: BuildkiteCI
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Griffin Smith 2020-07-25 18:44:37 -04:00 committed by glittershark
parent 1fe4a47aa2
commit 05e44c121d
7 changed files with 141 additions and 13 deletions

View file

@ -2,6 +2,7 @@
#include <absl/status/statusor.h>
#include "libproto/worker.grpc.pb.h"
#include "libutil/serialise.hh"
#include "libutil/types.hh"
@ -9,8 +10,12 @@ namespace nix {
MakeError(BadHash, Error);
// TODO(grfn): Replace this with the hash type enum from the daemon proto so we
// don't have to juggle two different types
enum HashType : char { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 };
std::optional<HashType> hash_type_from(nix::proto::HashType hash_type);
const int md5HashSize = 16;
const int sha1HashSize = 20;
const int sha256HashSize = 32;