module System.Nix.Derivation
  ( parseDerivation
  , buildDerivation
  )
where

import qualified Data.Text.Lazy.Builder        as Text.Lazy
                                                ( Builder )
import qualified Data.Attoparsec.Text.Lazy     as Text.Lazy
                                                ( Parser )
import           Nix.Derivation                 ( Derivation )
import qualified Nix.Derivation                as Derivation
import           System.Nix.StorePath           ( StoreDir
                                                , StorePath
                                                , storePathToFilePath
                                                )
import qualified System.Nix.StorePath          as StorePath



parseDerivation :: StoreDir -> Text.Lazy.Parser (Derivation StorePath Text)
parseDerivation :: StoreDir -> Parser (Derivation StorePath Text)
parseDerivation StoreDir
expectedRoot =
  forall fp txt.
(Ord fp, Ord txt) =>
Parser fp -> Parser txt -> Parser (Derivation fp txt)
Derivation.parseDerivationWith
    (Parser Text Text
"\"" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> StoreDir -> Parser Text StorePath
StorePath.pathParser StoreDir
expectedRoot forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Text Text
"\"")
    Parser Text Text
Derivation.textParser

buildDerivation :: StoreDir -> Derivation StorePath Text -> Text.Lazy.Builder
buildDerivation :: StoreDir -> Derivation StorePath Text -> Builder
buildDerivation StoreDir
storeDir =
  forall fp txt.
(fp -> Builder) -> (txt -> Builder) -> Derivation fp txt -> Builder
Derivation.buildDerivationWith
    (forall b a. (Show a, IsString b) => a -> b
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. StoreDir -> StorePath -> FilePath
storePathToFilePath StoreDir
storeDir)
    forall b a. (Show a, IsString b) => a -> b
show