1+ {-# LANGUAGE AllowAmbiguousTypes #-}
2+ {-# LANGUAGE DataKinds #-}
3+ {-# LANGUAGE KindSignatures #-}
14{-# LANGUAGE OverloadedStrings #-}
5+ {-# LANGUAGE RankNTypes #-}
6+ {-# LANGUAGE ScopedTypeVariables #-}
7+ {-# LANGUAGE TypeApplications #-}
28module System.Nix.Store.Remote (
39 runStore
410 , isValidPathUncached
@@ -32,6 +38,7 @@ module System.Nix.Store.Remote (
3238import Data.Maybe
3339import qualified Data.ByteString.Lazy as LBS
3440import qualified Data.Map.Strict as M
41+ import Data.Proxy (Proxy (Proxy ))
3542
3643import Control.Monad
3744
@@ -40,6 +47,7 @@ import qualified System.Nix.Derivation as Drv
4047import qualified System.Nix.GC as GC
4148import System.Nix.Hash (Digest , HashAlgorithm )
4249import System.Nix.Path
50+ import System.Nix.Hash
4351import System.Nix.Util
4452
4553import System.Nix.Store.Remote.Types
@@ -159,9 +167,40 @@ type Source = () -- abstract binary source
159167addToStoreNar :: ValidPathInfo -> Source -> RepairFlag -> CheckSigsFlag -> MonadStore ()
160168addToStoreNar = undefined -- XXX
161169
170+
171+ -- class BaseHashAlgorithm (a :: HashAlgorithm) where
172+ -- baseHashAlgorithm :: Bool
173+
174+ -- instance BaseHashAlgorithm MD5 where
175+ -- baseHashAlgorithm = MD5
176+
177+ -- instance BaseHashAlgorithm SHA1 where
178+ -- baseHashAlgorithm = SHA1
179+
180+ -- instance BaseHashAlgorithm SHA256 where
181+ -- baseHashAlgorithm = SHA256
182+
183+ -- instance forall n a.BaseHashAlgorithm a => BaseHashAlgorithm (Truncated n a) where
184+ -- baseHashAlgorithm = baseHashAlgorithm @a
185+
162186type PathFilter = Path -> Bool
163- addToStore :: LBS. ByteString -> Path -> Bool -> HashAlgorithm -> PathFilter -> RepairFlag -> MonadStore Path
164- addToStore name pth recursive hashAlgo pfilter repair = undefined -- XXX
187+ addToStore
188+ :: forall a . AlgoVal a
189+ => LBS. ByteString
190+ -> Path
191+ -> Bool
192+ -> Proxy a
193+ -> PathFilter
194+ -> RepairFlag
195+ -> MonadStore Path
196+ addToStore name pth recursive algoProxy pfilter repair = do
197+ runOpArgs AddToStore $ do
198+ putByteStringLen name
199+ putByteStringLen $ if algoVal @ a == SHA256 && recursive then 0 else 1
200+ putByteStringLen $ if recursive then 0 else 1
201+ putByteStringLen name
202+ fmap (fromMaybe " TODO: Error" ) sockGetPath
203+
165204
166205addTextToStore :: LBS. ByteString -> LBS. ByteString -> PathSet -> RepairFlag -> MonadStore (Maybe Path )
167206addTextToStore name text references' repair = do
0 commit comments