@@ -1,26 +1,34 @@
1{-# LANGUAGE PatternGuards #-}
1{-# LANGUAGE PatternGuards #-}
3+ Module : Distribution.NixOS.Derivation.Cabal
4+ Copyright : Peter Simons, Andres Loeh
7+ Maintainer : nix-dev@cs.uu.nl
8+ Stability : provisional
9+ Portability : portable
3module Distribution.NixOS.Derivation.Cabal
12module Distribution.NixOS.Derivation.Cabal
4 ( Derivation(..)
13 ( Derivation(..)
5 , parseDerivation
14 , parseDerivation
6 , module Distribution.NixOS.Derivation.Meta
15 , module Distribution.NixOS.Derivation.Meta
7− , Version(..), PackageName(..)
16+ , Version(..)
11−import Distribution.NixOS.Derivation.PrettyPrinting
12import Distribution.NixOS.Derivation.Meta
20import Distribution.NixOS.Derivation.Meta
13−import Distribution.Package
21+import Distribution.NixOS.PrettyPrinting
14import Distribution.Text
22import Distribution.Text
23+import Distribution.Package
15import Data.Version
24import Data.Version
16import Data.List
25import Data.List
17import Data.Char
26import Data.Char
18−import Text.PrettyPrint
19import Text.ParserCombinators.ReadP ( readP_to_S )
27import Text.ParserCombinators.ReadP ( readP_to_S )
20import Text.Regex.Posix
28import Text.Regex.Posix
22data Derivation = MkDerivation
30data Derivation = MkDerivation
23− { pname :: PackageName
31+ { pname :: String
24 , version :: Version
32 , version :: Version
25 , sha256 :: String
33 , sha256 :: String
26 , isLibrary :: Bool
34 , isLibrary :: Bool
@@ -38,12 +46,15 @@ instance Text Derivation where
38 disp = renderDerivation
46 disp = renderDerivation
39 parse = error "parsing Distribution.NixOS.Derivation.Cabal.Derivation is not supported yet"
47 parse = error "parsing Distribution.NixOS.Derivation.Cabal.Derivation is not supported yet"
49+instance Package Derivation where
50+ packageId deriv = PackageIdentifier (PackageName (pname deriv)) (version deriv)
41renderDerivation :: Derivation -> Doc
52renderDerivation :: Derivation -> Doc
42renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
53renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
44 , text "cabal.mkDerivation" <+> lparen <> text "self" <> colon <+> lbrace
55 , text "cabal.mkDerivation" <+> lparen <> text "self" <> colon <+> lbrace
45 , nest 2 $ vcat
56 , nest 2 $ vcat
46− [ attr "pname" $ doubleQuotes (disp (pname deriv))
57+ [ attr "pname" $ string (pname deriv)
47 , attr "version" $ doubleQuotes (disp (version deriv))
58 , attr "version" $ doubleQuotes (disp (version deriv))
48 , attr "sha256" $ string (sha256 deriv)
59 , attr "sha256" $ string (sha256 deriv)
49 , boolattr "isLibrary" (not (isLibrary deriv) || (isExecutable deriv)) (isLibrary deriv)
60 , boolattr "isLibrary" (not (isLibrary deriv) || (isExecutable deriv)) (isLibrary deriv)
@@ -73,7 +84,7 @@ parseDerivation buf
73 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
84 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
74 , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
85 , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
75 = Just $ MkDerivation
86 = Just $ MkDerivation
76− { pname = PackageName name
87+ { pname = name
77 , version = readVersion vers
88 , version = readVersion vers
78 , sha256 = sha
89 , sha256 = sha
79 , isLibrary = False
90 , isLibrary = False