Skip to content

Commit dfb13dd

Browse files
committed
Merge branch 'test-json' into derivation-work
2 parents c63a04e + 2c645e8 commit dfb13dd

File tree

11 files changed

+90
-55
lines changed

11 files changed

+90
-55
lines changed

.github/workflows/ci.dhall

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
let haskellCi =
2-
https://raw.githubusercontent.com/sorki/github-actions-dhall/main/haskell-ci.dhall
2+
https://raw.githubusercontent.com/obsidiansystems/github-actions-dhall/merge-group/haskell-ci.dhall
33

44
let defSteps = haskellCi.defaultCabalSteps
55

6-
in haskellCi.generalCi
6+
let ci =
7+
haskellCi.generalCi
78
( haskellCi.withNix
89
( defSteps
910
with docStep = None haskellCi.BuildStep
@@ -24,4 +25,6 @@ in haskellCi.generalCi
2425
, ghc = [ haskellCi.GHC.GHC9102, haskellCi.GHC.GHC984 ]
2526
, os = [ haskellCi.OS.Ubuntu, haskellCi.OS.MacOS ]
2627
}
27-
: haskellCi.CI.Type
28+
29+
in ci
30+
with on = ci.on // { merge_group = Some haskellCi.MergeGroup.default }

.github/workflows/ci.dhall.frozen

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
let haskellCi =
2-
https://raw.githubusercontent.com/sorki/github-actions-dhall/main/haskell-ci.dhall
3-
sha256:1f1a5102e99ea92eb585b4d36aaeabb0bd93d39e62ba82f3080250fdc234e33a
2+
https://raw.githubusercontent.com/obsidiansystems/github-actions-dhall/merge-group/haskell-ci.dhall
3+
sha256:66e034024b7fa1606428cba5c009999d44dd95613b41acee2700f8e31c7902f1
44

55
let defSteps = haskellCi.defaultCabalSteps
66

7-
in haskellCi.generalCi
7+
let ci =
8+
haskellCi.generalCi
89
( haskellCi.withNix
910
( defSteps
1011
with docStep = None haskellCi.BuildStep
@@ -25,4 +26,6 @@ in haskellCi.generalCi
2526
, ghc = [ haskellCi.GHC.GHC9102, haskellCi.GHC.GHC984 ]
2627
, os = [ haskellCi.OS.Ubuntu, haskellCi.OS.MacOS ]
2728
}
28-
: haskellCi.CI.Type
29+
30+
in ci
31+
with on = ci.on // { merge_group = Some haskellCi.MergeGroup.default }

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ jobs:
5757
- "macos-latest"
5858
name: Haskell CI
5959
'on':
60+
merge_group: {}
6061
pull_request: {}
6162
push: {}

hnix-store-core/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Unreleased
2+
3+
* Additions:
4+
* `System.Nix.Placeholder` module with `createPlaceholder`, `renderPlaceholder`, `DownstreamPlaceholder` support
5+
* `System.Nix.StorePath.ContentAddressed` module
6+
* `textToMethod`, `methodToText` in `System.Nix.ContentAddress`
7+
* `parseBasePath`, `parseBasePathFromText` in `System.Nix.StorePath`
8+
* `textToBaseEncoding`, `baseEncodingToText` in `System.Nix.Base`
9+
* `outputStoreObjectName` in `System.Nix.OutputName`
10+
* `SingleDerivedPath` type with `parseSingleDerivedPath`, `singleDerivedPathToText`
11+
12+
* Changes:
13+
* `OutputName.unOutputName` now returns `StorePathName` instead of `Text`
14+
* `DerivedPath_Built` constructor now takes `SingleDerivedPath` instead of `StorePath`
15+
116
# [0.8.0.0](https://github.com/haskell-nix/hnix-store/compare/core-0.7.0.0...core-0.8.0.0) 2024-07-31
217

318
* Changes:

hnix-store-core/hnix-store-core.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ extra-doc-files:
1717
CHANGELOG.md
1818
extra-source-files:
1919
README.md
20+
, tests/samples/example0.drv
21+
, tests/samples/example1.drv
2022

2123
common commons
2224
ghc-options: -Wall
@@ -96,8 +98,8 @@ library
9698
, monoidal-containers
9799
, some > 1.0.5 && < 2
98100
, these
99-
, time
100101
, text
102+
, time
101103
, unordered-containers
102104
, vector
103105
hs-source-dirs: src

hnix-store-core/src/System/Nix/StorePath.hs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module System.Nix.StorePath
2727
storePathToFilePath
2828
, storePathToRawFilePath
2929
, storePathToText
30+
, storePathBaseToText
31+
, storePathBaseToRawFilePath
3032
, storePathToNarInfo
3133
, storePathHashPartToText
3234
, -- * Parsing 'StorePath's
@@ -191,14 +193,25 @@ instance Default StoreDir where
191193
class HasStoreDir r where
192194
hasStoreDir :: r -> StoreDir
193195

194-
-- | Render a 'StorePath' as a 'RawFilePath'.
195-
storePathToRawFilePath :: StoreDir -> StorePath -> RawFilePath
196-
storePathToRawFilePath storeDir StorePath{..} =
197-
unStoreDir storeDir <> "/" <> hashPart <> "-" <> name
196+
-- | Render a 'StorePath' as a base path (without store directory).
197+
-- This is the relative path format: @hashPart-name@
198+
storePathBaseToRawFilePath :: StorePath -> RawFilePath
199+
storePathBaseToRawFilePath StorePath{..} =
200+
hashPart <> "-" <> name
198201
where
199202
hashPart = Data.Text.Encoding.encodeUtf8 $ storePathHashPartToText storePathHash
200203
name = Data.Text.Encoding.encodeUtf8 $ unStorePathName storePathName
201204

205+
-- | Render a 'StorePath' as a base path 'Text' (without store directory).
206+
-- This is the relative path format: @hashPart-name@
207+
storePathBaseToText :: StorePath -> Text
208+
storePathBaseToText = Data.Text.Encoding.decodeUtf8 . storePathBaseToRawFilePath
209+
210+
-- | Render a 'StorePath' as a 'RawFilePath'.
211+
storePathToRawFilePath :: StoreDir -> StorePath -> RawFilePath
212+
storePathToRawFilePath storeDir sp =
213+
unStoreDir storeDir <> "/" <> storePathBaseToRawFilePath sp
214+
202215
-- | Render a 'StorePath' as a 'FilePath'.
203216
storePathToFilePath :: StoreDir -> StorePath -> FilePath
204217
storePathToFilePath storeDir = Data.ByteString.Char8.unpack . storePathToRawFilePath storeDir

hnix-store-json/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Unreleased
2+
3+
The test suite is now much more comprenesive, uses test data from upstream Nix to make sure the JSON formats match.
4+
5+
* Comprehensive test suite with upstream Nix test data
6+
* Additions:
7+
* JSON instances for `StorePath`, `Hash`, `ContentAddress`
8+
* JSON instances for `OutputsSpec`, `SingleDerivedPath`, `DerivedPath`
9+
* JSON instances for `BuildTraceKey`, `Derivation`, `FreeformDerivationOutput`
10+
* Roundtrip property tests for all JSON-serializable types
11+
112
# 0.1.0.0 2024-07-31
213

314
* Initial release

hnix-store-json/hnix-store-json.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ library
4242
System.Nix.JSON
4343
build-depends:
4444
base >=4.12 && <5
45+
, hnix-store-core >= 0.8
46+
4547
, aeson >= 2.0 && < 3.0
4648
, attoparsec
4749
, constraints-extras
@@ -50,7 +52,6 @@ library
5052
, data-default-class
5153
, dependent-sum
5254
, deriving-aeson >= 0.2
53-
, hnix-store-core >= 0.8
5455
, monoidal-containers
5556
, text
5657
, these
@@ -81,6 +82,7 @@ test-suite json
8182
, hnix-store-core
8283
, hnix-store-json
8384
, hnix-store-tests
85+
8486
, aeson
8587
, bytestring
8688
, constraints-extras

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

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import System.Nix.Realisation (BuildTraceKey(..), Realisation, RealisationWithId
5353
import System.Nix.Realisation qualified
5454
import System.Nix.Signature (Signature)
5555
import System.Nix.Signature qualified
56-
import System.Nix.StorePath (StorePath, StorePathName, StorePathHashPart, storePathHash, storePathName, mkStorePathName, unStorePathName, parseBasePathFromText)
56+
import System.Nix.StorePath (StorePath, StorePathName, StorePathHashPart, mkStorePathName, unStorePathName, parseBasePathFromText)
5757
import System.Nix.StorePath qualified
5858

5959
instance ToJSON StorePathName where
@@ -80,19 +80,8 @@ instance FromJSON StorePathHashPart where
8080
)
8181

8282
instance ToJSON StorePath where
83-
toJSON sp =
84-
toJSON $ Data.Text.concat
85-
[ System.Nix.StorePath.storePathHashPartToText (storePathHash sp)
86-
, "-"
87-
, System.Nix.StorePath.unStorePathName (storePathName sp)
88-
]
89-
90-
toEncoding sp =
91-
toEncoding $ Data.Text.concat
92-
[ System.Nix.StorePath.storePathHashPartToText (storePathHash sp)
93-
, "-"
94-
, System.Nix.StorePath.unStorePathName (storePathName sp)
95-
]
83+
toJSON = toJSON . System.Nix.StorePath.storePathBaseToText
84+
toEncoding = toEncoding . System.Nix.StorePath.storePathBaseToText
9685

9786
instance FromJSON StorePath where
9887
parseJSON =
@@ -104,12 +93,7 @@ instance FromJSON StorePath where
10493
)
10594

10695
instance ToJSONKey StorePath where
107-
toJSONKey = Data.Aeson.Types.toJSONKeyText $ \sp ->
108-
Data.Text.concat
109-
[ System.Nix.StorePath.storePathHashPartToText (storePathHash sp)
110-
, "-"
111-
, System.Nix.StorePath.unStorePathName (storePathName sp)
112-
]
96+
toJSONKey = Data.Aeson.Types.toJSONKeyText System.Nix.StorePath.storePathBaseToText
11397

11498
instance FromJSONKey StorePath where
11599
fromJSONKey = FromJSONKeyTextParser $
@@ -332,33 +316,19 @@ instance FromJSON SingleDerivedPath where
332316
instance ToJSON DerivedPath where
333317
toJSON (DerivedPath_Opaque path) = toJSON path
334318
toJSON (DerivedPath_Built drvPath outputs) =
335-
case outputs of
336-
OutputsSpec_Names names | Data.Set.size names == 1 ->
337-
object
338-
[ "drvPath" .= toJSON drvPath
339-
, "output" .= Data.Set.elemAt 0 names
340-
]
341-
_ ->
342-
object
343-
[ "drvPath" .= toJSON drvPath
344-
, "outputs" .= outputs
345-
]
319+
object
320+
[ "drvPath" .= toJSON drvPath
321+
, "outputs" .= outputs
322+
]
346323

347324
instance FromJSON DerivedPath where
348325
parseJSON v = parseOpaque v <|> parseBuilt v
349326
where
350327
parseOpaque = fmap DerivedPath_Opaque . parseJSON
351-
parseBuilt = withObject "DerivedPath_Built" $ \obj -> do
352-
drvPath <- obj .: "drvPath"
353-
-- Try single output first, then multiple outputs
354-
mOutput <- obj .:? "output"
355-
mOutputs <- obj .:? "outputs"
356-
case (mOutput, mOutputs) of
357-
(Just output, Nothing) ->
358-
pure $ DerivedPath_Built drvPath (OutputsSpec_Names (Data.Set.singleton output))
359-
(Nothing, Just outputs) ->
360-
pure $ DerivedPath_Built drvPath outputs
361-
_ -> fail "Expected either 'output' or 'outputs' field"
328+
parseBuilt = withObject "DerivedPath_Built" $ \obj ->
329+
DerivedPath_Built
330+
<$> obj .: "drvPath"
331+
<*> obj .: "outputs"
362332

363333
data LowerLeading
364334
instance StringModifier LowerLeading where

hnix-store-tests/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Unreleased
2+
3+
* Additions:
4+
* `Arbitrary` instance for `SingleDerivedPath`
5+
16
# 0.1.0.0 2024-07-31
27

38
* Initial release

0 commit comments

Comments
 (0)