Skip to content

Commit 3b3752d

Browse files
committed
core: don't (re)export StorePathHashPart constructor
1 parent c095d12 commit 3b3752d

File tree

7 files changed

+29
-16
lines changed

7 files changed

+29
-16
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ module System.Nix.Internal.StorePath
1414
, StorePath(..)
1515
, StorePathName(..)
1616
, StorePathSet
17-
, mkStorePathHashPart
1817
, StorePathHashPart(..)
18+
, mkStorePathHashPart
1919
, ContentAddressableAddress(..)
2020
, NarHashMode(..)
2121
, -- * Manipulating 'StorePathName'
@@ -47,6 +47,7 @@ import qualified Data.Attoparsec.Text.Lazy as Parser.Text.Lazy
4747
import qualified System.FilePath as FilePath
4848
import Crypto.Hash ( SHA256
4949
, Digest
50+
, HashAlgorithm
5051
)
5152

5253
-- | A path in a Nix store.
@@ -83,11 +84,18 @@ newtype StorePathName = StorePathName
8384
} deriving (Eq, Hashable, Ord, Show)
8485

8586
-- | The hash algorithm used for store path hashes.
86-
newtype StorePathHashPart = StorePathHashPart ByteString
87+
newtype StorePathHashPart = StorePathHashPart
88+
{ -- | Extract the contents of the hash.
89+
unStorePathHashPart :: ByteString
90+
}
8791
deriving (Eq, Hashable, Ord, Show)
8892

89-
mkStorePathHashPart :: ByteString -> StorePathHashPart
90-
mkStorePathHashPart = coerce . mkStorePathHash @SHA256
93+
mkStorePathHashPart
94+
:: forall hashAlgo
95+
. HashAlgorithm hashAlgo
96+
=> ByteString
97+
-> StorePathHashPart
98+
mkStorePathHashPart = coerce . mkStorePathHash @hashAlgo
9199

92100
-- | A set of 'StorePath's.
93101
type StorePathSet = HashSet StorePath

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ import Crypto.Hash ( Context
2222

2323

2424
makeStorePath
25-
:: forall h
26-
. (NamedAlgo h)
25+
:: forall hashAlgo
26+
. (NamedAlgo hashAlgo)
2727
=> StoreDir
2828
-> ByteString
29-
-> Digest h
29+
-> Digest hashAlgo
3030
-> StorePathName
3131
-> StorePath
32-
makeStorePath storeDir ty h nm = StorePath (coerce storeHash) nm
32+
makeStorePath storeDir ty h nm = StorePath storeHash nm
3333
where
34-
storeHash = mkStorePathHash @h s
34+
storeHash = mkStorePathHashPart @hashAlgo s
3535
s =
3636
BS.intercalate ":" $
3737
ty:fmap encodeUtf8
38-
[ algoName @h
38+
[ algoName @hashAlgo
3939
, encodeDigestWith Base16 h
4040
, toText . Bytes.Char8.unpack $ unStoreDir storeDir
4141
, unStorePathName nm

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ module System.Nix.StorePath
77
, StorePath(..)
88
, StorePathName
99
, StorePathSet
10+
, StorePathHashPart
1011
, mkStorePathHashPart
11-
, StorePathHashPart(..)
12+
, unStorePathHashPart
1213
, ContentAddressableAddress(..)
1314
, NarHashMode(..)
1415
, -- * Manipulating 'StorePathName'

hnix-store-core/tests/Arbitrary.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ instance Arbitrary StorePathName where
3030
sn = elements $ alphanum <> "+-._?="
3131

3232
instance Arbitrary StorePathHashPart where
33-
arbitrary = mkStorePathHashPart . BSC.pack <$> arbitrary
33+
arbitrary = mkStorePathHashPart @SHA256 . BSC.pack <$> arbitrary
3434

3535
instance Arbitrary (Digest SHA256) where
3636
arbitrary = hash . BSC.pack <$> arbitrary

hnix-store-core/tests/Hash.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec_hash = do
3737
-- The example in question:
3838
-- https://nixos.org/nixos/nix-pills/nix-store-paths.html
3939
it "produces same base32 as nix pill flat file example" $ do
40-
shouldBe (encodeWith NixBase32 $ coerce $ mkStorePathHashPart "source:sha256:2bfef67de873c54551d884fdab3055d84d573e654efa79db3c0d7b98883f9ee3:/nix/store:myfile")
40+
shouldBe (encodeWith NixBase32 $ unStorePathHashPart $ mkStorePathHashPart @SHA256 "source:sha256:2bfef67de873c54551d884fdab3055d84d573e654efa79db3c0d7b98883f9ee3:/nix/store:myfile")
4141
"xv2iccirbrvklck36f1g7vldn5v58vck"
4242
where
4343
cmp :: String -> BaseEncoding -> (ByteString -> Digest a) -> ByteString -> Text -> SpecWith ()
@@ -52,7 +52,8 @@ prop_nixBase32Roundtrip = forAllShrink nonEmptyString genericShrink $
5252

5353
-- | API variants
5454
prop_nixBase16Roundtrip :: StorePathHashPart -> Property
55-
prop_nixBase16Roundtrip x = pure (coerce x) === decodeWith Base16 (encodeWith Base16 $ coerce x)
55+
prop_nixBase16Roundtrip x =
56+
pure (unStorePathHashPart x) === decodeWith Base16 (encodeWith Base16 $ unStorePathHashPart x)
5657

5758
-- | Hash encoding conversion ground-truth.
5859
-- Similiar to nix/tests/hash.sh

hnix-store-remote/src/System/Nix/Store/Remote.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ queryPathFromHashPart :: StorePathHashPart -> MonadStore StorePath
290290
queryPathFromHashPart storePathHash = do
291291
runOpArgs QueryPathFromHashPart
292292
$ putByteStringLen
293-
$ encodeUtf8 (encodeWith NixBase32 $ coerce storePathHash)
293+
$ encodeUtf8
294+
$ encodeWith NixBase32
295+
$ System.Nix.StorePath.unStorePathHashPart
296+
storePathHash
294297
sockGetPath
295298

296299
queryMissing

hnix-store-remote/tests/NixDaemon.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ dummy = do
166166
invalidPath :: StorePath
167167
invalidPath =
168168
let name = Data.Either.fromRight (error "impossible") $ makeStorePathName "invalid"
169-
in StorePath (mkStorePathHashPart "invalid") name
169+
in StorePath (mkStorePathHashPart @SHA256 "invalid") name
170170

171171
withBuilder :: (StorePath -> MonadStore a) -> MonadStore a
172172
withBuilder action = do

0 commit comments

Comments
 (0)