Skip to content

Commit 3b948d1

Browse files
Remote: port to Core (0.5) migration to cryptonite (#161)
Core migrated from `cryptohash` to `cryptonite`, interfaces changed, therefore the update.
1 parent 98da348 commit 3b948d1

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ library
4444
, binary
4545
, bytestring
4646
, containers
47+
, cryptonite
4748
, text
4849
, time
4950
, network
5051
, nix-derivation >= 1.1.1 && <2
5152
, mtl
5253
, unordered-containers
53-
, hnix-store-core >= 0.4 && <0.5
54+
, hnix-store-core >= 0.5 && <0.6
5455
hs-source-dirs: src
5556
default-language: Haskell2010
5657
ghc-options: -Wall
@@ -77,6 +78,7 @@ test-suite hnix-store-remote-tests
7778
, hnix-store-core >= 0.3
7879
, hnix-store-remote
7980
, containers
81+
, cryptonite
8082
, directory
8183
, process
8284
, filepath

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ import Nix.Derivation ( Derivation )
4747
import System.Nix.Build ( BuildMode
4848
, BuildResult
4949
)
50-
import System.Nix.Hash ( Digest
51-
, NamedAlgo
52-
, ValidAlgo
50+
import System.Nix.Hash ( NamedAlgo
5351
, SomeNamedDigest(..)
54-
, BaseEncoding(Base32)
52+
, BaseEncoding(NixBase32)
53+
, decodeDigestWith
5554
)
5655
import System.Nix.StorePath ( StorePath
5756
, StorePathName
5857
, StorePathSet
59-
, StorePathHashAlgo
58+
, StorePathHashPart
6059
)
6160
import System.Nix.StorePathMetadata ( StorePathMetadata(..)
6261
, StorePathTrust(..)
6362
)
63+
import System.Nix.Internal.Base ( encodeWith )
6464

6565
import qualified Data.Binary.Put
6666
import qualified Data.ByteString.Lazy
@@ -77,6 +77,8 @@ import System.Nix.Store.Remote.Binary
7777
import System.Nix.Store.Remote.Types
7878
import System.Nix.Store.Remote.Protocol
7979
import System.Nix.Store.Remote.Util
80+
import Crypto.Hash ( SHA256 )
81+
import Data.Coerce ( coerce )
8082

8183
type RepairFlag = Bool
8284
type CheckFlag = Bool
@@ -85,7 +87,7 @@ type SubstituteFlag = Bool
8587
-- | Pack `FilePath` as `Nar` and add it to the store.
8688
addToStore
8789
:: forall a
88-
. (ValidAlgo a, NamedAlgo a)
90+
. NamedAlgo a
8991
=> StorePathName -- ^ Name part of the newly created `StorePath`
9092
-> FilePath -- ^ Local `FilePath` to add
9193
-> Bool -- ^ Add target directory recursively
@@ -167,9 +169,9 @@ buildDerivation p drv buildMode = do
167169
-- but without it protocol just hangs waiting for
168170
-- more data. Needs investigation.
169171
-- Intentionally the only warning that should pop-up.
170-
putInt 0
172+
putInt (0 :: Integer)
171173

172-
res <- getSocketIncremental $ getBuildResult
174+
res <- getSocketIncremental getBuildResult
173175
pure res
174176

175177
ensurePath :: StorePath -> MonadStore ()
@@ -237,7 +239,7 @@ queryPathInfoUncached path = do
237239
let
238240
narHash =
239241
case
240-
System.Nix.Hash.decodeBase @'System.Nix.Hash.SHA256 Base32 narHashText
242+
decodeDigestWith @SHA256 NixBase32 narHashText
241243
of
242244
Left e -> error e
243245
Right x -> SomeDigest x
@@ -285,13 +287,13 @@ queryDerivationOutputNames p = do
285287
runOpArgs QueryDerivationOutputNames $ putPath p
286288
sockGetPaths
287289

288-
queryPathFromHashPart :: Digest StorePathHashAlgo -> MonadStore StorePath
290+
queryPathFromHashPart :: StorePathHashPart -> MonadStore StorePath
289291
queryPathFromHashPart storePathHash = do
290292
runOpArgs QueryPathFromHashPart
291293
$ putByteStringLen
292294
$ Data.ByteString.Lazy.fromStrict
293295
$ Data.Text.Encoding.encodeUtf8
294-
$ System.Nix.Hash.encodeInBase Base32 storePathHash
296+
$ encodeWith NixBase32 $ coerce storePathHash
295297
sockGetPath
296298

297299
queryMissing

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ module System.Nix.Store.Remote.Builders
1010
where
1111

1212
import Data.Text.Lazy ( Text )
13-
import System.Nix.Hash ( Digest
14-
, SomeNamedDigest(SomeDigest)
15-
, BaseEncoding(Base32)
16-
)
13+
import Crypto.Hash ( Digest )
1714
import System.Nix.StorePath ( ContentAddressableAddress(..)
1815
)
1916

2017
import Data.Text.Lazy.Builder ( Builder )
2118
import qualified Data.Text.Lazy.Builder
2219

23-
import qualified System.Nix.Hash
20+
import System.Nix.Hash
2421

2522
-- | Marshall `ContentAddressableAddress` to `Text`
2623
-- in form suitable for remote protocol usage.
@@ -38,4 +35,4 @@ contentAddressableAddressBuilder (Fixed _narHashMode (SomeDigest (digest :: Dige
3835

3936
digestBuilder :: Digest a -> Builder
4037
digestBuilder =
41-
Data.Text.Lazy.Builder.fromText . System.Nix.Hash.encodeInBase Base32
38+
Data.Text.Lazy.Builder.fromText . encodeDigestWith NixBase32

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import System.Nix.Hash
1919
import System.Nix.StorePath ( ContentAddressableAddress(..)
2020
, NarHashMode(..)
2121
)
22+
import Crypto.Hash ( SHA256 )
2223

2324
-- | Parse `ContentAddressableAddress` from `ByteString`
2425
parseContentAddressableAddress
@@ -34,7 +35,7 @@ contentAddressableAddressParser = caText <|> caFixed
3435
caText :: Parser ContentAddressableAddress
3536
caText = do
3637
_ <- "text:sha256:"
37-
digest <- decodeBase @'SHA256 Base32 <$> parseHash
38+
digest <- decodeDigestWith @SHA256 NixBase32 <$> parseHash
3839
either fail pure $ Text <$> digest
3940

4041
-- | Parser for @fixed:<r?>:<ht>:<h>@

hnix-store-remote/tests/Derivation.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import System.Nix.Store.Remote ( MonadStore
1818
, addToStore
1919
, addTextToStore
2020
)
21-
import System.Nix.Hash ( HashAlgorithm(SHA256) )
22-
2321
import qualified Data.Map
2422
import qualified Data.Set
2523
import qualified Data.Text
@@ -29,6 +27,7 @@ import qualified Data.Vector
2927
import qualified System.Nix.Derivation
3028
import qualified System.Nix.StorePath
3129
import qualified System.Directory
30+
import Crypto.Hash ( SHA256 )
3231

3332
drvSample :: StorePath -> StorePath -> StorePath -> Derivation StorePath Text
3433
drvSample builder' buildScript out = Derivation
@@ -48,7 +47,7 @@ withBash action = do
4847
Nothing -> error "No bash executable found"
4948
Just fp -> do
5049
let Right n = System.Nix.StorePath.makeStorePathName "bash"
51-
pth <- addToStore @'SHA256 n fp False (pure True) False
50+
pth <- addToStore @SHA256 n fp False (pure True) False
5251
action pth
5352

5453
withBuildScript :: (StorePath -> MonadStore a) -> MonadStore a

hnix-store-remote/tests/NixDaemon.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ import Test.Hspec.Expectations.Lifted
3232
import System.FilePath
3333

3434
import System.Nix.Build
35-
import System.Nix.Hash
3635
import System.Nix.StorePath
3736
import System.Nix.Store.Remote
3837
import System.Nix.Store.Remote.Protocol
3938

4039
import Derivation
40+
import Crypto.Hash ( SHA256
41+
)
4142

4243
createProcessEnv :: FilePath -> String -> [String] -> IO P.ProcessHandle
4344
createProcessEnv fp proc args = do
@@ -167,13 +168,13 @@ withPath action = do
167168
dummy :: MonadStore StorePath
168169
dummy = do
169170
let Right n = makeStorePathName "dummy"
170-
res <- addToStore @'SHA256 n "dummy" False (pure True) False
171+
res <- addToStore @SHA256 n "dummy" False (pure True) False
171172
pure res
172173

173174
invalidPath :: StorePath
174175
invalidPath =
175176
let Right n = makeStorePathName "invalid"
176-
in StorePath (hash "invalid") n "no_such_root"
177+
in StorePath (mkStorePathHashPart "invalid") n "no_such_root"
177178

178179
withBuilder :: (StorePath -> MonadStore a) -> MonadStore a
179180
withBuilder action = do
@@ -259,7 +260,7 @@ spec_protocol = Hspec.around withNixDaemon $
259260
itRights "adds file to store" $ do
260261
fp <- liftIO $ writeSystemTempFile "addition" "lal"
261262
let Right n = makeStorePathName "tmp-addition"
262-
res <- addToStore @'SHA256 n fp False (pure True) False
263+
res <- addToStore @SHA256 n fp False (pure True) False
263264
liftIO $ print res
264265

265266
context "with dummy" $ do

0 commit comments

Comments
 (0)