Skip to content

Commit e6f016d

Browse files
committed
Convert StorePathMetadata into Metadata a
Also derive bunch of common instances. Closes #147
1 parent a75162d commit e6f016d

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

hnix-store-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Next
22

33
* Changes:
4+
* `StorePathMetadata` converted to `Metadata a` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
45
* Constructors of `StorePathName` and `StorePathHashPart` are no longer
56
exported. Use respective `mkStorePath..` functions. [#230](https://github.com/haskell-nix/hnix-store/pull/230)
67
* `StorePathSet` type alias is no more, use `HashSet StorePath` [#230](https://github.com/haskell-nix/hnix-store/pull/230)
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
{-|
22
Description : Metadata about Nix store paths.
33
-}
4-
module System.Nix.StorePathMetadata where
4+
module System.Nix.StorePathMetadata
5+
( Metadata(..)
6+
, StorePathTrust(..)
7+
) where
58

6-
import System.Nix.StorePath ( StorePath
7-
, ContentAddressableAddress
8-
)
9-
import System.Nix.Hash ( SomeNamedDigest )
10-
import Data.Time ( UTCTime )
11-
import System.Nix.Signature ( NarSignature )
9+
import Data.Time (UTCTime)
1210

13-
-- | Metadata about a 'StorePath'
14-
data StorePathMetadata = StorePathMetadata
11+
import System.Nix.Hash (SomeNamedDigest)
12+
import System.Nix.Signature (NarSignature)
13+
import System.Nix.StorePath (ContentAddressableAddress)
14+
15+
-- | Metadata (typically about a 'StorePath')
16+
data Metadata a = Metadata
1517
{ -- | The path this metadata is about
16-
path :: !StorePath
18+
path :: !a
1719
, -- | The path to the derivation file that built this path, if any
1820
-- and known.
19-
deriverPath :: !(Maybe StorePath)
21+
deriverPath :: !(Maybe a)
2022
, -- TODO should this be optional?
2123
-- | The hash of the nar serialization of the path.
2224
narHash :: !SomeNamedDigest
2325
, -- | The paths that this path directly references
24-
references :: !(HashSet StorePath)
26+
references :: !(HashSet a)
2527
, -- | When was this path registered valid in the store?
2628
registrationTime :: !UTCTime
2729
, -- | The size of the nar serialization of the path, in bytes.
@@ -38,7 +40,7 @@ data StorePathMetadata = StorePathMetadata
3840
-- There is no guarantee from this type alone that this address
3941
-- is actually correct for this store path.
4042
contentAddressableAddress :: !(Maybe ContentAddressableAddress)
41-
}
43+
} deriving (Eq, Generic, Ord, Show)
4244

4345
-- | How much do we trust the path, based on its provenance?
4446
data StorePathTrust
@@ -47,4 +49,4 @@ data StorePathTrust
4749
| -- | It was built elsewhere (and substituted or similar) and so
4850
-- is less trusted
4951
BuiltElsewhere
50-
deriving (Show, Eq, Ord)
52+
deriving (Eq, Enum, Generic, Ord, Show)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import System.Nix.StorePath ( StorePath
5858
, StorePathHashPart
5959
, InvalidPathError
6060
)
61-
import System.Nix.StorePathMetadata ( StorePathMetadata(..)
61+
import System.Nix.StorePathMetadata ( Metadata(..)
6262
, StorePathTrust(..)
6363
)
6464
import System.Nix.Internal.Base ( encodeWith )
@@ -225,7 +225,7 @@ querySubstitutablePaths ps = do
225225
runOpArgs QuerySubstitutablePaths $ putPaths storeDir ps
226226
sockGetPaths
227227

228-
queryPathInfoUncached :: StorePath -> MonadStore StorePathMetadata
228+
queryPathInfoUncached :: StorePath -> MonadStore (Metadata StorePath)
229229
queryPathInfoUncached path = do
230230
storeDir <- getStoreDir
231231
runOpArgs QueryPathInfo $ do
@@ -266,7 +266,7 @@ queryPathInfoUncached path = do
266266

267267
trust = if ultimate then BuiltLocally else BuiltElsewhere
268268

269-
pure $ StorePathMetadata{..}
269+
pure $ Metadata{..}
270270

271271
queryReferrers :: StorePath -> MonadStore (HashSet StorePath)
272272
queryReferrers p = do

0 commit comments

Comments
 (0)