packages feed

nova-nix-0.11.0.0 / src / Nix / Push / Source.hs

-- | What a push reads: a t'PushSource' gives the records of the paths it-- sends and says where their files are.  "Nix.Push" and-- "Nix.Push.Directory" push from one.  'localPushSource' reads the records-- from an opened store's database, and a store reached through a daemon-- ("Nix.Daemon.ClientStore") asks the daemon for them.---- A source gives the records a push needs of a path in two ways, so that-- computing the closure asks only the references: 'psReferences', and-- 'psPathInfo' for the NAR hash and deriver of a path that is sent.module Nix.Push.Source  ( PushSource (..),    PushedPath (..),    localPushSource,  )whereimport Data.Text (Text)import Nix.Logger (Logger)import Nix.Store (Store (..), queryAllValidPaths, queryPathInfo, queryReferences, volumeCaseHack)import qualified Nix.Store.DB as DBimport Nix.Store.Path (StoreDir, StorePath, parseStorePath)import qualified NovaCache.NAR as NAR-- | What a source records of a path a push sends: the NAR hash it was-- registered under, the paths it refers to and the derivation that built-- it, if known.data PushedPath = PushedPath  { -- | The hash of the path's NAR serialisation, as a store's database    -- spells it ('Hash.formatNixHash').    ppNarHash :: !Text,    -- | The paths it refers to.    ppReferences :: ![StorePath],    -- | The derivation that built it.    ppDeriver :: !(Maybe StorePath)  }  deriving (Eq, Show)-- | What a push reads: where the files of the paths are, and what is-- recorded of each.  A record the source cannot give is a 'Left' with the-- reason, which fails the push.data PushSource = PushSource  { -- | The directory the files of the paths are read from.    psStoreDir :: !StoreDir,    -- | How the NAR of a tree is made on this volume    -- ('volumeCaseHack').    psCaseHack :: !NAR.CaseHack,    -- | Where the push's progress lines go.    psLogger :: !Logger,    -- | The paths a path refers to, none for a path the source does not    -- hold.  Computing a closure asks only this, so a record of a path    -- that is not sent need not read.    psReferences :: !(StorePath -> IO (Either Text [StorePath])),    -- | What is recorded of a path, or 'Nothing' for a path the source    -- does not hold as valid.    psPathInfo :: !(StorePath -> IO (Either Text (Maybe PushedPath))),    -- | Every valid path.    psAllValid :: !(IO (Either Text [StorePath]))  }-- | A store opened directly as a source: its records are its database's,-- parsed under its directory, which under @--store@ is not the platform's.-- A reference that does not parse fails the read, and so does a valid-- path that does not; a deriver that does not parse is dropped.localPushSource :: Store -> PushSourcelocalPushSource store =  PushSource    { psStoreDir = stDir store,      psCaseHack = volumeCaseHack (stCaseSensitivity store),      psLogger = stLogger store,      psReferences = localReferences store,      psPathInfo = localPathInfo store,      psAllValid = traverse parseValidPath <$> queryAllValidPaths (stDB store)    }  where    parseValidPath txt = maybe (Left ("unparseable store DB path: " <> txt)) Right (parseStorePath (stDir store) txt)-- | The references of a path in a store's database, none for a path it-- does not register.localReferences :: Store -> StorePath -> IO (Either Text [StorePath])localReferences store sp = traverse (parseReference store) <$> queryReferences (stDB store) sp-- | The record of a path in a store's database.localPathInfo :: Store -> StorePath -> IO (Either Text (Maybe PushedPath))localPathInfo store sp = do  recorded <- queryPathInfo (stDB store) sp  case recorded of    Nothing -> pure (Right Nothing)    Just info -> do      refTexts <- queryReferences (stDB store) sp      pure $ do        refs <- traverse (parseReference store) refTexts        Right (Just PushedPath {ppNarHash = DB.piNarHash info, ppReferences = refs, ppDeriver = DB.piDeriver info >>= parseStorePath (stDir store)})-- | A reference as the database spells it, parsed under the store's-- directory.parseReference :: Store -> Text -> Either Text StorePathparseReference store txt = maybe (Left ("unparseable reference in store DB: " <> txt)) Right (parseStorePath (stDir store) txt)