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           ( StorePath )
import qualified System.Nix.StorePath          as StorePath



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

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