@@ -9,11 +9,14 @@ module System.Nix.StorePath
99 ( -- * Basic store path types
1010 StoreDir (.. )
1111 , HasStoreDir (.. )
12- , getStoreDir
13- , StorePath (.. )
14- , StorePathName (.. )
15- , StorePathHashPart (.. )
12+ , StorePath
13+ , storePathHash
14+ , storePathName
15+ , StorePathName
16+ , unStorePathName
17+ , StorePathHashPart
1618 , mkStorePathHashPart
19+ , unStorePathHashPart
1720 , -- * Manipulating 'StorePathName'
1821 makeStorePathName
1922 , validStorePathName
@@ -29,9 +32,10 @@ module System.Nix.StorePath
2932 parsePath
3033 , parsePathFromText
3134 , pathParser
35+ -- * Utilities for tests
36+ , unsafeMakeStorePath
3237 ) where
3338
34- import Control.Monad.Reader.Class (MonadReader , asks )
3539import Crypto.Hash (HashAlgorithm )
3640import Data.Attoparsec.Text.Lazy (Parser , (<?>) )
3741import Data.ByteString (ByteString )
@@ -70,12 +74,18 @@ data StorePath = StorePath
7074 -- hello-1.2.3).
7175 storePathName :: ! StorePathName
7276 }
73- deriving (Eq , Generic , Ord , Show )
77+ deriving (Eq , Generic , Ord )
7478
7579instance Hashable StorePath where
7680 hashWithSalt s StorePath {.. } =
7781 s `hashWithSalt` storePathHash `hashWithSalt` storePathName
7882
83+ instance Show StorePath where
84+ show s =
85+ " StorePath"
86+ <> " "
87+ <> storePathToFilePath (StoreDir mempty ) s
88+
7989-- | The name portion of a Nix path.
8090--
8191-- 'unStorePathName' must only contain a-zA-Z0-9+._?=-, can't start
@@ -166,10 +176,6 @@ instance Default StoreDir where
166176class HasStoreDir r where
167177 hasStoreDir :: r -> StoreDir
168178
169- -- | Ask for a @StoreDir@
170- getStoreDir :: (HasStoreDir r , MonadReader r m ) => m StoreDir
171- getStoreDir = asks hasStoreDir
172-
173179-- | Render a 'StorePath' as a 'RawFilePath'.
174180storePathToRawFilePath :: StoreDir -> StorePath -> RawFilePath
175181storePathToRawFilePath storeDir StorePath {.. } =
@@ -291,3 +297,13 @@ pathParser expectedRoot = do
291297 (fail . show )
292298 pure
293299 (StorePath <$> hashPart <*> name)
300+
301+ -- * Utilities for tests
302+
303+ -- | Paths rarely need to be constructed directly.
304+ -- Prefer @parsePath@ or @parsePathFromText@
305+ unsafeMakeStorePath
306+ :: StorePathHashPart
307+ -> StorePathName
308+ -> StorePath
309+ unsafeMakeStorePath = StorePath
0 commit comments