Skip to content

Commit 68c7e47

Browse files
committed
Rename DeriationOutput (in System.Nix.Realisation) to BuildTraceKey
See the change log for detail why.
1 parent 1466b05 commit 68c7e47

File tree

9 files changed

+86
-83
lines changed

9 files changed

+86
-83
lines changed

hnix-store-core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* `SingleDerivedPath` type with `parseSingleDerivedPath`, `singleDerivedPathToText`
1111

1212
* Changes:
13+
* `DerivationOutput` was renamed to `BuildTraceKey`.
14+
Firstly, this avoided a conflict of this type used by `Realisation` with the `DerivationOutput` used by `Derivation` --- the latter deserves the name more since it is for `Derivation`.
15+
Secondly, I (@Ericson2314) am also working upstream to rename "realisations" to "build trace entries", and the collection of them to a "build trace", and so this brings the naming in line with that.
1316
* `OutputName.unOutputName` now returns `StorePathName` instead of `Text`
1417
* `DerivedPath_Built` constructor now takes `SingleDerivedPath` instead of `StorePath`
1518

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Data.Text (Text)
1515
import GHC.Generics (Generic)
1616

1717
import System.Nix.OutputName (OutputName)
18-
import System.Nix.Realisation (DerivationOutput, Realisation)
18+
import System.Nix.Realisation (BuildTraceKey, Realisation)
1919

2020
-- | Mode of the build operation
2121
-- Keep the order of these Enums to match enums from reference implementations
@@ -59,7 +59,7 @@ data BuildResult = BuildResult
5959
-- ^ Start time of this build (since 1.29)
6060
, buildResultStopTime :: Maybe UTCTime
6161
-- ^ Stop time of this build (since 1.29)
62-
, buildResultBuiltOutputs :: Maybe (Map (DerivationOutput OutputName) Realisation)
62+
, buildResultBuiltOutputs :: Maybe (Map (BuildTraceKey OutputName) Realisation)
6363
-- ^ Mapping of the output names to @Realisation@s (since 1.28)
6464
-- (paths with additional info and their dependencies)
6565
}

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Description : Derivation realisations
33
-}
44

55
module System.Nix.Realisation (
6-
DerivationOutput(..)
7-
, DerivationOutputError(..)
8-
, derivationOutputBuilder
9-
, derivationOutputParser
6+
BuildTraceKey(..)
7+
, BuildTraceKeyError(..)
8+
, buildTraceKeyBuilder
9+
, buildTraceKeyParser
1010
, Realisation(..)
1111
, RealisationWithId(..)
1212
) where
@@ -29,75 +29,75 @@ import Data.Text.Lazy.Builder qualified
2929
import System.Nix.Hash qualified
3030

