Skip to content

Commit f79effe

Browse files
committed
remote: fix handling of BuildResult.builtOutputs
1 parent 9c407cb commit f79effe

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

hnix-store-json/src/System/Nix/JSON.hs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ which is required for `-remote`.
1010
module System.Nix.JSON where
1111

1212
import Data.Aeson
13+
import Data.Aeson.Types (toJSONKeyText)
1314
import Deriving.Aeson
1415
import System.Nix.Base (BaseEncoding(NixBase32))
1516
import System.Nix.OutputName (OutputName)
@@ -90,7 +91,13 @@ instance ToJSON (DerivationOutput OutputName) where
9091
. System.Nix.Realisation.derivationOutputBuilder
9192
System.Nix.OutputName.unOutputName
9293

93-
instance ToJSONKey (DerivationOutput OutputName)
94+
instance ToJSONKey (DerivationOutput OutputName) where
95+
toJSONKey =
96+
toJSONKeyText
97+
$ Data.Text.Lazy.toStrict
98+
. Data.Text.Lazy.Builder.toLazyText
99+
. System.Nix.Realisation.derivationOutputBuilder
100+
System.Nix.OutputName.unOutputName
94101

95102
instance FromJSON (DerivationOutput OutputName) where
96103
parseJSON =
@@ -102,7 +109,15 @@ instance FromJSON (DerivationOutput OutputName) where
102109
System.Nix.OutputName.mkOutputName
103110
)
104111

105-
instance FromJSONKey (DerivationOutput OutputName)
112+
instance FromJSONKey (DerivationOutput OutputName) where
113+
fromJSONKey =
114+
FromJSONKeyTextParser
115+
( either
116+
(fail . show)
117+
pure
118+
. System.Nix.Realisation.derivationOutputParser
119+
System.Nix.OutputName.mkOutputName
120+
)
106121

107122
instance ToJSON Signature where
108123
toJSON = toJSON . System.Nix.Signature.signatureToText

hnix-store-json/tests/JSONSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ spec = do
9595
encode sampleDerivationOutput `shouldBe` "\"sha256:1b4sb93wp679q4zx9k1ignby1yna3z7c4c2ri3wphylbc2dwsys0!foo\""
9696

9797
it "sampleRealisation0 matches preimage" $
98-
encode sampleRealisation0 `shouldBe` "{\"outPath\":\"cdips4lakfk1qbf1x68fq18wnn3r5r14-builder.sh\",\"signatures\":[],\"dependentRealisations\":[]}"
98+
encode sampleRealisation0 `shouldBe` "{\"outPath\":\"cdips4lakfk1qbf1x68fq18wnn3r5r14-builder.sh\",\"signatures\":[],\"dependentRealisations\":{}}"
9999

100100
it "sampleRealisation1 matches preimage" $
101-
encode sampleRealisation1 `shouldBe` "{\"outPath\":\"5rwxzi7pal3qhpsyfc16gzkh939q1np6-curl-7.82.0.drv\",\"signatures\":[\"SMjnB3mPgXYjXacU+xN24BdzXlAgGAuFnYwPddU3bhjfHBeQus/OimdIPMgR/JMKFPHXORrk7pbjv68vecTEBA==\",\"fW3iEMfyx6IZzGNswD54BjclfkXiYzh0xRXddrXfJ1rp1l8p1xTi9/0g2EibbwLFb6p83cwIJv5KtTGksC54CQ==\"],\"dependentRealisations\":[[\"sha256:1b4sb93wp679q4zx9k1ignby1yna3z7c4c2ri3wphylbc2dwsys0!foo\",\"9472ijanf79nlkb5n1yh57s7867p1930-testFixed\"]]}"
101+
encode sampleRealisation1 `shouldBe` "{\"outPath\":\"5rwxzi7pal3qhpsyfc16gzkh939q1np6-curl-7.82.0.drv\",\"signatures\":[\"SMjnB3mPgXYjXacU+xN24BdzXlAgGAuFnYwPddU3bhjfHBeQus/OimdIPMgR/JMKFPHXORrk7pbjv68vecTEBA==\",\"fW3iEMfyx6IZzGNswD54BjclfkXiYzh0xRXddrXfJ1rp1l8p1xTi9/0g2EibbwLFb6p83cwIJv5KtTGksC54CQ==\"],\"dependentRealisations\":{\"sha256:1b4sb93wp679q4zx9k1ignby1yna3z7c4c2ri3wphylbc2dwsys0!foo\":\"9472ijanf79nlkb5n1yh57s7867p1930-testFixed\"}}"
102102

