2
2
{-# LANGUAGE OverloadedStrings #-}
3
3
{-# LANGUAGE TypeApplications #-}
4
4
{-# LANGUAGE ScopedTypeVariables #-}
5
+ {-# LANGUAGE AllowAmbiguousTypes #-}
6
+ {-# LANGUAGE TypeFamilies #-}
5
7
6
8
module System.Nix.ReadonlyStore where
7
9
@@ -13,7 +15,9 @@ import qualified Data.Text as T
13
15
import qualified Data.HashSet as HS
14
16
import Data.Text.Encoding
15
17
import System.Nix.Hash
18
+ import System.Nix.Nar
16
19
import System.Nix.StorePath
20
+ import Control.Monad.State.Strict
17
21
18
22
19
23
makeStorePath
@@ -70,3 +74,22 @@ makeFixedOutputPath fp recursive h =
70
74
computeStorePathForText
71
75
:: FilePath -> StorePathName -> ByteString -> (StorePathSet -> StorePath )
72
76
computeStorePathForText fp nm = makeTextPath fp nm . hash
77
+
78
+ computeStorePathForPath :: forall a . (ValidAlgo a , NamedAlgo a )
79
+ => StorePathName -- ^ Name part of the newly created `StorePath`
80
+ -> FilePath -- ^ Local `FilePath` to add
81
+ -> Bool -- ^ Add target directory recursively
82
+ -> (FilePath -> Bool ) -- ^ Path filter function
83
+ -> Bool -- ^ Only used by local store backend
84
+ -> IO StorePath
85
+ computeStorePathForPath name pth recursive _pathFilter _repair = do
86
+ selectedHash <- if recursive then recursiveContentHash else flatContentHash
87
+ pure $ makeFixedOutputPath " /nix/store" recursive selectedHash name
88
+ where
89
+ recursiveContentHash :: IO (Digest a )
90
+ recursiveContentHash = finalize @ a <$> execStateT streamNarUpdate (initialize @ a )
91
+ streamNarUpdate :: StateT (AlgoCtx a ) IO ()
92
+ streamNarUpdate = streamNarIO (modify . flip (update @ a )) narEffectsIO pth
93
+
94
+ flatContentHash :: IO (Digest a )
95
+ flatContentHash = hashLazy <$> narReadFile narEffectsIO pth
0 commit comments