Skip to content

Commit 9df926a

Browse files
committed
fixup! simple store path root, remote store rework
1 parent 67b960a commit 9df926a

File tree

4 files changed

+58
-33
lines changed

4 files changed

+58
-33
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ library
2929
, System.Nix.Signature
3030
, System.Nix.StorePath
3131
, System.Nix.StorePathMetadata
32-
, System.Nix.ValidPath
3332
build-depends: base >=4.10 && <5
3433
, attoparsec
3534
, base16-bytestring

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ data StorePathTrust
4747
| -- | It was built elsewhere (and substituted or similar) and so
4848
-- is less trusted
4949
BuiltElsewhere
50+
deriving (Show, Eq)

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

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import qualified Data.Binary.Put as B
4343
import Data.ByteString (ByteString)
4444
import qualified Data.ByteString.Lazy as BSL
4545
import qualified Data.Map.Strict as M
46+
import qualified Data.Set
4647
import Data.Proxy (Proxy)
4748
import Data.Text (Text)
4849

@@ -52,14 +53,14 @@ import System.Nix.Hash (Digest, ValidAlgo)
5253
import System.Nix.StorePath
5354
import System.Nix.Hash
5455
import System.Nix.Nar (localPackNar, putNar, narEffectsIO, Nar)
55-
import System.Nix.ValidPath
56+
import System.Nix.StorePathMetadata
5657

5758
import System.Nix.Store.Remote.Binary
5859
import System.Nix.Store.Remote.Types
5960
import System.Nix.Store.Remote.Protocol
6061
import System.Nix.Store.Remote.Util
6162

62-
import Data.Text.Encoding (encodeUtf8)
63+
import qualified Data.Text.Encoding -- (encodeUtf8)
6364

6465
type RepairFlag = Bool
6566
type CheckFlag = Bool
@@ -71,11 +72,10 @@ addToStore
7172
=> StorePathName
7273
-> FilePath
7374
-> Bool
74-
-> Proxy a
7575
-> (StorePath -> Bool)
7676
-> RepairFlag
7777
-> MonadStore StorePath
78-
addToStore name pth recursive _algoProxy pfilter repair = do
78+
addToStore name pth recursive _pathFilter _repair = do
7979

8080
-- TODO: Is this lazy enough? We need `B.putLazyByteString bs` to stream `bs`
8181
bs :: BSL.ByteString <- liftIO $ B.runPut . putNar <$> localPackNar narEffectsIO pth
@@ -92,23 +92,32 @@ addToStore name pth recursive _algoProxy pfilter repair = do
9292

9393
sockGetPath
9494

95-
addToStoreNar :: ValidPath -> Nar -> RepairFlag -> CheckSigsFlag -> MonadStore ()
96-
addToStoreNar ValidPath{..} nar repair checkSigs = do
95+
addToStoreNar :: StorePathMetadata -> Nar -> RepairFlag -> CheckSigsFlag -> MonadStore ()
96+
addToStoreNar StorePathMetadata{..} nar repair checkSigs = do
9797
-- after the command, protocol asks for data via Read message
9898
-- so we provide it here
9999
let n = B.runPut $ putNar nar
100100
setData n
101101

102102
void $ runOpArgs AddToStoreNar $ do
103103
putPath path
104-
maybe (putText "") (putPath) deriver
105-
putText narHash
104+
maybe (putText "") (putPath) deriverPath
105+
let putNarHash :: SomeNamedDigest -> B.PutM ()
106+
putNarHash (SomeDigest n) = putByteStringLen
107+
$ BSL.fromStrict
108+
$ Data.Text.Encoding.encodeUtf8
109+
$ encodeBase32 n
110+
111+
putNarHash narHash
106112
putPaths references
107113
putTime registrationTime
108-
putInt narSize
109-
putBool ultimate
110-
putTexts sigs
111-
putText ca
114+
-- XXX
115+
maybe (error "NO NAR BYTES") putInt narBytes
116+
putBool (trust == BuiltLocally)
117+
-- XXX
118+
putTexts [""]
119+
-- XXX
120+
putText ""
112121

113122
putBool repair
114123
putBool (not checkSigs)
@@ -190,23 +199,38 @@ querySubstitutablePaths ps = do
190199
putPaths ps
191200
sockGetPaths
192201

193-
queryPathInfoUncached :: StorePath -> MonadStore ValidPath
202+
queryPathInfoUncached :: forall a.NamedAlgo a => StorePath -> MonadStore StorePathMetadata
194203
queryPathInfoUncached path = do
195204
runOpArgs QueryPathInfo $ do
196205
putPath path
197206

198207
valid <- sockGetBool
199208
unless valid $ error "Path is not valid"
200209

