From 28c7e926ea48e4f5e57b9b8d1a70ccc494b2c188 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 3 Aug 2020 23:50:42 -0400 Subject: feat(3p/nix): Implement AddToStore rpc client Implement the AddToStore RPC client method, which uses an AddToStorePathWriterSink (the dual of the AddToStorePathReaderSource on the server side) to hook into the dumpPath machinery (which we should refactor not to use sinks or sources, but not yet) and write dumped paths as binary data over gRPC. With this commit and sandboxing disabled, the following derivation builds cleanly: derivation { name = "test"; builder = ./build.sh; system = "x86_64-linux"; } where build.sh has chmod +x and contains: #!/bin/sh echo 1 > $out Change-Id: I94cab86f0825a3a9993262a9807130645c13bf44 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1638 Reviewed-by: kanepyork Tested-by: BuildkiteCI --- third_party/nix/src/libutil/hash.cc | 15 +++++++++++++++ third_party/nix/src/libutil/hash.hh | 2 ++ 2 files changed, 17 insertions(+) (limited to 'third_party/nix/src/libutil') diff --git a/third_party/nix/src/libutil/hash.cc b/third_party/nix/src/libutil/hash.cc index 97cc137b11a7..f7ee44728f60 100644 --- a/third_party/nix/src/libutil/hash.cc +++ b/third_party/nix/src/libutil/hash.cc @@ -35,6 +35,21 @@ std::optional hash_type_from(nix::proto::HashType hash_type) { } } +nix::proto::HashType HashTypeToProto(HashType hash_type) { + switch (hash_type) { + case HashType::htMD5: + return nix::proto::HashType::MD5; + case HashType::htSHA1: + return nix::proto::HashType::SHA1; + case HashType::htSHA256: + return nix::proto::HashType::SHA256; + case HashType::htSHA512: + return nix::proto::HashType::SHA512; + default: + return nix::proto::HashType::UNKNOWN; + } +} + void Hash::init() { if (type == htMD5) { hashSize = md5HashSize; diff --git a/third_party/nix/src/libutil/hash.hh b/third_party/nix/src/libutil/hash.hh index bc32f9146373..4d52702aee75 100644 --- a/third_party/nix/src/libutil/hash.hh +++ b/third_party/nix/src/libutil/hash.hh @@ -16,6 +16,8 @@ enum HashType : char { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 }; std::optional hash_type_from(nix::proto::HashType hash_type); +nix::proto::HashType HashTypeToProto(HashType hash_type); + const int md5HashSize = 16; const int sha1HashSize = 20; const int sha256HashSize = 32; -- cgit 1.4.1