{-|
Description : Metadata about Nix store paths.
-}
module System.Nix.StorePathMetadata where

import           System.Nix.StorePath           ( StorePath
                                                , StorePathSet
                                                , ContentAddressableAddress
                                                )
import           System.Nix.Hash                ( SomeNamedDigest )
import           Data.Time                      ( UTCTime )
import           System.Nix.Signature           ( NarSignature )

-- | Metadata about a 'StorePath'
data StorePathMetadata = StorePathMetadata
  { -- | The path this metadata is about
    StorePathMetadata -> StorePath
path :: !StorePath
  , -- | The path to the derivation file that built this path, if any
    -- and known.
    StorePathMetadata -> Maybe StorePath
deriverPath :: !(Maybe StorePath)
  , -- TODO should this be optional?
    -- | The hash of the nar serialization of the path.
    StorePathMetadata -> SomeNamedDigest
narHash :: !SomeNamedDigest
  , -- | The paths that this path directly references
    StorePathMetadata -> StorePathSet
references :: !StorePathSet
  , -- | When was this path registered valid in the store?
    StorePathMetadata -> UTCTime
registrationTime :: !UTCTime
  , -- | The size of the nar serialization of the path, in bytes.
    StorePathMetadata -> Maybe Word64
narBytes :: !(Maybe Word64)
  , -- | How much we trust this path.
    StorePathMetadata -> StorePathTrust
trust :: !StorePathTrust
  , -- | A set of cryptographic attestations of this path's validity.
    --
    -- There is no guarantee from this type alone that these
    -- signatures are valid.
    StorePathMetadata -> Set NarSignature
sigs :: !(Set NarSignature)
  , -- | Whether and how this store path is content-addressable.
    --
    -- There is no guarantee from this type alone that this address
    -- is actually correct for this store path.
    StorePathMetadata -> Maybe ContentAddressableAddress
contentAddressableAddress :: !(Maybe ContentAddressableAddress)
  }

-- | How much do we trust the path, based on its provenance?
data StorePathTrust
  = -- | It was built locally and thus ultimately trusted
    BuiltLocally
  | -- | It was built elsewhere (and substituted or similar) and so
    -- is less trusted
    BuiltElsewhere
  deriving (Int -> StorePathTrust -> ShowS
[StorePathTrust] -> ShowS
StorePathTrust -> String
(Int -> StorePathTrust -> ShowS)
-> (StorePathTrust -> String)
-> ([StorePathTrust] -> ShowS)
-> Show StorePathTrust
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StorePathTrust] -> ShowS
$cshowList :: [StorePathTrust] -> ShowS
show :: StorePathTrust -> String
$cshow :: StorePathTrust -> String
showsPrec :: Int -> StorePathTrust -> ShowS
$cshowsPrec :: Int -> StorePathTrust -> ShowS
Show, StorePathTrust -> StorePathTrust -> Bool
(StorePathTrust -> StorePathTrust -> Bool)
-> (StorePathTrust -> StorePathTrust -> Bool) -> Eq StorePathTrust
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StorePathTrust -> StorePathTrust -> Bool
$c/= :: StorePathTrust -> StorePathTrust -> Bool
== :: StorePathTrust -> StorePathTrust -> Bool
$c== :: StorePathTrust -> StorePathTrust -> Bool
Eq, Eq StorePathTrust
Eq StorePathTrust
-> (StorePathTrust -> StorePathTrust -> Ordering)
-> (StorePathTrust -> StorePathTrust -> Bool)
-> (StorePathTrust -> StorePathTrust -> Bool)
-> (StorePathTrust -> StorePathTrust -> Bool)
-> (StorePathTrust -> StorePathTrust -> Bool)
-> (StorePathTrust -> StorePathTrust -> StorePathTrust)
-> (StorePathTrust -> StorePathTrust -> StorePathTrust)
-> Ord StorePathTrust
StorePathTrust -> StorePathTrust -> Bool
StorePathTrust -> StorePathTrust -> Ordering
StorePathTrust -> StorePathTrust -> StorePathTrust
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: StorePathTrust -> StorePathTrust -> StorePathTrust
$cmin :: StorePathTrust -> StorePathTrust -> StorePathTrust
max :: StorePathTrust -> StorePathTrust -> StorePathTrust
$cmax :: StorePathTrust -> StorePathTrust -> StorePathTrust
>= :: StorePathTrust -> StorePathTrust -> Bool
$c>= :: StorePathTrust -> StorePathTrust -> Bool
> :: StorePathTrust -> StorePathTrust -> Bool
$c> :: StorePathTrust -> StorePathTrust -> Bool
<= :: StorePathTrust -> StorePathTrust -> Bool
$c<= :: StorePathTrust -> StorePathTrust -> Bool
< :: StorePathTrust -> StorePathTrust -> Bool
$c< :: StorePathTrust -> StorePathTrust -> Bool
compare :: StorePathTrust -> StorePathTrust -> Ordering
$ccompare :: StorePathTrust -> StorePathTrust -> Ordering
$cp1Ord :: Eq StorePathTrust
Ord)