From e3cb536f19920018b522f76ac2661d68627b7c9e Mon Sep 17 00:00:00 2001
From: Matthew Bauer <mjbauer95@gmail.com>
Date: Fri, 12 Jun 2020 15:25:29 -0500
Subject: [PATCH] Fix add-to-store --flat to put in correct hash

---
 src/nix/add-to-store.cc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc
index a5a77f17c..26edcf95a 100644
--- a/src/nix/add-to-store.cc
+++ b/src/nix/add-to-store.cc
@@ -53,14 +53,10 @@ struct CmdAddToStore : MixDryRun, StoreCommand
 
         auto narHash = hashString(htSHA256, *sink.s);
 
-        ValidPathInfo info(store->makeFixedOutputPath(ingestionMethod, narHash, *namePart));
-        info.narHash = narHash;
-        info.narSize = sink.s->size();
-
         Hash hash;
         switch (ingestionMethod) {
         case FileIngestionMethod::Recursive: {
-            hash = info.narHash;
+            hash = narHash;
             break;
         }
         case FileIngestionMethod::Flat: {
@@ -70,6 +66,10 @@ struct CmdAddToStore : MixDryRun, StoreCommand
             break;
         }
         }
+
+        ValidPathInfo info(store->makeFixedOutputPath(ingestionMethod, hash, *namePart));
+        info.narHash = narHash;
+        info.narSize = sink.s->size();
         info.ca = makeFixedOutputCA(ingestionMethod, hash);
 
         if (!dryRun) {