@@ -17,10 +17,8 @@ module System.Nix.Path
1717 , Roots
1818 ) where
1919
20- import Crypto.Hash (Digest )
21- import Crypto.Hash.Algorithms (SHA256 )
22- import Crypto.Hash.Truncated (Truncated )
23- import qualified Data.ByteArray as B
20+ import System.Nix.Hash (Digest (.. ),
21+ HashAlgorithm (TruncatedSHA256 ))
2422import qualified Data.ByteString as BS
2523import qualified Data.ByteString.Char8 as BSC
2624import Data.Hashable (Hashable (.. ), hashPtrWithSalt )
@@ -33,6 +31,9 @@ import System.IO.Unsafe (unsafeDupablePerformIO)
3331import Text.Regex.Base.RegexLike (makeRegex , matchTest )
3432import Text.Regex.TDFA.Text (Regex )
3533
34+ -- | The hash algorithm used for store path hashes.
35+ type PathHashAlgo = TruncatedSHA256
36+
3637-- | The name portion of a Nix path.
3738--
3839-- Must be composed of a-z, A-Z, 0-9, +, -, ., _, ?, and =, can't
@@ -52,26 +53,10 @@ pathName n = case matchTest nameRegex n of
5253 True -> Just $ PathName n
5354 False -> Nothing
5455
55- -- | The hash algorithm used for store path hashes.
56- type PathHashAlgo = Truncated SHA256 20
57-
5856-- | A path in a store.
5957data Path = Path ! (Digest PathHashAlgo ) ! PathName
6058 deriving (Eq , Ord , Show )
6159
62- -- | Wrapper to defined a 'Hashable' instance for 'Digest'.
63- newtype HashableDigest a = HashableDigest (Digest a )
64-
65- instance Hashable (HashableDigest a ) where
66- hashWithSalt s (HashableDigest d) = unsafeDupablePerformIO $
67- B. withByteArray d $ \ ptr -> hashPtrWithSalt ptr (B. length d) s
68-
69- instance Hashable Path where
70- hashWithSalt s (Path digest name) =
71- s `hashWithSalt`
72- (HashableDigest digest) `hashWithSalt` name
73-
74-
7560type PathSet = HashSet Path
7661
7762-- | Information about substitutes for a 'Path'.
@@ -130,3 +115,6 @@ filePathPart p = case BSC.any (`elem` ['/', '\NUL']) p of
130115 True -> Nothing
131116
132117type Roots = Map Path Path
118+
119+ instance Hashable Path where
120+ hashWithSalt s (Path hash name) = s `hashWithSalt` hash `hashWithSalt` name
0 commit comments