Skip to content

Commit

Permalink
remote: add Remote.GADT
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Nov 30, 2023
1 parent c578cf6 commit f0f82f1
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
1 change: 1 addition & 0 deletions hnix-store-remote/hnix-store-remote.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ library
, System.Nix.Store.Remote
, System.Nix.Store.Remote.Arbitrary
, System.Nix.Store.Remote.Client
, System.Nix.Store.Remote.GADT
, System.Nix.Store.Remote.Logger
, System.Nix.Store.Remote.MonadStore
, System.Nix.Store.Remote.Serialize
Expand Down
150 changes: 150 additions & 0 deletions hnix-store-remote/src/System/Nix/Store/Remote/GADT.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{-# language GADTs #-}
{-# language Rank2Types #-}

module System.Nix.Store.Remote.GADT
( StoreRequest(..)
) where

import Control.Monad.IO.Class (MonadIO)
import Data.ByteString (ByteString)
import Data.HashSet (HashSet)
import Data.Kind (Type)
import Data.Map (Map)
import Data.Set (Set)
import Data.Text (Text)
import Data.Some (Some)

import System.Nix.Build (BuildMode, BuildResult)
import System.Nix.Derivation (Derivation)
import System.Nix.DerivedPath (DerivedPath)
import System.Nix.Hash (HashAlgo)
import System.Nix.Nar (NarSource)
import System.Nix.Store.Types (RepairMode)
import System.Nix.StorePath (StorePath, StorePathName, StorePathHashPart)
import System.Nix.StorePath.Metadata (Metadata)
import System.Nix.Store.Remote.Types.CheckMode (CheckMode)
import System.Nix.Store.Remote.Types.SubstituteMode (SubstituteMode)

data StoreRequest :: Type -> Type where
-- | Add @NarSource@ to the store.
AddToStore
:: StorePathName -- ^ Name part of the newly created @StorePath@
-> Bool -- ^ Add target directory recursively
-> Some HashAlgo
-> (forall m . MonadIO m => NarSource m) -- ^ provide nar stream
-> RepairMode -- ^ Only used by local store backend
-> StoreRequest StorePath

-- | Add text to store.
--
-- Reference accepts repair but only uses it
-- to throw error in case of remote talking to nix-daemon.
AddTextToStore
:: Text -- ^ Name of the text
-> Text -- ^ Actual text to add
-> HashSet StorePath -- ^ Set of @StorePath@s that the added text references
-> RepairMode -- ^ Repair mode, must be @RepairMode_DontRepair@ in case of remote backend
-> StoreRequest StorePath

AddSignatures
:: StorePath
-> [ByteString]
-> StoreRequest ()

-- | Add temporary garbage collector root.
--
-- This root is removed as soon as the client exits.
AddIndirectRoot
:: StorePath
-> StoreRequest ()

AddTempRoot
:: StorePath
-> StoreRequest ()

-- | Build paths if they are an actual derivations.
--
-- If derivation output paths are already valid, do nothing.
BuildPaths
:: Set DerivedPath
-> BuildMode
-> StoreRequest ()

BuildDerivation
:: StorePath
-> Derivation StorePath Text
-> BuildMode
-> StoreRequest BuildResult

EnsurePath
:: StorePath
-> StoreRequest ()

-- | Find garbage collector roots.
FindRoots
:: StoreRequest (Map ByteString StorePath)

IsValidPath
:: StorePath
-> StoreRequest Bool

-- | Query valid paths from set, optionally try to use substitutes.
QueryValidPaths
:: HashSet StorePath
-- ^ Set of @StorePath@s to query
-> SubstituteMode
-- ^ Try substituting missing paths when @SubstituteMode_DoSubstitute@
-> StoreRequest (HashSet StorePath)

QueryAllValidPaths
:: StoreRequest (HashSet StorePath)

QuerySubstitutablePaths
:: HashSet StorePath
-> StoreRequest (HashSet StorePath)

QueryPathInfo
:: StorePath
-> StoreRequest (Maybe (Metadata StorePath))

QueryReferrers
:: StorePath
-> StoreRequest (HashSet StorePath)

QueryValidDerivers
:: StorePath
-> StoreRequest (HashSet StorePath)

QueryDerivationOutputs
:: StorePath
-> StoreRequest (HashSet StorePath)

QueryDerivationOutputNames
:: StorePath
-> StoreRequest (HashSet StorePathName)

QueryPathFromHashPart
:: StorePathHashPart
-> StoreRequest StorePath

QueryMissing
:: Set DerivedPath
-> StoreRequest
( HashSet StorePath -- Paths that will be built
, HashSet StorePath -- Paths that have substitutes
, HashSet StorePath -- Unknown paths
, Integer -- Download size
, Integer -- Nar size?
)

OptimiseStore
:: StoreRequest ()

SyncWithGC
:: StoreRequest ()

-- returns True on errors
VerifyStore
:: CheckMode
-> RepairMode
-> StoreRequest Bool

0 comments on commit f0f82f1

Please sign in to comment.