diff --git a/hnix-store-core/src/System/Nix/ReadonlyStore.hs b/hnix-store-core/src/System/Nix/ReadonlyStore.hs index ad966ae0..5e3c5a41 100644 --- a/hnix-store-core/src/System/Nix/ReadonlyStore.hs +++ b/hnix-store-core/src/System/Nix/ReadonlyStore.hs @@ -12,7 +12,9 @@ import qualified Data.Text as T import qualified Data.HashSet as HS import Data.Text.Encoding import System.Nix.Hash +import System.Nix.Nar import System.Nix.StorePath +import Control.Monad.State.Strict makeStorePath @@ -45,9 +47,7 @@ makeTextPath fp nm h refs = makeStorePath fp ty h nm makeFixedOutputPath :: forall hashAlgo - . ( ValidAlgo hashAlgo - , NamedAlgo hashAlgo - ) + . (NamedAlgo hashAlgo) => FilePath -> Bool -> Digest hashAlgo @@ -69,3 +69,22 @@ makeFixedOutputPath fp recursive h = computeStorePathForText :: FilePath -> StorePathName -> ByteString -> (StorePathSet -> StorePath) computeStorePathForText fp nm = makeTextPath fp nm . hash + +computeStorePathForPath + :: StorePathName -- ^ Name part of the newly created `StorePath` + -> FilePath -- ^ Local `FilePath` to add + -> Bool -- ^ Add target directory recursively + -> (FilePath -> Bool) -- ^ Path filter function + -> Bool -- ^ Only used by local store backend + -> IO StorePath +computeStorePathForPath name pth recursive _pathFilter _repair = do + selectedHash <- if recursive then recursiveContentHash else flatContentHash + pure $ makeFixedOutputPath "/nix/store" recursive selectedHash name + where + recursiveContentHash :: IO (Digest 'SHA256) + recursiveContentHash = finalize <$> execStateT streamNarUpdate (initialize @'SHA256) + streamNarUpdate :: StateT (AlgoCtx 'SHA256) IO () + streamNarUpdate = streamNarIO (modify . flip (update @'SHA256)) narEffectsIO pth + + flatContentHash :: IO (Digest 'SHA256) + flatContentHash = hashLazy <$> narReadFile narEffectsIO pth