mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-08-17 22:00:43 +03:00
remote: simplify buildDerivation
This commit is contained in:
parent
da9b46cdc3
commit
696f9e8421
@ -2,39 +2,23 @@
|
||||
module Main where
|
||||
|
||||
import Data.Default.Class (Default(def))
|
||||
import Data.Text (Text)
|
||||
import System.Nix.Derivation (Derivation)
|
||||
import System.Nix.StorePath (StorePath)
|
||||
|
||||
import qualified Data.Text
|
||||
import qualified Data.Text.IO
|
||||
import qualified Data.Attoparsec.Text
|
||||
import qualified System.Environment
|
||||
import qualified System.Nix.Build
|
||||
import qualified System.Nix.Derivation
|
||||
import qualified System.Nix.StorePath
|
||||
import qualified System.Nix.Store.Remote
|
||||
|
||||
parseDerivation :: FilePath -> IO (Derivation StorePath Text)
|
||||
parseDerivation source = do
|
||||
contents <- Data.Text.IO.readFile source
|
||||
case Data.Attoparsec.Text.parseOnly
|
||||
(System.Nix.Derivation.parseDerivation def) contents of
|
||||
Left e -> error e
|
||||
Right drv -> pure drv
|
||||
|
||||
main :: IO ()
|
||||
main = System.Environment.getArgs >>= \case
|
||||
[filename] -> do
|
||||
case System.Nix.StorePath.parsePathFromText def (Data.Text.pack filename) of
|
||||
Left e -> error $ show e
|
||||
Right p -> do
|
||||
d <- parseDerivation filename
|
||||
out <-
|
||||
System.Nix.Store.Remote.runStore
|
||||
$ System.Nix.Store.Remote.buildDerivation
|
||||
p
|
||||
d
|
||||
System.Nix.Build.BuildMode_Normal
|
||||
print out
|
||||
_ -> error "No input derivation file"
|
||||
|
@ -137,7 +137,6 @@ executable build-derivation
|
||||
buildable: False
|
||||
build-depends:
|
||||
base >=4.12 && <5
|
||||
, attoparsec
|
||||
, hnix-store-core
|
||||
, hnix-store-remote
|
||||
, data-default-class
|
||||
|
@ -32,10 +32,8 @@ import Data.HashSet (HashSet)
|
||||
import Data.Map (Map)
|
||||
import Data.Set (Set)
|
||||
import Data.Some (Some)
|
||||
import Data.Text (Text)
|
||||
|
||||
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)
|
||||
@ -52,6 +50,12 @@ import System.Nix.Store.Remote.Types.SubstituteMode (SubstituteMode)
|
||||
import System.Nix.Store.Remote.Client.Core
|
||||
import System.Nix.Store.Types (FileIngestionMethod(..), RepairMode(..))
|
||||
|
||||
import qualified Control.Monad.IO.Class
|
||||
import qualified Data.Attoparsec.Text
|
||||
import qualified Data.Text.IO
|
||||
import qualified System.Nix.Derivation
|
||||
import qualified System.Nix.StorePath
|
||||
|
||||
-- | Add `NarSource` to the store
|
||||
addToStore
|
||||
:: MonadRemoteStore m
|
||||
@ -114,10 +118,18 @@ addIndirectRoot = doReq . AddIndirectRoot
|
||||
buildDerivation
|
||||
:: MonadRemoteStore m
|
||||
=> StorePath
|
||||
-> Derivation StorePath Text
|
||||
-> BuildMode
|
||||
-> m BuildResult
|
||||
buildDerivation a b c = doReq (BuildDerivation a b c)
|
||||
buildDerivation sp mode = do
|
||||
sd <- getStoreDir
|
||||
drvContents <-
|
||||
Control.Monad.IO.Class.liftIO
|
||||
$ Data.Text.IO.readFile
|
||||
$ System.Nix.StorePath.storePathToFilePath sd sp
|
||||
case Data.Attoparsec.Text.parseOnly
|
||||
(System.Nix.Derivation.parseDerivation sd) drvContents of
|
||||
Left e -> throwError $ RemoteStoreError_DerivationParse e
|
||||
Right drv -> doReq (BuildDerivation sp drv mode)
|
||||
|
||||
-- | Build paths if they are an actual derivations.
|
||||
--
|
||||
|
@ -55,6 +55,7 @@ data RemoteStoreError
|
||||
= RemoteStoreError_Fixme String
|
||||
| RemoteStoreError_BuildFailed
|
||||
| RemoteStoreError_ClientVersionTooOld
|
||||
| RemoteStoreError_DerivationParse String
|
||||
| RemoteStoreError_Disconnected
|
||||
| RemoteStoreError_GetAddrInfoFailed
|
||||
| RemoteStoreError_GenericIncrementalLeftovers String ByteString -- when there are bytes left over after genericIncremental parser is done, (Done x leftover), first param is show x
|
||||
|
Loading…
Reference in New Issue
Block a user