@@ -9,10 +9,13 @@ module System.Nix.Store.ReadOnly
9
9
) where
10
10
11
11
import Control.Monad.State (StateT , execStateT , modify )
12
- import Crypto.Hash (Context , Digest , SHA256 )
12
+ import Crypto.Hash (Context , Digest , SHA256 , HashAlgorithm )
13
13
import Data.ByteString (ByteString )
14
+ import Data.Constraint.Extras (Has (has ))
15
+ import Data.Dependent.Sum (DSum ((:=>) ))
14
16
import Data.HashSet (HashSet )
15
- import System.Nix.Hash (BaseEncoding (Base16 ), NamedAlgo (algoName ))
17
+ import Data.Some (Some (Some ))
18
+ import System.Nix.Hash (BaseEncoding (Base16 ), HashAlgo (.. ))
16
19
import System.Nix.Store.Types (FileIngestionMethod (.. ), PathFilter , RepairMode )
17
20
import System.Nix.StorePath (StoreDir , StorePath , StorePathName )
18
21
@@ -28,22 +31,20 @@ import qualified System.Nix.Nar
28
31
import qualified System.Nix.StorePath
29
32
30
33
makeStorePath
31
- :: forall hashAlgo
32
- . (NamedAlgo hashAlgo )
33
- => StoreDir
34
+ :: StoreDir
34
35
-> ByteString
35
- -> Digest hashAlgo
36
+ -> DSum HashAlgo Digest
36
37
-> StorePathName
37
38
-> StorePath
38
- makeStorePath storeDir ty h nm =
39
+ makeStorePath storeDir ty (hashAlgo :=> (digest :: Digest a )) nm =
39
40
System.Nix.StorePath. unsafeMakeStorePath storeHash nm
40
41
where
41
- storeHash = System.Nix.StorePath. mkStorePathHashPart @ hashAlgo s
42
+ storeHash = has @ HashAlgorithm hashAlgo $ System.Nix.StorePath. mkStorePathHashPart @ a s
42
43
s =
43
44
Data.ByteString. intercalate " :" $
44
45
ty: fmap Data.Text.Encoding. encodeUtf8
45
- [ algoName @ hashAlgo
46
- , System.Nix.Hash. encodeDigestWith Base16 h
46
+ [ System.Nix.Hash. algoToText hashAlgo
47
+ , System.Nix.Hash. encodeDigestWith Base16 digest
47
48
, Data.Text. pack . Data.ByteString.Char8. unpack $ System.Nix.StorePath. unStoreDir storeDir
48
49
, System.Nix.StorePath. unStorePathName nm
49
50
]
@@ -54,7 +55,7 @@ makeTextPath
54
55
-> Digest SHA256
55
56
-> HashSet StorePath
56
57
-> StorePath
57
- makeTextPath storeDir nm h refs = makeStorePath storeDir ty h nm
58
+ makeTextPath storeDir nm h refs = makeStorePath storeDir ty ( HashAlgo_SHA256 :=> h) nm
58
59
where
59
60
ty =
60
61
Data.ByteString. intercalate
@@ -65,25 +66,23 @@ makeTextPath storeDir nm h refs = makeStorePath storeDir ty h nm
65
66
<$> Data.HashSet. toList refs)
66
67
67
68
makeFixedOutputPath
68
- :: forall hashAlgo
69
- . NamedAlgo hashAlgo
70
- => StoreDir
69
+ :: StoreDir
71
70
-> FileIngestionMethod
72
- -> Digest hashAlgo
71
+ -> DSum HashAlgo Digest
73
72
-> StorePathName
74
73
-> StorePath
75
- makeFixedOutputPath storeDir recursive h =
74
+ makeFixedOutputPath storeDir recursive algoDigest @ (hashAlgo :=> digest) =
76
75
if recursive == FileIngestionMethod_FileRecursive
77
- && (algoName @ hashAlgo ) == " sha256 "
78
- then makeStorePath storeDir " source" h
79
- else makeStorePath storeDir " output:out" h'
76
+ && Some hashAlgo == Some HashAlgo_SHA256
77
+ then makeStorePath storeDir " source" algoDigest
78
+ else makeStorePath storeDir " output:out" ( HashAlgo_SHA256 :=> h')
80
79
where
81
80
h' =
82
81
Crypto.Hash. hash @ ByteString @ SHA256
83
82
$ " fixed:out:"
84
- <> Data.Text.Encoding. encodeUtf8 (algoName @ hashAlgo )
83
+ <> Data.Text.Encoding. encodeUtf8 (System.Nix.Hash. algoToText hashAlgo)
85
84
<> (if recursive == FileIngestionMethod_FileRecursive then " :r:" else " :" )
86
- <> Data.Text.Encoding. encodeUtf8 (System.Nix.Hash. encodeDigestWith Base16 h )
85
+ <> Data.Text.Encoding. encodeUtf8 (System.Nix.Hash. encodeDigestWith Base16 digest )
87
86
<> " :"
88
87
89
88
computeStorePathForText
@@ -108,7 +107,7 @@ computeStorePathForPath storeDir name pth recursive _pathFilter _repair = do
108
107
if recursive == FileIngestionMethod_FileRecursive
109
108
then recursiveContentHash
110
109
else flatContentHash
111
- pure $ makeFixedOutputPath storeDir recursive selectedHash name
110
+ pure $ makeFixedOutputPath storeDir recursive ( HashAlgo_SHA256 :=> selectedHash) name
112
111
where
113
112
recursiveContentHash :: IO (Digest SHA256 )
114
113
recursiveContentHash =
0 commit comments