@@ -14,12 +14,12 @@
14module Distribution.NixOS.Derivation.Cabal
14module Distribution.NixOS.Derivation.Cabal
15 ( Derivation(..)
15 ( Derivation(..)
16 , parseDerivation
16 , parseDerivation
17+ , DerivationSource(..)
17 , module Distribution.NixOS.Derivation.Meta
18 , module Distribution.NixOS.Derivation.Meta
18 , module Data.Version
19 , module Data.Version
23import Distribution.NixOS.Derivation.Meta
23import Distribution.NixOS.Derivation.Meta
24import Distribution.NixOS.PrettyPrinting
24import Distribution.NixOS.PrettyPrinting
25import Distribution.Package
25import Distribution.Package
@@ -34,18 +34,18 @@ import Data.Char
34import Data.Function
34import Data.Function
35import Text.Regex.Posix hiding ( empty )
35import Text.Regex.Posix hiding ( empty )
37+data DerivationSource = Hackage String | Directory String | FetchUrl String String deriving (Eq, Show, Ord)
37-- | A represtation of Nix expressions for building Haskell packages.
39-- | A represtation of Nix expressions for building Haskell packages.
38-- The data type correspond closely to the definition of
40-- The data type correspond closely to the definition of
39-- 'PackageDescription' from Cabal.
41-- 'PackageDescription' from Cabal.
41-- Note that the "Text" instance definition provides pretty-printing,
43-- Note that the "Text" instance definition provides pretty-printing,
42-- but no parsing as of now!
44-- but no parsing as of now!
44data Derivation = MkDerivation
45data Derivation = MkDerivation
45 { pname :: String
46 { pname :: String
46 , version :: Version
47 , version :: Version
47− , sha256 :: Maybe String
48+ , src :: DerivationSource
48− , src :: Maybe FilePath
49 , isLibrary :: Bool
49 , isLibrary :: Bool
50 , isExecutable :: Bool
50 , isExecutable :: Bool
51 , extraFunctionArgs :: [String]
51 , extraFunctionArgs :: [String]
@@ -79,9 +79,7 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
79 , nest 2 $ vcat $
79 , nest 2 $ vcat $
80 [ attr "pname" $ string (pname deriv)
80 [ attr "pname" $ string (pname deriv)
81 , attr "version" $ doubleQuotes (disp (version deriv))
81 , attr "version" $ doubleQuotes (disp (version deriv))
82− ] ++ maybeToList (fmap (attr "sha256" . string) $ sha256 deriv)
82+ ] ++ sourceAttrs (src deriv) ++
83− ++ maybeToList (fmap (attr "src" . text) $ src deriv)
85 [ boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
83 [ boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
86 , boolattr "isExecutable" (not (isLibrary deriv) || isExecutable deriv) (isExecutable deriv)
84 , boolattr "isExecutable" (not (isLibrary deriv) || isExecutable deriv) (isExecutable deriv)
87 , listattr "buildDepends" (buildDepends deriv)
85 , listattr "buildDepends" (buildDepends deriv)
@@ -103,8 +101,15 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
104 inputs = nub $ sortBy (compare `on` map toLower) $ filter (/="cabal") $ filter (not . isPrefixOf "self.") $
102 inputs = nub $ sortBy (compare `on` map toLower) $ filter (/="cabal") $ filter (not . isPrefixOf "self.") $
105 buildDepends deriv ++ testDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv ++ extraFunctionArgs deriv
103 buildDepends deriv ++ testDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv ++ extraFunctionArgs deriv
104+ ++ ["fetchurl" | FetchUrl _ _ <- [src deriv]]
106 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ]
105 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ]
107 ++ map text (configureFlags deriv)
106 ++ map text (configureFlags deriv)
107+ sourceAttrs (Hackage hash) = [attr "sha256" $ string hash]
108+ sourceAttrs (Directory dir) = [attr "src" $ text dir]
109+ sourceAttrs (FetchUrl url hash) = return $ attr "src" $ text "fetchurl" <+> lbrace $$ nest 2 (vcat
110+ [ attr "url" $ string url
111+ , attr "sha256" $ string hash
109-- | A very incomplete parser that extracts 'pname', 'version',
114-- | A very incomplete parser that extracts 'pname', 'version',
110-- 'sha256', 'platforms', 'hydraPlatforms', 'maintainers', 'doCheck',
115-- 'sha256', 'platforms', 'hydraPlatforms', 'maintainers', 'doCheck',
@@ -116,8 +121,9 @@ parseDerivation buf
116 , [name] <- buf `regsubmatch` "pname *= *\"([^\"]+)\""
121 , [name] <- buf `regsubmatch` "pname *= *\"([^\"]+)\""
117 , [vers'] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
122 , [vers'] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
118 , Just vers <- simpleParse vers'
123 , Just vers <- simpleParse vers'
119− , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
124+ , sha <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
120 , sr <- buf `regsubmatch` "src *= *([^;]+);"
125 , sr <- buf `regsubmatch` "src *= *([^;]+);"
126+ , url <- buf `regsubmatch` "url *= *([^;]+);"
121 , hplats <- buf `regsubmatch` "hydraPlatforms *= *([^;]+);"
127 , hplats <- buf `regsubmatch` "hydraPlatforms *= *([^;]+);"
122 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
128 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
123 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
129 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
@@ -127,8 +133,11 @@ parseDerivation buf
127 = Just MkDerivation
133 = Just MkDerivation
128 { pname = name
134 { pname = name
129 , version = vers
135 , version = vers
130− , sha256 = listToMaybe sha
136+ , src = case (sr,url) of
131− , src = listToMaybe sr
137+ ([] , _ ) -> Hackage $ head sha
138+ (_ , url':_ ) -> FetchUrl url' $ head sha
139+ (sr':_, [] ) -> Directory sr'
132 , isLibrary = False
141 , isLibrary = False
133 , isExecutable = False
142 , isExecutable = False
134 , extraFunctionArgs = []
143 , extraFunctionArgs = []