103103
forceRight
104104
:: Show a

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ library
107107
build-depends:
108108
base >=4.12 && <5
109109
, hnix-store-core >= 0.8 && <0.9
110+
, hnix-store-json >= 0.1
110111
, hnix-store-nar >= 0.1
111112
, hnix-store-tests >= 0.1
113+
, aeson
112114
, attoparsec
113115
, bytestring
114116
, cereal

hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import qualified Control.Monad.Reader
113113
import qualified Data.Attoparsec.Text
114114
import qualified Data.Bits
115115
import qualified Data.ByteString
116+
import qualified Data.ByteString.Lazy
116117
import qualified Data.HashSet
117118
import qualified Data.Map.Strict
118119
import qualified Data.Maybe
@@ -133,6 +134,7 @@ import System.Nix.ContentAddress (ContentAddress)
133134
import System.Nix.Derivation (Derivation(..), DerivationOutput(..))
134135
import System.Nix.DerivedPath (DerivedPath, ParseOutputsError)
135136
import System.Nix.Hash (HashAlgo(..))
137+
import System.Nix.JSON ()
136138
import System.Nix.OutputName (OutputName)
137139
import System.Nix.Realisation (DerivationOutputError, Realisation(..))
138140
import System.Nix.Signature (Signature, NarSignature)
@@ -141,6 +143,7 @@ import System.Nix.StorePath (HasStoreDir(..), InvalidNameError, InvalidPathError
141143
import System.Nix.StorePath.Metadata (Metadata(..), StorePathTrust(..))
142144
import System.Nix.Store.Remote.Types
143145

146+
import qualified Data.Aeson
144147
import qualified Data.Coerce
145148
import qualified Data.Bifunctor
146149
import qualified Data.Some
@@ -616,14 +619,11 @@ realisation
616619
=> NixSerializer r SError Realisation
617620
realisation = Serializer
618621
{ getS = do
619-
realisationOutPath <- getS storePath
620-
realisationSignatures <- getS (set signature)
621-
realisationDependencies <- getS (mapS derivationOutputTyped storePath)
622-
pure Realisation{..}
623-
, putS = \Realisation{..} -> do
624-
putS storePath realisationOutPath
625-
putS (set signature) realisationSignatures
626-
putS (mapS derivationOutputTyped storePath) realisationDependencies
622+
rb <- getS byteString
623+
case Data.Aeson.eitherDecode (Data.ByteString.Lazy.fromStrict rb) of
624+
Left e -> error e
625+
Right r -> pure r
626+
, putS = putS byteString . Data.ByteString.Lazy.toStrict . Data.Aeson.encode
627627
}
628628

629629
-- * Signatures
@@ -816,7 +816,11 @@ buildResult = Serializer
816816

817817
buildResultBuiltOutputs <-
818818
if protoVersion_minor pv >= 28
819-
then pure <$> getS (mapS outputName realisation)
819+
then
820+
pure
821+
. Data.Map.Strict.mapKeys
822+
System.Nix.Realisation.derivationOutputName
823+
<$> getS (mapS derivationOutputTyped realisation)
820824
else pure Nothing
821825
pure BuildResult{..}
822826

@@ -831,6 +835,7 @@ buildResult = Serializer
831835
putS time $ Data.Maybe.fromMaybe t0 buildResultStartTime
832836
putS time $ Data.Maybe.fromMaybe t0 buildResultStopTime
833837
Control.Monad.when (protoVersion_minor pv >= 28)
838+
-- TODO realisation.id
834839
$ putS (mapS outputName realisation)
835840
$ Data.Maybe.fromMaybe mempty buildResultBuiltOutputs
836841
}

0 commit comments

Comments
 (0)