|
| 1 | +-- due to recent generic-arbitrary |
| 2 | +{-# OPTIONS_GHC -Wno-orphans -fconstraint-solver-iterations=0 #-} |
1 | 3 |
|
2 | 4 | module System.Nix.Derivation |
3 | 5 | ( parseDerivation |
4 | 6 | , buildDerivation |
5 | | - ) |
6 | | -where |
| 7 | + ) where |
7 | 8 |
|
8 | | -import qualified Data.Text.Lazy.Builder as Text.Lazy |
9 | | - ( Builder ) |
10 | | -import qualified Data.Attoparsec.Text.Lazy as Text.Lazy |
11 | | - ( Parser ) |
12 | | -import Nix.Derivation ( Derivation ) |
13 | | -import qualified Nix.Derivation as Derivation |
14 | | -import System.Nix.StorePath ( StoreDir |
15 | | - , StorePath |
16 | | - , storePathToFilePath |
17 | | - ) |
18 | | -import qualified System.Nix.StorePath as StorePath |
| 9 | +import Data.Attoparsec.Text.Lazy (Parser) |
| 10 | +import Data.Text.Lazy.Builder (Builder) |
| 11 | +import Test.QuickCheck (Arbitrary(..)) |
| 12 | +import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..)) |
| 13 | +import Test.QuickCheck.Instances () |
19 | 14 |
|
| 15 | +import Nix.Derivation (Derivation, DerivationOutput) |
| 16 | +import System.Nix.StorePath (StoreDir, StorePath) |
20 | 17 |
|
| 18 | +import qualified Data.Attoparsec.Text.Lazy |
| 19 | +import qualified Data.Text.Lazy |
21 | 20 |
|
22 | | -parseDerivation :: StoreDir -> Text.Lazy.Parser (Derivation StorePath Text) |
| 21 | +import qualified Nix.Derivation |
| 22 | +import qualified System.Nix.StorePath |
| 23 | + |
| 24 | +deriving via GenericArbitrary (Derivation StorePath Text) |
| 25 | + instance Arbitrary (Derivation StorePath Text) |
| 26 | +deriving via GenericArbitrary (DerivationOutput StorePath Text) |
| 27 | + instance Arbitrary (DerivationOutput StorePath Text) |
| 28 | + |
| 29 | +parseDerivation :: StoreDir -> Parser (Derivation StorePath Text) |
23 | 30 | parseDerivation expectedRoot = |
24 | | - Derivation.parseDerivationWith |
25 | | - ("\"" *> StorePath.pathParser expectedRoot <* "\"") |
26 | | - Derivation.textParser |
| 31 | + Nix.Derivation.parseDerivationWith |
| 32 | + pathParser |
| 33 | + Nix.Derivation.textParser |
| 34 | + where |
| 35 | + pathParser = do |
| 36 | + text <- Nix.Derivation.textParser |
| 37 | + case Data.Attoparsec.Text.Lazy.parseOnly |
| 38 | + (System.Nix.StorePath.pathParser expectedRoot) |
| 39 | + (Data.Text.Lazy.fromStrict text) |
| 40 | + of |
| 41 | + Right p -> pure p |
| 42 | + Left e -> fail e |
27 | 43 |
|
28 | | -buildDerivation :: StoreDir -> Derivation StorePath Text -> Text.Lazy.Builder |
| 44 | +buildDerivation :: StoreDir -> Derivation StorePath Text -> Builder |
29 | 45 | buildDerivation storeDir = |
30 | | - Derivation.buildDerivationWith |
31 | | - (show . storePathToFilePath storeDir) |
| 46 | + Nix.Derivation.buildDerivationWith |
| 47 | + (show . System.Nix.StorePath.storePathToText storeDir) |
32 | 48 | show |
0 commit comments