Permalink
Browse files

Re-use nixos-types library.

  • Loading branch information...
1 parent d19c3c2 commit a86bc154c93a5714d320afc2a0ecb0e57a8779fb @peti peti committed Aug 23, 2011
View
@@ -1,15 +1,6 @@
-module Main ( main ) where
+module Main (main) where
import Distribution.Simple
-import Distribution.Simple.LocalBuildInfo ( withPrograms )
-import Distribution.Simple.Program ( userSpecifyArgs )
main :: IO ()
-main = defaultMainWithHooks $
- simpleUserHooks `modify_haddockHook` \oldHH pkg lbi hooks flags ->
- (\lbi' -> oldHH pkg lbi' hooks flags) $
- lbi `modify_withPrograms` \oldWP ->
- userSpecifyArgs "haddock" ["--optghc=-D__HADDOCK__"] oldWP
- where
- modify_haddockHook hooks f = hooks { haddockHook = f (haddockHook hooks) }
- modify_withPrograms lbi f = lbi { withPrograms = f (withPrograms lbi) }
+main = defaultMain
View
@@ -9,7 +9,7 @@ Homepage: http://github.com/haskell4nix/cabal2nix
Category: Distribution
Synopsis: Convert Cabal files into Nix build instructions
Cabal-Version: >= 1.8
-Build-Type: Custom
+Build-Type: Simple
Tested-With: GHC == 6.12.3, GHC == 7.0.4, GHC == 7.2.1
Description:
The cabal2nix utility converts Cabal files into Nix build instructions. The
@@ -41,21 +41,11 @@ Source-Repository head
Type: git
Location: git://github.com/haskell4nix/cabal2nix.git
-Library
- Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8
- hs-source-dirs: src
- Extensions: PatternGuards, CPP
- Ghc-Options: -Wall
- Exposed-Modules: Distribution.NixOS.Derivation.Cabal
- Distribution.NixOS.Derivation.License
- Distribution.NixOS.Derivation.Meta
- other-modules: Distribution.NixOS.PrettyPrinting
-
Executable cabal2nix
main-is: Cabal2Nix.hs
hs-source-dirs: src
Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8,
- filepath, directory, process, HTTP
+ filepath, directory, process, HTTP, nixos-types
Extensions: PatternGuards, RecordWildCards, CPP
Ghc-Options: -Wall
other-modules: Cabal2Nix.CorePackages
@@ -66,16 +56,12 @@ Executable cabal2nix
Cabal2Nix.Normalize
Cabal2Nix.Package
Cabal2Nix.PostProcess
- Distribution.NixOS.Derivation.Cabal
- Distribution.NixOS.Derivation.License
- Distribution.NixOS.Derivation.Meta
- Distribution.NixOS.PrettyPrinting
Executable hackage4nix
main-is: Hackage4Nix.hs
hs-source-dirs: src
Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8,
- mtl, containers, directory, filepath
+ mtl, containers, directory, filepath, nixos-types
Extensions: PatternGuards, RecordWildCards, CPP
Ghc-Options: -Wall
other-modules: Cabal2Nix.CorePackages
@@ -85,10 +71,6 @@ Executable hackage4nix
Cabal2Nix.Normalize
Cabal2Nix.Package
Cabal2Nix.PostProcess
- Distribution.NixOS.Derivation.Cabal
- Distribution.NixOS.Derivation.License
- Distribution.NixOS.Derivation.Meta
- Distribution.NixOS.PrettyPrinting
Executable packagelist
main-is: PackageList.hs
@@ -1,127 +0,0 @@
-{-# LANGUAGE PatternGuards, CPP #-}
-{- |
- Module : Distribution.NixOS.Derivation.Cabal
- License : BSD3
-
- Maintainer : nix-dev@cs.uu.nl
- Stability : provisional
- Portability : PatternGuards
-
- A represtation of Nix expressions based on Cabal builder defined in
- @pkgs\/development\/libraries\/haskell\/cabal\/cabal.nix@.
--}
-
-module Distribution.NixOS.Derivation.Cabal
- ( Derivation(..)
- , parseDerivation
- , module Distribution.NixOS.Derivation.Meta
- , module Data.Version
- )
- where
-
-import Distribution.NixOS.Derivation.Meta
-import Distribution.NixOS.PrettyPrinting
-import Distribution.Text
-import Distribution.Package
-#ifdef __HADDOCK__
-import Distribution.PackageDescription ( PackageDescription )
-#endif
-import Data.Version
-import Data.List
-import Data.Char
-import Text.Regex.Posix
-
--- | A represtation of Nix expressions for building Haskell packages.
--- The data type correspond closely to the definition of
--- 'PackageDescription' from Cabal.
---
--- Note that the "Text" instance definition provides pretty-printing,
--- but no parsing as of now!
-
-data Derivation = MkDerivation
- { pname :: String
- , version :: Version
- , sha256 :: String
- , isLibrary :: Bool
- , isExecutable :: Bool
- , buildDepends :: [String]
- , buildTools :: [String]
- , extraLibs :: [String]
- , pkgConfDeps :: [String]
- , runHaddock :: Bool
- , metaSection :: Meta
- }
- deriving (Show, Eq, Ord)
-
-instance Text Derivation where
- disp = renderDerivation
- parse = error "parsing Distribution.NixOS.Derivation.Cabal.Derivation is not supported yet"
-
-instance Package Derivation where
- packageId deriv = PackageIdentifier (PackageName (pname deriv)) (version deriv)
-
-renderDerivation :: Derivation -> Doc
-renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
- [ text ""
- , text "cabal.mkDerivation" <+> lparen <> text "self" <> colon <+> lbrace
- , nest 2 $ vcat
- [ attr "pname" $ string (pname deriv)
- , attr "version" $ doubleQuotes (disp (version deriv))
- , attr "sha256" $ string (sha256 deriv)
- , boolattr "isLibrary" (not (isLibrary deriv) || (isExecutable deriv)) (isLibrary deriv)
- , boolattr "isExecutable" (not (isLibrary deriv) || (isExecutable deriv)) (isExecutable deriv)
- , listattr "buildDepends" (buildDepends deriv)
- , listattr "buildTools" (buildTools deriv)
- , listattr "extraLibraries" (extraLibs deriv)
- , listattr "pkgconfigDepends" (pkgConfDeps deriv)
- , boolattr "noHaddock" (not (runHaddock deriv)) (not (runHaddock deriv))
- , disp (metaSection deriv)
- ]
- , rbrace <> rparen
- , text ""
- ]
- where
- inputs = nub $ sortBy (\x y -> compare (map toLower x) (map toLower y)) $
- filter (/="cabal") $ filter (/="Cabal") $
- buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
-
--- | A very incomplete parser that extracts 'pname', 'version',
--- 'sha256', 'platforms', 'maintainers', and 'runHaddock' from the given
--- Nix expression.
-
-parseDerivation :: String -> Maybe Derivation
-parseDerivation buf
- | buf =~ "cabal.mkDerivation"
- , [name] <- buf `regsubmatch` "pname *= *\"([^\"]+)\""
- , [vers'] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
- , Just vers <- simpleParse vers'
- , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
- , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
- , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
- , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
- = Just $ MkDerivation
- { pname = name
- , version = vers
- , sha256 = sha
- , isLibrary = False
- , isExecutable = False
- , buildDepends = []
- , buildTools = []
- , extraLibs = []
- , pkgConfDeps = []
- , runHaddock = case noHaddock of "true":[] -> False
- _ -> True
- , metaSection = Meta
- { homepage = ""
- , description = ""
- , license = Unknown Nothing
- , maintainers = concatMap words maint
- , platforms = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats)
- }
- }
- | otherwise = Nothing
-
-regsubmatch :: String -> String -> [String]
-regsubmatch buf patt = let (_,_,_,x) = f in x
- where f :: (String,String,String,[String])
- f = match (makeRegexOpts compExtended execBlank patt) buf
@@ -1,51 +0,0 @@
-{- |
- Module : Distribution.NixOS.Derivation.License
- License : BSD3
-
- Maintainer : nix-dev@cs.uu.nl
- Stability : provisional
- Portability : portable
-
- Known licenses in Nix expressions are represented using the
- attributes defined in @pkgs\/lib\/licenses.nix@, and unknown licenses
- are represented as a literal string.
- -}
-
-module Distribution.NixOS.Derivation.License ( License(..) ) where
-
-import Distribution.NixOS.PrettyPrinting
-import Distribution.Text
-
--- | The representation for licenses used in Nix derivations. Known
--- licenses are Nix expressions -- such as @stdenv.lib.licenses.bsd3@
--- --, so their exact \"name\" is not generally known, because the path
--- to @stdenv@ depends on the context defined in the expression. In
--- Cabal expressions, for example, the BSD3 license would have to be
--- referred to as @self.stdenv.lib.licenses.bsd3@. Other expressions,
--- however, use different paths to the @licenses@ record.. Because of
--- this station, this library cannot provide an abstract data type that
--- encompasses all known licenses. Instead, the @License@ type just
--- distinguishes references to known and unknown licenses. The
--- difference between the two is in the way they are pretty-printed:
---
--- > > putStrLn (display (Known "stdenv.lib.license.gpl2"))
--- > stdenv.lib.license.gpl2
--- >
--- > > putStrLn (display (Unknown (Just "GPL")))
--- > "GPL"
--- >
--- > > putStrLn (display (Unknown Nothing))
--- > "unknown"
---
--- Note that the "Text" instance definition provides pretty-printing,
--- but no parsing as of now!
-
-data License = Known String
- | Unknown (Maybe String)
- deriving (Show, Eq, Ord)
-
-instance Text License where
- disp (Known x) = text x
- disp (Unknown x) = string (maybe "unknown" id x)
- parse = error "parsing Distribution.NixOS.Derivation.License is not supported yet"
-
@@ -1,68 +0,0 @@
-{- |
- Module : Distribution.NixOS.Derivation.Meta
- License : BSD3
-
- Maintainer : nix-dev@cs.uu.nl
- Stability : provisional
- Portability : portable
-
- A representation of the @meta@ section used in Nix expressions. A
- detailed description can be found in section 4, \"Meta-attributes\",
- of the Nixpkgs manual at <http://nixos.org/nixpkgs/docs.html>.
- -}
-
-module Distribution.NixOS.Derivation.Meta
- ( Meta(..)
- , module Distribution.NixOS.Derivation.License
- )
- where
-
-import Distribution.NixOS.PrettyPrinting
-import Distribution.NixOS.Derivation.License
-import Distribution.Text
-
--- | A representation of the @meta@ section used in Nix expressions.
---
--- > > putStrLn (display (Meta "http://example.org" "an example package" (Unknown Nothing)
--- > > ["stdenv.lib.platforms."++x | x<-["unix","cygwin"]]
--- > > ["stdenv.lib.maintainers."++x | x<-["joe","jane"]]))
--- > meta = {
--- > homepage = "http://example.org";
--- > description = "an example package";
--- > license = "unknown";
--- > platforms =
--- > stdenv.lib.platforms.unix ++ stdenv.lib.platforms.cygwin;
--- > maintainers = [ stdenv.lib.maintainers.joe stdenv.lib.maintainers.jane ];
--- > };
---
--- Note that the "Text" instance definition provides pretty-printing,
--- but no parsing as of now!
-
-data Meta = Meta
- { homepage :: String -- ^ URL of the package homepage
- , description :: String -- ^ short description of the package
- , license :: License -- ^ licensing terms
- , platforms :: [String] -- ^ list of supported platforms from @pkgs\/lib\/platforms.nix@
- , maintainers :: [String] -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
- }
- deriving (Show, Eq, Ord)
-
-instance Text Meta where
- disp = renderMeta
- parse = error "parsing Distribution.NixOS.Derivation.Cabal.Meta is not supported yet"
-
-renderMeta :: Meta -> Doc
-renderMeta meta = vcat
- [ text "meta" <+> equals <+> lbrace
- , nest 2 $ vcat
- [ onlyIf (homepage meta) $ attr "homepage" $ string (homepage meta)
- , onlyIf (description meta) $ attr "description" $ string (description meta)
- , attr "license" $ disp (license meta)
- , onlyIf (platforms meta) $ sep
- [ text "platforms" <+> equals
- , nest 2 ((fsep $ punctuate (text " ++") $ map text (platforms meta))) <> semi
- ]
- , listattr "maintainers" (maintainers meta)
- ]
- , rbrace <> semi
- ]
@@ -1,57 +0,0 @@
-{- |
- Module : Distribution.NixOS.PrettyPrinting
- License : BSD3
-
- Maintainer : nix-dev@cs.uu.nl
- Stability : provisional
- Portability : portable
-
- Internal pretty-printing helpers for Nix expressions.
--}
-
-module Distribution.NixOS.PrettyPrinting
- ( onlyIf
- , listattr
- , boolattr
- , attr
- , string
- , funargs
- , module Text.PrettyPrint
- )
- where
-
-import Text.PrettyPrint
-
-attr :: String -> Doc -> Doc
-attr n v = text n <+> equals <+> v <> semi
-
-onlyIf :: [a] -> Doc -> Doc
-onlyIf p d = if not (null p) then d else empty
-
-boolattr :: String -> Bool -> Bool -> Doc
-boolattr n p v = if p then attr n (bool v) else empty
-
-listattr :: String -> [String] -> Doc
-listattr n vs = onlyIf vs $
- sep [ text n <+> equals <+> lbrack,
- nest 2 $ fsep $ map text vs,
- rbrack <> semi
- ]
-
-bool :: Bool -> Doc
-bool True = text "true"
-bool False = text "false"
-
-string :: String -> Doc
-string = doubleQuotes . text
-
-prepunctuate :: Doc -> [Doc] -> [Doc]
-prepunctuate _ [] = []
-prepunctuate p (d:ds) = d : map (p <>) ds
-
-funargs :: [Doc] -> Doc
-funargs xs = sep [
- lbrace <+> (fcat $ prepunctuate (comma <> text " ") $
- map (nest 2) xs),
- rbrace <> colon
- ]

0 comments on commit a86bc15

Please sign in to comment.