Skip to content

Commit 747225c

Browse files
committed
core: StorePath add HasStoreDir, getStoreDir
1 parent 6160cfd commit 747225c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Description : Representation of Nix store paths.
99
module System.Nix.StorePath
1010
( -- * Basic store path types
1111
StoreDir(..)
12+
, HasStoreDir(..)
13+
, getStoreDir
1214
, StorePath(..)
1315
, StorePathName(..)
1416
, StorePathHashPart(..)
@@ -33,6 +35,7 @@ module System.Nix.StorePath
3335
#if !MIN_VERSION_base(4,18,0)
3436
import Control.Applicative (liftA2)
3537
#endif
38+
import Control.Monad.Reader.Class (MonadReader, asks)
3639
import Crypto.Hash (HashAlgorithm, SHA256)
3740
import Data.Attoparsec.Text.Lazy (Parser, (<?>))
3841
import Data.ByteString (ByteString)
@@ -189,6 +192,13 @@ instance Arbitrary StoreDir where
189192
instance Default StoreDir where
190193
def = StoreDir "/nix/store"
191194

195+
class HasStoreDir r where
196+
hasStoreDir :: r -> StoreDir
197+
198+
-- | Ask for a @StoreDir@
199+
getStoreDir :: (HasStoreDir r, MonadReader r m) => m StoreDir
200+
getStoreDir = asks hasStoreDir
201+
192202
-- | Render a 'StorePath' as a 'RawFilePath'.
193203
storePathToRawFilePath :: StoreDir -> StorePath -> RawFilePath
194204
storePathToRawFilePath storeDir StorePath{..} =

0 commit comments

Comments
 (0)