packages feed

nova-nix-0.11.0.0 / src / Nix / Trust / Fetch.hs

-- | Making a closure's fixed-output inputs valid without running anything-- from the closure, then reading those the store holds, for-- "Nix.Trust"'s report.---- The store is an argument, a t'FixedOutputStore', so the order the inputs-- are made valid and read in, and the failure each step stops with, are-- pure logic that runs in tests over a monad that records the calls.  A-- store opened directly and a store reached through a daemon-- ("Nix.Daemon.ClientStore") each give the four operations.module Nix.Trust.Fetch  ( FixedOutputStore (..),    fetchAndScan,  )whereimport Control.Monad.Except (ExceptT (..), liftEither, runExceptT)import Control.Monad.Trans (lift)import Data.Bool (bool)import Data.Foldable (traverse_)import Data.List (partition)import Data.Map.Strict (Map)import qualified Data.Map.Strict as Mapimport Data.Maybe (catMaybes)import Data.Text (Text)import Nix.DependencyGraph (DepNode (..))import Nix.Realise (ClosureOutcome (..))import Nix.Store.Path (StorePath, defaultStoreDir, storePathToText)import Nix.Trust (ContentFacts, fetchedByBuiltin)-- | What making the inputs valid and reading them asks of a store.  An-- operation that cannot be carried out, as opposed to one that ends in-- an outcome, is a 'Left' with the reason.data FixedOutputStore m = FixedOutputStore  { -- | Realise an input 'fetchedByBuiltin' selects, which fetches it or    -- substitutes it.  'Left' is why it failed.    fosFetch :: !(DepNode -> m (Either Text ())),    -- | Substitute an input's output with what it references.  'Left' is    -- why the store could not be asked.    fosSubstitute :: !(StorePath -> m (Either Text ClosureOutcome)),    -- | Whether the store holds a path as valid.    fosHeld :: !(StorePath -> m (Either Text Bool)),    -- | The facts of a held path's files.    fosScan :: !(StorePath -> m ContentFacts)  }-- | Make each fixed-output input's output valid in a way that runs-- nothing from the closure, then scan every one the store holds.  An-- input that nova-nix's builtins fetch with no input of their own is-- realised, which substitutes or fetches it; any other is only-- substituted, with what it references, since making it would run its-- builder.  That substitution leaves the derivation's @allowSubstitutes@-- unread: the attribute chooses between building and substituting, and-- there is no build here to choose.---- Every fetch is made first, then every substitution, then each input is-- read in order: asked whether the store holds it, and scanned if so.-- The first fetch that fails stops the run, as a build stops, and so-- does the first substitution that fails, as upstream's goal for-- substituting a path fails when a substituter fails, whatever-- @fallback@ says: @--fallback@ passes over only a cache that cannot be-- asked, there and here.  An input no cache offers, or whose references-- no cache offers, does not stop the run: it is not held, so it is not-- read, and the report names it as not read.  A failure is the reason-- alone, for the caller to word.fetchAndScan :: (Monad m) => FixedOutputStore m -> [(DepNode, StorePath)] -> m (Either Text (Map StorePath ContentFacts))fetchAndScan store inputs = runExceptT $ do  traverse_ (ExceptT . fosFetch store . fst) fetched  traverse_ (substitute . snd) others  Map.fromList . catMaybes <$> traverse scan inputs  where    (fetched, others) = partition (fetchedByBuiltin . dnDerivation . fst) inputs    substitute output = ExceptT (fosSubstitute store output) >>= liftEither . substitutionStop output    scan (_, output) = do      held <- ExceptT (fosHeld store output)      bool (pure Nothing) (Just . (,) output <$> lift (fosScan store output)) held-- | Whether a substitution's outcome stops the run, and with what words.-- An input no cache offers, or whose references no cache offers, does-- not: it is left unread.substitutionStop :: StorePath -> ClosureOutcome -> Either Text ()substitutionStop _ ClosureComplete = Right ()substitutionStop _ ClosureUnavailable = Right ()substitutionStop _ ClosureIncomplete = Right ()substitutionStop output ClosureFailed = Left ("a substitute for '" <> storePathToText defaultStoreDir output <> "' or a path it references failed")substitutionStop _ (ClosureQueryFailed failure) = Left failure