201-
deriver <- sockGetPathMay
202-
narHash <- bsToText <$> sockGetStr
210+
deriverPath <- sockGetPathMay
211+
212+
narHashText <- Data.Text.Encoding.decodeUtf8 <$> sockGetStr
213+
let narHash = case decodeBase32 narHashText of
214+
Left e -> error e
215+
Right x -> SomeDigest @a x
216+
203217
references <- sockGetPaths
204218
registrationTime <- sockGet getTime
205-
narSize <- sockGetInt
219+
narBytes <- Just <$> sockGetInt
206220
ultimate <- sockGetBool
207-
sigs <- map bsToText <$> sockGetStrings
221+
222+
-- XXX
223+
sigStrings <- map bsToText <$> sockGetStrings
224+
225+
let sigs = Data.Set.empty
226+
contentAddressableAddress = Nothing
227+
208228
ca <- bsToText <$> sockGetStr
209-
return $ ValidPath {..}
229+
230+
let trust = if ultimate then BuiltLocally
231+
else BuiltElsewhere
232+
233+
return $ StorePathMetadata {..}
210234

211235
queryReferrers :: StorePath -> MonadStore StorePathSet
212236
queryReferrers p = do
@@ -235,7 +259,7 @@ queryDerivationOutputNames p = do
235259
queryPathFromHashPart :: Digest StorePathHashAlgo -> MonadStore StorePath
236260
queryPathFromHashPart storePathHash = do
237261
runOpArgs QueryPathFromHashPart $
238-
putByteStringLen $ BSL.fromStrict $ encodeUtf8 $ encodeBase32 storePathHash
262+
putByteStringLen $ BSL.fromStrict $ Data.Text.Encoding.encodeUtf8 $ encodeBase32 storePathHash
239263
sockGetPath
240264

241265
queryMissing :: StorePathSet -> MonadStore (StorePathSet, StorePathSet, StorePathSet, Integer, Integer)
@@ -253,7 +277,7 @@ queryMissing ps = do
253277
optimiseStore :: MonadStore ()
254278
optimiseStore = void $ simpleOp OptimiseStore
255279

256-
syncWithGC ::MonadStore ()
280+
syncWithGC :: MonadStore ()
257281
syncWithGC = void $ simpleOp SyncWithGC
258282

259283
-- returns True on errors

hnix-store-remote/tests/NixDaemon.hs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import System.Nix.Hash
4646
import System.Nix.StorePath
4747
import System.Nix.ReadonlyStore
4848
import System.Nix.Nar
49-
import qualified System.Nix.ValidPath as VP
49+
import qualified System.Nix.StorePathMetadata as VP
5050
import System.Nix.Store.Remote
5151
import System.Nix.Store.Remote.Logger
5252
import System.Nix.Store.Remote.Types
@@ -148,7 +148,7 @@ withPath action = do
148148
-- | dummy path, adds <tmp>/dummpy with "Hello World" contents
149149
dummy = do
150150
let Right n = makeStorePathName "dummy"
151-
res <- addToStore n "dummy" False (Proxy :: Proxy 'SHA256) (pure True) False
151+
res <- addToStore @SHA256 n "dummy" False (pure True) False
152152
return res
153153

154154
invalidPath :: StorePath
@@ -162,7 +162,8 @@ withNar act = do
162162

163163
let narContents = runPut $ putNar nar
164164
narHash = hashLazy @SHA256 narContents
165-
narSize = BSL.length narContents
165+
-- narSize vs narBytes
166+
narBytes = BSL.length narContents
166167

167168
deriver <- addTextToStore "some-deriver" "" (HS.fromList []) False
168169

@@ -172,16 +173,16 @@ withNar act = do
172173

173174
addTempRoot path
174175

175-
let vp = VP.ValidPath
176+
let vp = VP.StorePathMetadata
176177
{ VP.path = path
177-
, VP.deriver = Just deriver
178-
, VP.narHash = (encodeBase16 narHash)
178+
, VP.deriverPath = Just deriver
179+
, VP.narHash = SomeDigest narHash
179180
, VP.references = HS.empty
180181
, VP.registrationTime = now
181-
, VP.narSize = fromIntegral narSize
182-
, VP.ultimate = True
183-
, VP.sigs = []
184-
, VP.ca = ""
182+
, VP.narBytes = Just $ fromIntegral narBytes
183+
, VP.trust = VP.BuiltLocally
184+
, VP.sigs = S.empty -- []
185+
, VP.contentAddressableAddress = Nothing
185186
}
186187

187188
addToStoreNar vp nar False False
@@ -227,7 +228,7 @@ spec_protocol = Hspec.around withNixDaemon $ do
227228
itRights "non-empty query" $ withPath $ \path -> queryAllValidPaths `shouldReturn` (HS.fromList [path])
228229

229230
context "queryPathInfoUncached" $ do
230-
itRights "queries path info" $ withPath $ queryPathInfoUncached
231+
itRights "queries path info" $ withPath $ queryPathInfoUncached @SHA256
231232

232233
context "ensurePath" $ do
233234
itRights "simple ensure" $ withPath $ ensurePath
@@ -277,7 +278,7 @@ spec_protocol = Hspec.around withNixDaemon $ do
277278
itRights "adds file to store" $ do
278279
fp <- liftIO $ writeSystemTempFile "addition" "lal"
279280
let Right n = makeStorePathName "tmp-addition"
280-
res <- addToStore n fp False (Proxy :: Proxy 'SHA256) (pure True) False
281+
res <- addToStore @SHA256 n fp False (pure True) False
281282
liftIO $ print res
282283

283284
context "with dummy" $ do

0 commit comments

Comments
 (0)