about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/derivations.hh
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-17T13·30-0400
committerglittershark <grfn@gws.fyi>2020-07-18T19·52+0000
commita79df261b498473ae7c6d4a04f32c50d5954124f (patch)
tree1758dd00cc3c541cd67801bd30cbef8c62aca593 /third_party/nix/src/libstore/derivations.hh
parent3f4e5050cd046c137ff6d0a1bd046c5494f60471 (diff)
feat(3p/nix/nix-daemon): Implement Worker::BuildDerivation handler r/1382
Implement the proto handler on the server side for
Worker::BuildDerivation. This includes several additions to the proto
which I had missed on the first pass, including the actual proto
definition for the Derivation itself and a few sequence number
reorderings which are fine because this is all provisional and not
deployed yet.

A couple things to note

- I implemented a couple constructors for nix classes that initialize
  themselves based on their proto variants, which felt nice and didn't
  end up causing any issues.
- I've made the conversions between the enum types in nix and in proto
  explicit via switch statements rather than using a static_cast, out of
  an abundance of caution that the error would get mismatched in the
  future and we'd convert the wrong thing to the wrong thing - this is
  verbose, but exceptionally future proof.

Change-Id: Iecf6b88e76bc37e49efa05fd65d6cd0cb0deffed
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1249
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Reviewed-by: Kane York <rikingcoding@gmail.com>
Diffstat (limited to 'third_party/nix/src/libstore/derivations.hh')
-rw-r--r--third_party/nix/src/libstore/derivations.hh19
1 files changed, 19 insertions, 0 deletions
diff --git a/third_party/nix/src/libstore/derivations.hh b/third_party/nix/src/libstore/derivations.hh
index 7574aa90c2c4..d8a5dbf09246 100644
--- a/third_party/nix/src/libstore/derivations.hh
+++ b/third_party/nix/src/libstore/derivations.hh
@@ -2,6 +2,7 @@
 
 #include <map>
 
+#include "libproto/worker.pb.h"
 #include "libstore/store-api.hh"
 #include "libutil/hash.hh"
 #include "libutil/types.hh"
@@ -18,20 +19,31 @@ struct DerivationOutput {
   std::string hashAlgo; /* hash used for expected hash computation */
   std::string hash;     /* expected hash, may be null */
   DerivationOutput() {}
+  // TODO(grfn): Make explicit
   DerivationOutput(Path path, std::string hashAlgo, std::string hash) {
     this->path = path;
     this->hashAlgo = hashAlgo;
     this->hash = hash;
   }
+
+  explicit DerivationOutput(
+      const nix::proto::Derivation_DerivationOutput& proto_derivation_output)
+      : path(proto_derivation_output.path().path()),
+        hashAlgo(proto_derivation_output.hash_algo()),
+        hash(proto_derivation_output.hash()) {}
+
   void parseHashInfo(bool& recursive, Hash& hash) const;
 };
 
+// TODO(grfn): change to absl::flat_hash_map
 typedef std::map<std::string, DerivationOutput> DerivationOutputs;
 
 /* For inputs that are sub-derivations, we specify exactly which
    output IDs we are interested in. */
+// TODO(grfn): change to absl::flat_hash_map
 typedef std::map<Path, StringSet> DerivationInputs;
 
+// TODO(grfn): change to absl::flat_hash_map
 typedef std::map<std::string, std::string> StringPairs;
 
 struct BasicDerivation {
@@ -42,6 +54,13 @@ struct BasicDerivation {
   Strings args;
   StringPairs env;
 
+  BasicDerivation(){};
+
+  // Convert the given proto derivation to a BasicDerivation in the given
+  // nix::Store.
+  static BasicDerivation from_proto(
+      const nix::proto::Derivation* proto_derivation, const nix::Store* store);
+
   virtual ~BasicDerivation(){};
 
   /* Return the path corresponding to the output identifier `id' in