Skip to content

Commit 3b06982

Browse files
authored
Merge pull request #231 from sorki/srk/cereal
remote: start transitioning from binary to cereal
2 parents 4734067 + cefbca3 commit 3b06982

31 files changed

+920
-274
lines changed

cabal.project

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
packages: ./hnix-store-core/*.cabal ./hnix-store-remote/*.cabal
1+
packages:
2+
./hnix-store-core/hnix-store-core.cabal
3+
./hnix-store-remote/hnix-store-remote.cabal
4+
5+
package hnix-store-remote
6+
flags: +build-readme +io-testsuite
7+

cabal.project.local.ci

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
tests: True
22

3-
flags: +io-testsuite
4-
53
package hnix-store-core
64
ghc-options: -Wunused-packages -Wall
75

hnix-store-core/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
# Next
22

33
* Changes:
4+
* `StorePathMetadata` converted to `Metadata a` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
45
* Constructors of `StorePathName` and `StorePathHashPart` are no longer
56
exported. Use respective `mkStorePath..` functions. [#230](https://github.com/haskell-nix/hnix-store/pull/230)
67
* `StorePathSet` type alias is no more, use `HashSet StorePath` [#230](https://github.com/haskell-nix/hnix-store/pull/230)
8+
* `makeStorePath` and `parsePath` now returns `Either InvalidPathError StorePath` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
9+
* `BuildResult`s `timesBuild` field changes type from `Integer` to `Int` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
710

811
* Additions:
12+
* `Default StoreDir` instance [#231](https://github.com/haskell-nix/hnix-store/pull/231)
13+
* `System.Nix.StorePath.storePathHashPartToText` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
14+
* Added `Generic` and `Show` instances for
15+
`Signature` and `NarSignature` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
16+
* Added `Eq` and `Ord` instances for `SomeNamedDigest` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
17+
* `BuildStatus` grows `NoSubstituters` and `ResolvesToAlreadyValid` constructors [#231](https://github.com/haskell-nix/hnix-store/pull/231)
18+
* `InvalidPathError` replacing previous stringy error [#231](https://github.com/haskell-nix/hnix-store/pull/231)
919
* Added `Arbitrary` instances for (exported by default) [#230](https://github.com/haskell-nix/hnix-store/pull/230)
1020
* `StorePath`
1121
* `StorePathName`
1222
* `StorePathHashPart`
1323
* `StoreDir`
24+
* Added `Arbitrary` instances for [#231](https://github.com/haskell-nix/hnix-store/pull/231)
25+
* `BuildMode`
26+
* `BuildStatus`
27+
* `BuildResult`
28+
* `Derivation StorePath Text`
29+
* `DerivationOutput StorePath Text`
1430

1531
# [0.7.0.0](https://github.com/haskell-nix/hnix-store/compare/core-0.6.1.0...core-0.7.0.0) 2023-11-15
1632

hnix-store-core/cabal.project

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ library
6060
, case-insensitive
6161
, cereal
6262
, containers
63+
, data-default-class
64+
, generic-arbitrary < 1.1
6365
-- Required for cryptonite low-level type convertion
6466
, memory
6567
, cryptonite
@@ -71,6 +73,7 @@ library
7173
, mtl
7274
, nix-derivation >= 1.1.1 && <2
7375
, QuickCheck
76+
, quickcheck-instances
7477
, saltine
7578
, time
7679
, text
@@ -89,9 +92,13 @@ library
8992
, DeriveFoldable
9093
, DeriveTraversable
9194
, DeriveLift
95+
, DerivingStrategies
96+
, DerivingVia
9297
, FlexibleContexts
9398
, FlexibleInstances
9499
, StandaloneDeriving
100+
, ScopedTypeVariables
101+
, RecordWildCards
95102
, TypeApplications
96103
, TypeSynonymInstances
97104
, InstanceSigs
@@ -116,6 +123,7 @@ test-suite format-tests
116123
main-is: Driver.hs
117124
other-modules:
118125
Derivation
126+
ContentAddressableAddress
119127
NarFormat
120128
Hash
121129
StorePath
@@ -134,9 +142,11 @@ test-suite format-tests
134142
, bytestring
135143
, containers
136144
, cryptonite
145+
, data-default-class
137146
, directory
138147
, filepath
139148
, process
149+
, nix-derivation >= 1.1.1 && <2
140150
, tasty
141151
, tasty-golden
142152
, hspec

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{-# language RecordWildCards #-}
1+
-- due to recent generic-arbitrary
2+
{-# OPTIONS_GHC -fconstraint-solver-iterations=0 #-}
23
{-|
34
Description : Build related types
45
Maintainer : srk <[email protected]>
@@ -8,15 +9,18 @@ module System.Nix.Build
89
, BuildStatus(..)
910
, BuildResult(..)
1011
, buildSuccess
11-
)
12-
where
12+
) where
1313

14-
import Data.Time ( UTCTime )
14+
import Data.Time (UTCTime)
15+
import Test.QuickCheck (Arbitrary(..))
16+
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
17+
import Test.QuickCheck.Instances ()
1518

1619
-- keep the order of these Enums to match enums from reference implementations
1720
-- src/libstore/store-api.hh
1821
data BuildMode = Normal | Repair | Check
19-
deriving (Eq, Ord, Enum, Show)
22+
deriving (Eq, Generic, Ord, Enum, Show)
23+
deriving Arbitrary via GenericArbitrary BuildMode
2024

2125
data BuildStatus =
2226
Built
@@ -32,8 +36,10 @@ data BuildStatus =
3236
| DependencyFailed
3337
| LogLimitExceeded
3438
| NotDeterministic
35-
deriving (Eq, Ord, Enum, Show)
36-
39+
| ResolvesToAlreadyValid
40+
| NoSubstituters
41+
deriving (Eq, Generic, Ord, Enum, Show)
42+
deriving Arbitrary via GenericArbitrary BuildStatus
3743

3844
-- | Result of the build
3945
data BuildResult = BuildResult
@@ -42,15 +48,16 @@ data BuildResult = BuildResult
4248
, -- | possible build error message
4349
errorMessage :: !(Maybe Text)
4450
, -- | How many times this build was performed
45-
timesBuilt :: !Integer
51+
timesBuilt :: !Int
4652
, -- | If timesBuilt > 1, whether some builds did not produce the same result
4753
isNonDeterministic :: !Bool
4854
, -- Start time of this build
4955
startTime :: !UTCTime
5056
, -- Stop time of this build
5157
stopTime :: !UTCTime
5258
}
53-
deriving (Eq, Ord, Show)
59+
deriving (Eq, Generic, Ord, Show)
60+
deriving Arbitrary via GenericArbitrary BuildResult
5461

5562
buildSuccess :: BuildResult -> Bool
5663
buildSuccess BuildResult {..} =
Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
1+
-- due to recent generic-arbitrary
2+
{-# OPTIONS_GHC -Wno-orphans -fconstraint-solver-iterations=0 #-}
13

24
module System.Nix.Derivation
35
( parseDerivation
46
, buildDerivation
5-
)
6-
where
7+
) where
78

8-
import qualified Data.Text.Lazy.Builder as Text.Lazy
9-
( Builder )
10-
import qualified Data.Attoparsec.Text.Lazy as Text.Lazy
11-
( Parser )
12-
import Nix.Derivation ( Derivation )
13-
import qualified Nix.Derivation as Derivation
14-
import System.Nix.StorePath ( StoreDir
15-
, StorePath
16-
, storePathToFilePath
17-
)
18-
import qualified System.Nix.StorePath as StorePath
9+
import Data.Attoparsec.Text.Lazy (Parser)
10+
import Data.Text.Lazy.Builder (Builder)
11+
import Test.QuickCheck (Arbitrary(..))
12+
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
13+
import Test.QuickCheck.Instances ()
1914

15+
import Nix.Derivation (Derivation, DerivationOutput)
16+
import System.Nix.StorePath (StoreDir, StorePath)
2017

18+
import qualified Data.Attoparsec.Text.Lazy
19+
import qualified Data.Text.Lazy
2120

22-
parseDerivation :: StoreDir -> Text.Lazy.Parser (Derivation StorePath Text)
21+
import qualified Nix.Derivation
22+
import qualified System.Nix.StorePath
23+
24+
deriving via GenericArbitrary (Derivation StorePath Text)
25+
instance Arbitrary (Derivation StorePath Text)
26+
deriving via GenericArbitrary (DerivationOutput StorePath Text)
27+
instance Arbitrary (DerivationOutput StorePath Text)
28+
29+
parseDerivation :: StoreDir -> Parser (Derivation StorePath Text)
2330
parseDerivation expectedRoot =
24-
Derivation.parseDerivationWith
25-
("\"" *> StorePath.pathParser expectedRoot <* "\"")
26-
Derivation.textParser
31+
Nix.Derivation.parseDerivationWith
32+
pathParser
33+
Nix.Derivation.textParser
34+
where
35+
pathParser = do
36+
text <- Nix.Derivation.textParser
37+
case Data.Attoparsec.Text.Lazy.parseOnly
38+
(System.Nix.StorePath.pathParser expectedRoot)
39+
(Data.Text.Lazy.fromStrict text)
40+
of
41+
Right p -> pure p
42+
Left e -> fail e
2743

28-
buildDerivation :: StoreDir -> Derivation StorePath Text -> Text.Lazy.Builder
44+
buildDerivation :: StoreDir -> Derivation StorePath Text -> Builder
2945
buildDerivation storeDir =
30-
Derivation.buildDerivationWith
31-
(show . storePathToFilePath storeDir)
46+
Nix.Derivation.buildDerivationWith
47+
(show . System.Nix.StorePath.storePathToText storeDir)
3248
show

hnix-store-core/src/System/Nix/Internal/Hash.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module System.Nix.Internal.Hash
1919
)
2020
where
2121

22+
import Crypto.Hash (Digest)
2223
import qualified Text.Show
2324
import qualified Crypto.Hash as C
2425
import qualified Data.ByteString as BS
@@ -45,11 +46,23 @@ instance NamedAlgo C.SHA512 where
4546
algoName = "sha512"
4647

4748
-- | A digest whose 'NamedAlgo' is not known at compile time.
48-
data SomeNamedDigest = forall a . NamedAlgo a => SomeDigest (C.Digest a)
49+
data SomeNamedDigest = forall a . NamedAlgo a => SomeDigest (Digest a)
4950

5051
instance Show SomeNamedDigest where
5152
show sd = case sd of
52-
SomeDigest (digest :: C.Digest hashType) -> toString $ "SomeDigest " <> algoName @hashType <> ":" <> encodeDigestWith NixBase32 digest
53+
SomeDigest (digest :: Digest hashType) -> toString $ "SomeDigest " <> algoName @hashType <> ":" <> encodeDigestWith NixBase32 digest
54+
55+
instance Eq SomeNamedDigest where
56+
(==) (SomeDigest (a :: Digest aType))
57+
(SomeDigest (b :: Digest bType))
58+
= algoName @aType == algoName @bType
59+
&& encodeDigestWith NixBase32 a == encodeDigestWith NixBase32 b
60+
61+
instance Ord SomeNamedDigest where
62+
(<=) (SomeDigest (a :: Digest aType))
63+
(SomeDigest (b :: Digest bType))
64+
= algoName @aType <= algoName @bType
65+
&& encodeDigestWith NixBase32 a <= encodeDigestWith NixBase32 b
5366

5467
mkNamedDigest :: Text -> Text -> Either String SomeNamedDigest
5568
mkNamedDigest name sriHash =

hnix-store-core/src/System/Nix/Internal/Nar/Parser.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import qualified System.Nix.Internal.Nar.Options as Nar
4747
-- of the actions the parser can take, and @ParserState@ for the
4848
-- internals of the parser
4949
newtype NarParser m a = NarParser
50-
{ runNarParser ::
50+
{ _runNarParser ::
5151
State.StateT
5252
ParserState
5353
(Except.ExceptT
@@ -554,15 +554,12 @@ testParser' :: (m ~ IO) => FilePath -> IO (Either String ())
554554
testParser' fp =
555555
withFile fp ReadMode $ \h -> runParser Nar.narEffectsIO parseNar h "tmp"
556556

557-
558-
559-
560557
-- | Distance to the next multiple of 8
561558
padLen :: Int -> Int
562559
padLen n = (8 - n) `mod` 8
563560

564-
565-
dbgState :: IO.MonadIO m => NarParser m ()
566-
dbgState = do
561+
-- | Debugging helper
562+
_dbgState :: IO.MonadIO m => NarParser m ()
563+
_dbgState = do
567564
s <- State.get
568565
IO.liftIO $ print (tokenStack s, directoryStack s)

hnix-store-core/src/System/Nix/Internal/Signature.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import qualified Crypto.Saltine.Internal.ByteSizes as NaClSizes
2323

2424
-- | A NaCl signature.
2525
newtype Signature = Signature ByteString
26-
deriving (Eq, Ord)
26+
deriving (Eq, Generic, Ord, Show)
2727

2828
instance IsEncoding Signature where
2929
decode s
@@ -42,4 +42,4 @@ data NarSignature = NarSignature
4242
, -- | The archive's signature.
4343
sig :: Signature
4444
}
45-
deriving (Eq, Ord)
45+
deriving (Eq, Generic, Ord, Show)

0 commit comments

Comments
 (0)