11{-# LANGUAGE OverloadedStrings #-}
22
33module System.Nix.Store.ReadOnly
4- ( makeStorePath
4+ ( References (.. )
5+ , makeStorePath
56 , makeFixedOutputPath
67 , computeStorePathForPath
78 ) where
@@ -26,6 +27,23 @@ import qualified System.Nix.Hash
2627import qualified System.Nix.Nar
2728import qualified System.Nix.StorePath
2829
30+ data References = References
31+ { references_others :: HashSet StorePath
32+ , references_self :: Bool
33+ }
34+
35+ instance Semigroup References where
36+ a <> b = References
37+ { references_others = references_others a <> references_others b
38+ , references_self = references_self a || references_self b
39+ }
40+
41+ instance Monoid References where
42+ mempty = References
43+ { references_others = mempty
44+ , references_self = False
45+ }
46+
2947makeStorePath
3048 :: forall hashAlgo
3149 . (NamedAlgo hashAlgo )
@@ -47,6 +65,20 @@ makeStorePath storeDir ty h nm =
4765 , System.Nix.StorePath. unStorePathName nm
4866 ]
4967
68+ makeType
69+ :: StoreDir
70+ -> ByteString
71+ -> References
72+ -> ByteString
73+ makeType storeDir ty refs =
74+ Data.ByteString. intercalate " :" $ ty : (others ++ self)
75+ where
76+ others = Data.List. sort
77+ $ fmap (System.Nix.StorePath. storePathToRawFilePath storeDir)
78+ $ Data.HashSet. toList
79+ $ references_others refs
80+ self = [" self" | references_self refs]
81+
5082makeTextPath
5183 :: NamedAlgo _SHA256
5284 => StoreDir
@@ -56,29 +88,28 @@ makeTextPath
5688 -> StorePath
5789makeTextPath storeDir h refs nm = makeStorePath storeDir ty h nm
5890 where
59- ty =
60- Data.ByteString. intercalate " :"
61- $ " text"
62- : Data.List. sort
63- (System.Nix.StorePath. storePathToRawFilePath storeDir
64- <$> Data.HashSet. toList refs)
91+ ty = makeType storeDir " text" $ References
92+ { references_others = refs
93+ , references_self = False
94+ }
6595
6696makeFixedOutputPath
6797 :: forall hashAlgo
6898 . NamedAlgo hashAlgo
6999 => StoreDir
70100 -> ContentAddressMethod
71101 -> Digest hashAlgo
72- -> HashSet StorePath
102+ -> References
73103 -> StorePathName
74104 -> StorePath
75105makeFixedOutputPath storeDir method h refs =
76106 case method of
77- ContentAddressMethod_Text -> makeTextPath storeDir h refs
107+ ContentAddressMethod_Text ->
108+ makeTextPath storeDir h $ references_others refs
78109 _ ->
79110 if method == ContentAddressMethod_NixArchive
80111 && (algoName @ hashAlgo ) == " sha256"
81- then makeStorePath storeDir " source" h
112+ then makeStorePath storeDir (makeType storeDir " source" refs) h
82113 else makeStorePath storeDir " output:out" h'
83114 where
84115 h' =
0 commit comments