Skip to content

Commit 99e7950

Browse files
committed
Add type for sets of StorePaths.
1 parent 6011a2e commit 99e7950

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Description : Representation of Nix store paths.
66
{-# LANGUAGE KindSignatures #-}
77
{-# LANGUAGE ConstraintKinds #-}
88
{-# LANGUAGE RecordWildCards #-}
9+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
910
module System.Nix.Internal.StorePath where
1011
import System.Nix.Hash (HashAlgorithm(Truncated, SHA256), Digest, encodeBase32)
1112
import Text.Regex.Base.RegexLike (makeRegex, matchTest)
@@ -16,6 +17,8 @@ import GHC.TypeLits (Symbol, KnownSymbol, symbolVal)
1617
import Data.ByteString (ByteString)
1718
import qualified Data.ByteString as BS
1819
import 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
4451
newtype 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.
5057
type 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.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module System.Nix.StorePath
55
( -- * Basic store path types
66
StorePath(..)
77
, StorePathName
8+
, StorePathSet
89
, StorePathHashAlgo
910
, StoreDir
1011
, -- * Manipulating 'StorePathName'

0 commit comments

Comments
 (0)