@@ -6,6 +6,7 @@ Description : Representation of Nix store paths.
66{-# LANGUAGE KindSignatures #-}
77{-# LANGUAGE ConstraintKinds #-}
88{-# LANGUAGE RecordWildCards #-}
9+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
910module System.Nix.Internal.StorePath where
1011import System.Nix.Hash (HashAlgorithm (Truncated , SHA256 ), Digest , encodeBase32 )
1112import Text.Regex.Base.RegexLike (makeRegex , matchTest )
@@ -16,6 +17,8 @@ import GHC.TypeLits (Symbol, KnownSymbol, symbolVal)
1617import Data.ByteString (ByteString )
1718import qualified Data.ByteString as BS
1819import qualified Data.ByteString.Char8 as BC
20+ import Data.Hashable (Hashable (.. ))
21+ import Data.HashSet (HashSet )
1922
2023-- | A path in a Nix store.
2124--
@@ -36,6 +39,10 @@ data StorePath (storeDir :: StoreDir) = StorePath
3639 storePathName :: ! StorePathName
3740 }
3841
42+ instance Hashable (StorePath storeDir ) where
43+ hashWithSalt s (StorePath {.. }) =
44+ s `hashWithSalt` storePathHash `hashWithSalt` storePathName
45+
3946-- | The name portion of a Nix path.
4047--
4148-- 'unStorePathName' must only contain a-zA-Z0-9+._?=-, can't start
@@ -44,11 +51,14 @@ data StorePath (storeDir :: StoreDir) = StorePath
4451newtype StorePathName = StorePathName
4552 { -- | Extract the contents of the name.
4653 unStorePathName :: Text
47- }
54+ } deriving ( Hashable )
4855
4956-- | The hash algorithm used for store path hashes.
5057type StorePathHashAlgo = 'Truncated 20 'SHA256
5158
59+ -- | A set of 'StorePath's.
60+ type StorePathSet storeDir = HashSet (StorePath storeDir )
61+
5262-- | A type-level representation of the root directory of a Nix store.
5363--
5464-- The extra complexity of type indices requires justification.
0 commit comments