11{-# language GADTs #-}
22{-# language Rank2Types #-}
3+ {-# LANGUAGE TemplateHaskell #-}
34
45module System.Nix.Store.Remote.GADT
56 ( StoreRequest (.. )
67 ) where
78
8- import Control.Monad.IO.Class (MonadIO )
99import Data.ByteString (ByteString )
10+ import Data.GADT.Compare.TH (deriveGEq , deriveGCompare )
11+ import Data.GADT.Show.TH (deriveGShow )
1012import Data.HashSet (HashSet )
1113import Data.Kind (Type )
1214import Data.Map (Map )
1315import Data.Set (Set )
1416import Data.Text (Text )
15- import Data.Some (Some )
17+ import Data.Some (Some ( Some ) )
1618
1719import System.Nix.Build (BuildMode , BuildResult )
1820import System.Nix.Derivation (Derivation )
1921import System.Nix.DerivedPath (DerivedPath )
2022import System.Nix.Hash (HashAlgo )
21- import System.Nix.Nar (NarSource )
2223import System.Nix.Store.Types (RepairMode )
2324import System.Nix.StorePath (StorePath , StorePathName , StorePathHashPart )
2425import System.Nix.StorePath.Metadata (Metadata )
@@ -30,8 +31,16 @@ data StoreRequest :: Type -> Type where
3031 AddToStore
3132 :: StorePathName -- ^ Name part of the newly created @StorePath@
3233 -> Bool -- ^ Add target directory recursively
33- -> Some HashAlgo
34- -> (forall m . MonadIO m => NarSource m ) -- ^ provide nar stream
34+ -> Some HashAlgo -- ^ Nar hashing algorithm
35+ -- -> (forall m . MonadIO m => NarSource m) -- ^ provide nar stream
36+ -- Not part of StoreRequest
37+ -- as it would require StoreRequest (m :: Type -> Type) :: Type -> Type
38+ -- for which we cannot derive anything
39+ --
40+ -- Also the thing is the only special case
41+ -- and it is always sent *after* the other
42+ -- information so it can be handled
43+ -- separately after that. Hopefully.
3544 -> RepairMode -- ^ Only used by local store backend
3645 -> StoreRequest StorePath
3746
@@ -148,3 +157,37 @@ data StoreRequest :: Type -> Type where
148157 :: CheckMode
149158 -> RepairMode
150159 -> StoreRequest Bool
160+
161+ deriving instance Eq (StoreRequest a )
162+ deriving instance Show (StoreRequest a )
163+
164+ deriveGEq ''StoreRequest
165+ deriveGCompare ''StoreRequest
166+ deriveGShow ''StoreRequest
167+
168+ instance {-# OVERLAPPING #-} Eq (Some StoreRequest ) where
169+ Some (AddToStore a b c d) == Some (AddToStore a' b' c' d') = (a, b, c, d) == (a', b', c', d')
170+ Some (AddTextToStore a b c d) == Some (AddTextToStore a' b' c' d') = (a, b, c, d) == (a', b', c', d')
171+ Some (AddSignatures a b) == Some (AddSignatures a' b') = (a, b) == (a', b')
172+ Some (AddIndirectRoot a) == Some (AddIndirectRoot a') = a == a'
173+ Some (AddTempRoot a) == Some (AddTempRoot a') = a == a'
174+ Some (BuildPaths a b) == Some (BuildPaths a' b') = (a, b) == (a', b')
175+ Some (BuildDerivation a b c) == Some (BuildDerivation a' b' c') = (a, b, c) == (a', b', c')
176+ Some (EnsurePath a) == Some (EnsurePath a') = a == a'
177+ Some (FindRoots ) == Some (FindRoots ) = True
178+ Some (IsValidPath a) == Some (IsValidPath a') = a == a'
179+ Some (QueryValidPaths a b) == Some (QueryValidPaths a' b') = (a, b) == (a', b')
180+ Some QueryAllValidPaths == Some QueryAllValidPaths = True
181+ Some (QuerySubstitutablePaths a) == Some (QuerySubstitutablePaths a') = a == a'
182+ Some (QueryPathInfo a) == Some (QueryPathInfo a') = a == a'
183+ Some (QueryReferrers a) == Some (QueryReferrers a') = a == a'
184+ Some (QueryValidDerivers a) == Some (QueryValidDerivers a') = a == a'
185+ Some (QueryDerivationOutputs a) == Some (QueryDerivationOutputs a') = a == a'
186+ Some (QueryDerivationOutputNames a) == Some (QueryDerivationOutputNames a') = a == a'
187+ Some (QueryPathFromHashPart a) == Some (QueryPathFromHashPart a') = a == a'
188+ Some (QueryMissing a) == Some (QueryMissing a') = a == a'
189+ Some OptimiseStore == Some OptimiseStore = True
190+ Some SyncWithGC == Some SyncWithGC = True
191+ Some (VerifyStore a b) == Some (VerifyStore a' b') = (a, b) == (a', b')
192+
193+ _ == _ = False
0 commit comments