3131
-- | Output of the derivation
32-
data DerivationOutput a = DerivationOutput
33-
{ derivationOutputHash :: DSum HashAlgo Digest
32+
data BuildTraceKey a = BuildTraceKey
33+
{ buildTraceKeyHash :: DSum HashAlgo Digest
3434
-- ^ Hash modulo of the derivation
35-
, derivationOutputOutput :: a
35+
, buildTraceKeyOutput :: a
3636
-- ^ Output (either a OutputName or StorePatH)
3737
} deriving (Eq, Generic, Ord, Show)
3838

39-
data DerivationOutputError
40-
= DerivationOutputError_Digest String
41-
| DerivationOutputError_Name InvalidNameError
42-
| DerivationOutputError_NoExclamationMark
43-
| DerivationOutputError_NoColon
44-
| DerivationOutputError_TooManyParts [Text]
39+
data BuildTraceKeyError
40+
= BuildTraceKeyError_Digest String
41+
| BuildTraceKeyError_Name InvalidNameError
42+
| BuildTraceKeyError_NoExclamationMark
43+
| BuildTraceKeyError_NoColon
44+
| BuildTraceKeyError_TooManyParts [Text]
4545
deriving (Eq, Ord, Show)
4646

47-
derivationOutputParser
47+
buildTraceKeyParser
4848
:: (Text -> Either InvalidNameError outputName)
4949
-> Text
50-
-> Either DerivationOutputError (DerivationOutput outputName)
51-
derivationOutputParser outputName dOut =
50+
-> Either BuildTraceKeyError (BuildTraceKey outputName)
51+
buildTraceKeyParser outputName dOut =
5252
case Data.Text.splitOn (Data.Text.singleton '!') dOut of
53-
[] -> Left DerivationOutputError_NoColon
53+
[] -> Left BuildTraceKeyError_NoColon
5454
[sriHash, oName] -> do
5555
hash <-
5656
case Data.Text.splitOn (Data.Text.singleton ':') sriHash of
57-
[] -> Left DerivationOutputError_NoColon
57+
[] -> Left BuildTraceKeyError_NoColon
5858
[hashName, digest] ->
5959
Data.Bifunctor.first
60-
DerivationOutputError_Digest
60+
BuildTraceKeyError_Digest
6161
$ System.Nix.Hash.mkNamedDigest hashName digest
62-
x -> Left $ DerivationOutputError_TooManyParts x
62+
x -> Left $ BuildTraceKeyError_TooManyParts x
6363
name <-
6464
Data.Bifunctor.first
65-
DerivationOutputError_Name
65+
BuildTraceKeyError_Name
6666
$ outputName oName
6767

68-
pure $ DerivationOutput hash name
69-
x -> Left $ DerivationOutputError_TooManyParts x
68+
pure $ BuildTraceKey hash name
69+
x -> Left $ BuildTraceKeyError_TooManyParts x
7070

71-
derivationOutputBuilder
71+
buildTraceKeyBuilder
7272
:: (outputName -> Text)
73-
-> DerivationOutput outputName
73+
-> BuildTraceKey outputName
7474
-> Builder
75-
derivationOutputBuilder outputName DerivationOutput{..} =
76-
System.Nix.Hash.algoDigestBuilder derivationOutputHash
75+
buildTraceKeyBuilder outputName BuildTraceKey{..} =
76+
System.Nix.Hash.algoDigestBuilder buildTraceKeyHash
7777
<> Data.Text.Lazy.Builder.singleton '!'
78-
<> Data.Text.Lazy.Builder.fromText (outputName derivationOutputOutput)
78+
<> Data.Text.Lazy.Builder.fromText (outputName buildTraceKeyOutput)
7979

8080
-- | Build realisation context
8181
--
8282
-- realisationId is ommited since it is a key
83-
-- of type @DerivationOutput OutputName@ so
83+
-- of type @BuildTraceKey OutputName@ so
8484
-- we will use @RealisationWithId@ newtype
8585
data Realisation = Realisation
8686
{ realisationOutPath :: StorePath
8787
-- ^ Output path
8888
, realisationSignatures :: Set Signature
8989
-- ^ Signatures
90-
, realisationDependencies :: Map (DerivationOutput OutputName) StorePath
90+
, realisationDependencies :: Map (BuildTraceKey OutputName) StorePath
9191
-- ^ Dependent realisations required for this one to be valid
9292
} deriving (Eq, Generic, Ord, Show)
9393

9494
-- | For wire protocol
9595
--
9696
-- We store this normalized in @Build.buildResultBuiltOutputs@
97-
-- as @Map (DerivationOutput OutputName) Realisation@
97+
-- as @Map (BuildTraceKey OutputName) Realisation@
9898
-- but wire protocol needs it de-normalized so we
9999
-- need a special (From|To)JSON instances for it
100100
newtype RealisationWithId = RealisationWithId
101-
{ unRealisationWithId :: (DerivationOutput OutputName, Realisation)
101+
{ unRealisationWithId :: (BuildTraceKey OutputName, Realisation)
102102
}
103103
deriving (Eq, Generic, Ord, Show)

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import System.Nix.DerivedPath (DerivedPath(..), OutputsSpec(..), SingleDerivedPa
3636
import System.Nix.Hash
3737
import System.Nix.OutputName (OutputName)
3838
import System.Nix.OutputName qualified
39-
import System.Nix.Realisation (DerivationOutput(..), Realisation, RealisationWithId(..))
39+
import System.Nix.Realisation (BuildTraceKey(..), Realisation, RealisationWithId(..))
4040
import System.Nix.Realisation qualified
4141
import System.Nix.Signature (Signature)
4242
import System.Nix.Signature qualified
@@ -97,46 +97,46 @@ deriving newtype instance ToJSON OutputName
9797
deriving newtype instance FromJSONKey OutputName
9898
deriving newtype instance ToJSONKey OutputName
9999

100-
instance ToJSON (DerivationOutput OutputName) where
100+
instance ToJSON (BuildTraceKey OutputName) where
101101
toJSON =
102102
toJSON
103103
. Data.Text.Lazy.toStrict
104104
. Data.Text.Lazy.Builder.toLazyText
105-
. System.Nix.Realisation.derivationOutputBuilder
105+
. System.Nix.Realisation.buildTraceKeyBuilder
106106
(System.Nix.StorePath.unStorePathName . System.Nix.OutputName.unOutputName)
107107

108108
toEncoding =
109109
toEncoding
110110
. Data.Text.Lazy.toStrict
111111
. Data.Text.Lazy.Builder.toLazyText
112-
. System.Nix.Realisation.derivationOutputBuilder
112+
. System.Nix.Realisation.buildTraceKeyBuilder
113113
(System.Nix.StorePath.unStorePathName . System.Nix.OutputName.unOutputName)
114114

115-
instance ToJSONKey (DerivationOutput OutputName) where
115+
instance ToJSONKey (BuildTraceKey OutputName) where
116116
toJSONKey =
117117
Data.Aeson.Types.toJSONKeyText
118118
$ Data.Text.Lazy.toStrict
119119
. Data.Text.Lazy.Builder.toLazyText
120-
. System.Nix.Realisation.derivationOutputBuilder
120+
. System.Nix.Realisation.buildTraceKeyBuilder
121121
(System.Nix.StorePath.unStorePathName . System.Nix.OutputName.unOutputName)
122122

123-
instance FromJSON (DerivationOutput OutputName) where
123+
instance FromJSON (BuildTraceKey OutputName) where
124124
parseJSON =
125-
withText "DerivationOutput OutputName"
125+
withText "BuildTraceKey OutputName"
126126
( either
127127
(fail . show)
128128
pure
129-
. System.Nix.Realisation.derivationOutputParser
129+
. System.Nix.Realisation.buildTraceKeyParser
130130
System.Nix.OutputName.mkOutputName
131131
)
132132

133-
instance FromJSONKey (DerivationOutput OutputName) where
133+
instance FromJSONKey (BuildTraceKey OutputName) where
134134
fromJSONKey =
135135
FromJSONKeyTextParser
136136
( either
137137
(fail . show)
138138
pure
139-
. System.Nix.Realisation.derivationOutputParser
139+
. System.Nix.Realisation.buildTraceKeyParser
140140
System.Nix.OutputName.mkOutputName
141141
)
142142

@@ -265,8 +265,8 @@ deriving
265265
instance FromJSON Realisation
266266

267267
-- For a keyed version of Realisation
268-
-- we use RealisationWithId (DerivationOutput OutputName, Realisation)
269-
-- instead of Realisation.id :: (DerivationOutput OutputName)
268+
-- we use RealisationWithId (BuildTraceKey OutputName, Realisation)
269+
-- instead of Realisation.id :: (BuildTraceKey OutputName)
270270
-- field.
271271
instance ToJSON RealisationWithId where
272272
toJSON (RealisationWithId (drvOut, r)) =

hnix-store-json/tests/JSONSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import System.Nix.ContentAddress (ContentAddress)
1212
import System.Nix.DerivedPath (DerivedPath, OutputsSpec, SingleDerivedPath)
1313
import System.Nix.JSON ({-HashJSON-})
1414
import System.Nix.OutputName (OutputName)
15-
import System.Nix.Realisation (DerivationOutput, Realisation)
15+
import System.Nix.Realisation (BuildTraceKey, Realisation)
1616
import System.Nix.Signature (Signature)
1717
import System.Nix.StorePath (StorePath, StorePathName, StorePathHashPart)
1818

@@ -37,6 +37,6 @@ spec = do
3737
prop "OutputsSpec" $ roundtripsJSON @OutputsSpec
3838
prop "SingleDerivedPath" $ roundtripsJSON @SingleDerivedPath
3939
prop "DerivedPath" $ roundtripsJSON @DerivedPath
40-
prop "DerivationOutput OutputName" $ roundtripsJSON @(DerivationOutput OutputName)
40+
prop "BuildTraceKey OutputName" $ roundtripsJSON @(BuildTraceKey OutputName)
4141
prop "Signature" $ roundtripsJSON @Signature
4242
prop "Realisation" $ roundtripsJSON @Realisation

hnix-store-json/tests/RealisationSpec.hs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ import Test.Hspec.Nix (forceRight)
1414
import System.Nix.Hash qualified
1515
import System.Nix.JSON ()
1616
import System.Nix.OutputName qualified
17-
import System.Nix.Realisation (DerivationOutput(..), Realisation(..), RealisationWithId(..))
17+
import System.Nix.Realisation (BuildTraceKey(..), Realisation(..), RealisationWithId(..))
1818
import System.Nix.Signature qualified
1919
import System.Nix.StorePath qualified
2020

21-
sampleDerivationOutput :: DerivationOutput System.Nix.OutputName.OutputName
22-
sampleDerivationOutput = DerivationOutput
23-
{ derivationOutputHash =
21+
sampleBuildTraceKey :: BuildTraceKey System.Nix.OutputName.OutputName
22+
sampleBuildTraceKey = BuildTraceKey
23+
{ buildTraceKeyHash =
2424
forceRight
2525
$ System.Nix.Hash.mkNamedDigest
2626
"sha256"
2727
"1b4sb93wp679q4zx9k1ignby1yna3z7c4c2ri3wphylbc2dwsys0"
28-
, derivationOutputOutput =
28+
, buildTraceKeyOutput =
2929
forceRight
3030
$ System.Nix.OutputName.mkOutputName "foo"
3131
}
@@ -55,7 +55,7 @@ sampleRealisation1 = Realisation
5555
]
5656
, realisationDependencies =
5757
Data.Map.fromList
58-
[ ( sampleDerivationOutput
58+
[ ( sampleBuildTraceKey
5959
, forceRight
6060
$ System.Nix.StorePath.parseBasePathFromText
6161
"9472ijanf79nlkb5n1yh57s7867p1930-testFixed"
@@ -66,13 +66,13 @@ sampleRealisation1 = Realisation
6666
-- upstream-nix/src/libstore-tests/data/realisation/simple.json
6767
upstreamSimpleRealisation :: RealisationWithId
6868
upstreamSimpleRealisation = RealisationWithId
69-
( DerivationOutput
70-
{ derivationOutputHash =
69+
( BuildTraceKey
70+
{ buildTraceKeyHash =
7171
forceRight
7272
$ System.Nix.Hash.mkNamedDigest
7373
"sha256"
7474
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
75-
, derivationOutputOutput =
75+
, buildTraceKeyOutput =
7676
forceRight
7777
$ System.Nix.OutputName.mkOutputName "foo"
7878
}
@@ -88,13 +88,13 @@ upstreamSimpleRealisation = RealisationWithId
8888
-- upstream-nix/src/libstore-tests/data/realisation/with-dependent-realisations.json
8989
upstreamWithDependentRealisations :: RealisationWithId
9090
upstreamWithDependentRealisations = RealisationWithId
91-
( DerivationOutput
92-
{ derivationOutputHash =
91+
( BuildTraceKey
92+
{ buildTraceKeyHash =
9393
forceRight
9494
$ System.Nix.Hash.mkNamedDigest
9595
"sha256"
9696
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
97-
, derivationOutputOutput =
97+
, buildTraceKeyOutput =
9898
forceRight
9999
$ System.Nix.OutputName.mkOutputName "foo"
100100
}
@@ -105,13 +105,13 @@ upstreamWithDependentRealisations = RealisationWithId
105105
, realisationSignatures = mempty
106106
, realisationDependencies =
107107
Data.Map.fromList
108-
[ ( DerivationOutput
109-
{ derivationOutputHash =
108+
[ ( BuildTraceKey
109+
{ buildTraceKeyHash =
110110
forceRight
111111
$ System.Nix.Hash.mkNamedDigest
112112
"sha256"
113113
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
114-
, derivationOutputOutput =
114+
, buildTraceKeyOutput =
115115
forceRight
116116
$ System.Nix.OutputName.mkOutputName "foo"
117117
}
@@ -125,8 +125,8 @@ upstreamWithDependentRealisations = RealisationWithId
125125
spec :: Spec
126126
spec = do
127127
describe "ground truth" $ do
128-
it "sampleDerivationOutput matches preimage" $
129-
encode sampleDerivationOutput `shouldBe` "\"sha256:1b4sb93wp679q4zx9k1ignby1yna3z7c4c2ri3wphylbc2dwsys0!foo\""
128+
it "sampleBuildTraceKey matches preimage" $
129+
encode sampleBuildTraceKey `shouldBe` "\"sha256:1b4sb93wp679q4zx9k1ignby1yna3z7c4c2ri3wphylbc2dwsys0!foo\""
130130

131131
it "sampleRealisation0 matches preimage (relative paths)" $
132132
encode sampleRealisation0 `shouldBe` "{\"outPath\":\"cdips4lakfk1qbf1x68fq18wnn3r5r14-builder.sh\",\"signatures\":[],\"dependentRealisations\":{}}"

0 commit comments

Comments
 (0)