Skip to content

Commit 1cdf67e

Browse files
committed
Remove overcomplicated JSON instance for derivation path
Sadly this was a hallucination.
1 parent 6b496b7 commit 1cdf67e

File tree

1 file changed

+8
-22
lines changed
  • hnix-store-json/src/System/Nix

1 file changed

+8
-22
lines changed

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -243,33 +243,19 @@ instance FromJSON SingleDerivedPath where
243243
instance ToJSON DerivedPath where
244244
toJSON (DerivedPath_Opaque path) = toJSON path
245245
toJSON (DerivedPath_Built drvPath outputs) =
246-
case outputs of
247-
OutputsSpec_Names names | Data.Set.size names == 1 ->
248-
object
249-
[ "drvPath" .= toJSON drvPath
250-
, "output" .= Data.Set.elemAt 0 names
251-
]
252-
_ ->
253-
object
254-
[ "drvPath" .= toJSON drvPath
255-
, "outputs" .= outputs
256-
]
246+
object
247+
[ "drvPath" .= toJSON drvPath
248+
, "outputs" .= outputs
249+
]
257250

258251
instance FromJSON DerivedPath where
259252
parseJSON v = parseOpaque v <|> parseBuilt v
260253
where
261254
parseOpaque = fmap DerivedPath_Opaque . parseJSON
262-
parseBuilt = withObject "DerivedPath_Built" $ \obj -> do
263-
drvPath <- obj .: "drvPath"
264-
-- Try single output first, then multiple outputs
265-
mOutput <- obj .:? "output"
266-
mOutputs <- obj .:? "outputs"
267-
case (mOutput, mOutputs) of
268-
(Just output, Nothing) ->
269-
pure $ DerivedPath_Built drvPath (OutputsSpec_Names (Data.Set.singleton output))
270-
(Nothing, Just outputs) ->
271-
pure $ DerivedPath_Built drvPath outputs
272-
_ -> fail "Expected either 'output' or 'outputs' field"
255+
parseBuilt = withObject "DerivedPath_Built" $ \obj ->
256+
DerivedPath_Built
257+
<$> obj .: "drvPath"
258+
<*> obj .: "outputs"
273259

274260
data LowerLeading
275261
instance StringModifier LowerLeading where

0 commit comments

Comments
 (0)