cabal2nix 1.9 → 1.10
raw patch · 6 files changed
+126/−129 lines, 6 filesdep −bytestringdep ~Cabal
Dependencies removed: bytestring
Dependency ranges changed: Cabal
Files
- cabal2nix.cabal +5/−4
- src/Cabal2Nix.hs +4/−2
- src/Cabal2Nix/CorePackages.hs +1/−1
- src/Cabal2Nix/License.hs +1/−1
- src/Cabal2Nix/Package.hs +22/−8
- src/Hackage4Nix.hs +93/−113
cabal2nix.cabal view
@@ -1,5 +1,5 @@ Name: cabal2nix-Version: 1.9+Version: 1.10 Copyright: (c) 2011 Peter Simons and Andres Loeh License: BSD3 License-File: LICENSE@@ -10,7 +10,7 @@ Synopsis: Convert Cabal files into Nix build instructions Cabal-Version: >= 1.6 Build-Type: Simple-Tested-With: GHC == 7.0.4+Tested-With: GHC == 6.12.3, GHC == 7.0.4 Description: The cabal2nix utility converts Cabal files into Nix build instructions. The commandline syntax is:@@ -56,12 +56,13 @@ Executable hackage4nix main-is: Hackage4Nix.hs hs-source-dirs: src- Build-Depends: base >= 3 && < 5, Cabal, pretty, filepath, directory, bytestring,+ Build-Depends: base >= 3 && < 5, Cabal >= 1.8, pretty, filepath, directory, regex-posix, mtl, containers- Ghc-Options: -Wall+ Extensions: PatternGuards other-modules: Cabal2Nix.Pretty Cabal2Nix.License Cabal2Nix.Name Cabal2Nix.CorePackages Cabal2Nix.Package Cabal2Nix.Hackage+
src/Cabal2Nix.hs view
@@ -22,7 +22,7 @@ | "file://" `isPrefixOf` path = readCabalFile (drop 7 path) | otherwise = readFile path -data CliOption = PrintHelp | SHA256 String | Maintainer String | Platform String+data CliOption = PrintHelp | SHA256 String | Maintainer String | Platform String | NoHaddock deriving (Eq) main :: IO ()@@ -33,6 +33,7 @@ , Option [] ["sha256"] (ReqArg SHA256 "HASH") "sha256 hash of source tarball" , Option ['m'] ["maintainer"] (ReqArg Maintainer "MAINTAINER") "maintainer of this package (may be specified multiple times)" , Option ['p'] ["platform"] (ReqArg Platform "PLATFORM") "supported build platforms (may be specified multiple times)"+ , Option [] ["no-haddock"] (NoArg NoHaddock) "don't run Haddock when building this package" ] usage :: String@@ -58,6 +59,7 @@ let uri = args hash = [ h | SHA256 h <- opts ]+ noHaddock = NoHaddock `elem` opts maintainers = [ m | Maintainer m <- opts ] platforms' = [ p | Platform p <- opts ] platforms@@ -78,4 +80,4 @@ sha256 <- if null hash then hashPackage packageId else return (head hash) - putStr (showNixPkg (cabal2nix cabal sha256 platforms maintainers))+ putStr (showNixPkg (cabal2nix cabal sha256 noHaddock platforms maintainers))
src/Cabal2Nix/CorePackages.hs view
@@ -30,7 +30,7 @@ "old-time", "pretty", "process",- "random",+ -- "random", "template-haskell", -- "time", "unix"
src/Cabal2Nix/License.hs view
@@ -16,6 +16,6 @@ showLic BSD4 = "self.stdenv.lib.licenses.bsd4" showLic MIT = "self.stdenv.lib.licenses.mit" showLic PublicDomain = "self.stdenv.lib.licenses.publicDomain"-showLic AllRightsReserved = show "unknown"+showLic AllRightsReserved = "self.stdenv.lib.licenses.proprietary" showLic OtherLicense = show "unknown" showLic l = error $ "unknown license: " ++ show l
src/Cabal2Nix/Package.hs view
@@ -2,7 +2,7 @@ ( cabal2nix, showNixPkg , PkgName, PkgVersion, PkgSHA256, PkgURL, PkgDescription, PkgLicense , PkgIsLib, PkgIsExe, PkgDependencies, PkgBuildTools, PkgExtraLibs- , PkgPkgconfigDeps, PkgPlatforms, PkgMaintainers+ , PkgPkgconfigDeps, PkgPlatforms, PkgMaintainers, PkgNoHaddock, Pkg(..) ) where @@ -27,13 +27,14 @@ type PkgSHA256 = String type PkgURL = String type PkgDescription = String-type PkgLicense = License+type PkgLicense = String type PkgIsLib = Bool type PkgIsExe = Bool type PkgDependencies = [Dependency] -- [CondTree ConfVar [Dependency] ()] type PkgBuildTools = [Dependency] type PkgExtraLibs = [String] type PkgPkgconfigDeps = [String]+type PkgNoHaddock = Bool type PkgPlatforms = [String] type PkgMaintainers = [String] @@ -49,13 +50,14 @@ PkgBuildTools PkgExtraLibs PkgPkgconfigDeps+ PkgNoHaddock PkgPlatforms PkgMaintainers deriving (Show) showNixPkg :: Pkg -> String showNixPkg (Pkg name ver sha256 url desc lic isLib isExe deps- tools libs pcs platforms maintainers) =+ tools libs pcs noHaddock platforms maintainers) = render doc where doc = funargs (map text ("cabal" : pkgInputs)) $$@@ -73,12 +75,13 @@ listattr "buildTools" pkgBuildTools, listattr "extraLibraries" pkgLibs, listattr "pkgconfigDepends" pkgPCs,+ boolattr "noHaddock" noHaddock noHaddock, vcat [ text "meta" <+> equals <+> lbrace, nest 2 $ vcat [ onlyIf url $ attr "homepage" $ string url, onlyIf desc $ attr "description" $ string desc,- attr "license" $ text (showLic lic),+ attr "license" $ text lic, onlyIf platforms $ sep [ text "platforms" <+> equals,@@ -101,23 +104,24 @@ pkgInputs = nub $ pkgLibs ++ pkgPCs ++ pkgBuildTools ++ pkgDeps -cabal2nix :: GenericPackageDescription -> PkgSHA256 -> PkgPlatforms -> PkgMaintainers -> Pkg-cabal2nix cabal sha256 platforms maintainers =+cabal2nix :: GenericPackageDescription -> PkgSHA256 -> PkgNoHaddock -> PkgPlatforms -> PkgMaintainers -> Pkg+cabal2nix cabal sha256 noHaddock platforms maintainers = Pkg pkgname pkgver sha256 url desc lic isLib isExe (buildDepends tpkg) tools libs pcs+ noHaddock [ if '.' `elem` p then p else "self.stdenv.lib.platforms." ++ p | p <- platforms ] [ if '.' `elem` m then m else "self.stdenv.lib.maintainers." ++ m | m <- maintainers ] where pkg = packageDescription cabal PackageName pkgname = pkgName (package pkg) pkgver = showVersion (pkgVersion (package pkg))- lic = license pkg+ lic = showLic (license pkg) url = homepage pkg- desc = synopsis pkg+ desc = normalizeDescription (synopsis pkg) -- globalDeps = buildDepends pkg -- Potentially dangerous: determine a default flattening of the -- package description. Better approach: export the conditional@@ -136,3 +140,13 @@ unDep :: Dependency -> String unDep (Dependency (PackageName x) _) = x++normalizeDescription :: String -> String+normalizeDescription desc+ | null desc = []+ | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (reverse (tail (reverse desc)))+ | otherwise = unwords (words desc) >>= quote++quote :: Char -> [Char]+quote '"' = "\\\""+quote c = [c]
src/Hackage4Nix.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings, PatternGuards #-}+{-# LANGUAGE PatternGuards #-} module Main ( main ) where @@ -11,22 +11,13 @@ import qualified Data.Set as Set import Control.Monad.State import Control.Exception ( bracket )-import qualified Data.ByteString.Char8 as BS import Text.Regex.Posix import Data.Version import Text.ParserCombinators.ReadP ( readP_to_S ) import Distribution.PackageDescription.Parse ( parsePackageDescription, ParseResult(..) ) import Distribution.PackageDescription ( GenericPackageDescription() ) import System.Console.GetOpt ( OptDescr(..), ArgDescr(..), ArgOrder(..), usageInfo, getOpt )-import Cabal2Nix.Package ( cabal2nix, showNixPkg, PkgName, PkgSHA256, PkgPlatforms, PkgMaintainers )--type ByteString = BS.ByteString--pack :: String -> ByteString-pack = BS.pack--unpack :: ByteString -> String-unpack = BS.unpack+import Cabal2Nix.Package ( cabal2nix, showNixPkg, PkgName, PkgVersion, PkgSHA256, PkgPlatforms, PkgMaintainers, PkgNoHaddock ) type PkgSet = Set.Set Pkg @@ -71,61 +62,54 @@ discoverNixFiles :: (FilePath -> Hackage4Nix ()) -> FilePath -> Hackage4Nix () discoverNixFiles yield dirOrFile- | "." `isPrefixOf` takeFileName dirOrFile = msgDebug $ "ignore file or directory " ++ dirOrFile+ | "." `isPrefixOf` takeFileName dirOrFile = return () | otherwise = do isFile <- io (doesFileExist dirOrFile) case (isFile, takeExtension dirOrFile) of- (True,".nix") -> do- msgDebug ("discovered file " ++ dirOrFile)- yield dirOrFile- (True,_) -> msgDebug $ "ignore file " ++ dirOrFile- (False,_) -> do- msgDebug ("discovered dir " ++ dirOrFile)- io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>))+ (True,".nix") -> yield dirOrFile+ (True,_) -> return ()+ (False,_) -> io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>)) -type PkgVersion = String-data Pkg = Pkg PkgName PkgVersion PkgSHA256 PkgPlatforms PkgMaintainers FilePath+type Regenerate = Bool+data Pkg = Pkg PkgName PkgVersion PkgSHA256 PkgNoHaddock PkgPlatforms PkgMaintainers FilePath Regenerate deriving (Show, Eq, Ord) -regmatch :: ByteString -> String -> Bool-regmatch buf patt = match (makeRegexOpts compExtended execBlank (pack patt)) buf--regsubmatch :: ByteString -> String -> [ByteString]+regsubmatch :: String -> String -> [String] regsubmatch buf patt = let (_,_,_,x) = f in x- where f :: (ByteString,ByteString,ByteString,[ByteString])- f = match (makeRegexOpts compExtended execBlank (pack patt)) buf+ where f :: (String,String,String,[String])+ f = match (makeRegexOpts compExtended execBlank patt) buf normalizeMaintainer :: String -> String normalizeMaintainer x | "self.stdenv.lib.maintainers." `isPrefixOf` x = drop 28 x | otherwise = x -parseNixFile :: FilePath -> ByteString -> Hackage4Nix (Maybe Pkg)+parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg) parseNixFile path buf- | True <- (pack path) `regmatch` (concat (intersperse "|" badPackages))+ | not (buf =~ "cabal.mkDerivation")+ = msgDebug ("ignore non-cabal package " ++ path) >> return Nothing+ | any (`isSuffixOf`path) badPackagePaths = msgDebug ("ignore known bad package " ++ path) >> return Nothing- | True <- buf `regmatch` "src = (fetchgit|sourceFromHead)"+ | buf =~ "src = (fetchurl|fetchgit|sourceFromHead)" = msgDebug ("ignore non-hackage package " ++ path) >> return Nothing- | True <- buf `regmatch` "noHaddock"- = msgDebug ("ignore non-haddock package " ++ path) >> return Nothing- | True <- buf =~ pack "cabal.mkDerivation"- , [name] <- buf `regsubmatch` "name *= *\"([^\"]+)\""+ | [name] <- buf `regsubmatch` "name *= *\"([^\"]+)\"" , [vers] <- buf `regsubmatch` "version *= *\"([^\"]+)\"" , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\"" , plats <- buf `regsubmatch` "platforms *= *([^;]+);" , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"- = let plats' = concatMap BS.words (map (BS.map (\c -> if c == '+' then ' ' else c)) plats)- maint' = concatMap BS.words maint+ , haddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"+ = let plats' = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats)+ maint' = concatMap words maint+ noHaddock+ | "true":[] <- haddock = True+ | otherwise = False+ regenerate = not (name `elem` patchedPackages) &&+ not (buf =~ "preConfigure|configureFlags|postInstall|patchPhase") in- return $ Just $ Pkg (unpack name)- (unpack vers)- (unpack sha)- (map unpack plats')- (map (normalizeMaintainer . unpack) maint')- (path)- | True <- buf `regmatch` "cabal.mkDerivation"- = msgInfo ("failed to parse file " ++ path) >> return Nothing- | otherwise = return Nothing+ return $ Just $ Pkg name vers sha noHaddock plats'+ (map normalizeMaintainer maint')+ path regenerate+ | otherwise = msgInfo ("failed to parse file " ++ path) >> return Nothing readVersion :: String -> Version readVersion str =@@ -136,10 +120,10 @@ selectLatestVersions :: PkgSet -> PkgSet selectLatestVersions = Set.fromList . nubBy f2 . sortBy f1 . Set.toList where- f1 (Pkg n1 v1 _ _ _ _) (Pkg n2 v2 _ _ _ _)+ f1 (Pkg n1 v1 _ _ _ _ _ _) (Pkg n2 v2 _ _ _ _ _ _) | n1 == n2 = compare v2 v1 | otherwise = compare n1 n2- f2 (Pkg n1 _ _ _ _ _) (Pkg n2 _ _ _ _ _)+ f2 (Pkg n1 _ _ _ _ _ _ _) (Pkg n2 _ _ _ _ _ _ _) = n1 == n2 discoverUpdates :: PkgName -> PkgVersion -> Hackage4Nix [PkgVersion]@@ -147,53 +131,54 @@ hackage <- gets _hackageDb versionStrings <- io $ readDirectory (hackage </> name) let versions = map readVersion versionStrings- return [ showVersion v | v <- versions, v > readVersion vers ]+ return (sort [ showVersion v | v <- versions, v > readVersion vers ]) updateNixPkgs :: [FilePath] -> Hackage4Nix () updateNixPkgs paths = do msgDebug $ "updating = " ++ show paths flip mapM_ paths $ \fileOrDir -> flip discoverNixFiles fileOrDir $ \file -> do- nix' <- io (BS.readFile file) >>= parseNixFile file+ nix' <- io (readFile file) >>= parseNixFile file flip (maybe (return ())) nix' $ \nix -> do- let Pkg name vers sha plats maints path = nix- maints' = nub (sort (maints ++ ["andres","simons"]))- plats'- | null plats && not (null maints) = ["self.ghc.meta.platforms"]- | otherwise = plats- msgDebug ("re-generate " ++ path)- when (null maints) (msgInfo ("warning: no maintainers configured for " ++ path))- pkg <- readCabalFile name vers- io $ writeFile path (showNixPkg (cabal2nix pkg sha plats' maints'))+ let Pkg name vers sha noHaddock plats maints path regenerate = nix modify $ \cfg -> cfg { _pkgset = Set.insert nix (_pkgset cfg) }+ when regenerate $ do+ msgDebug ("re-generate " ++ path)+ let maints' = nub (sort (maints ++ ["andres","simons"]))+ plats'+ | null plats && not (null maints) = ["self.ghc.meta.platforms"]+ | otherwise = plats+ when (null maints) (msgInfo ("no maintainers configured for " ++ path))+ pkg <- readCabalFile name vers+ io $ writeFile path (showNixPkg (cabal2nix pkg sha noHaddock plats' maints')) pkgset <- gets (selectLatestVersions . _pkgset) updates' <- flip mapM (Set.elems pkgset) $ \pkg -> do- let Pkg name vers _ _ _ _ = pkg+ let Pkg name vers _ _ _ _ _ _ = pkg updates <- discoverUpdates name vers return (pkg,updates) let updates = [ u | u@(_,(_:_)) <- updates' ] when (not (null updates)) $ do msgInfo "The following updates are available:" flip mapM_ updates $ \(pkg,versions) -> do- let Pkg name vers _ plats maints path = pkg+ let Pkg name vers _ noHaddock plats maints path regenerate = pkg msgInfo "" msgInfo $ name ++ "-" ++ vers ++ ":" flip mapM_ versions $ \newVersion -> do- msgInfo $ " " ++ genCabal2NixCmdline (Pkg name newVersion undefined plats maints path)+ msgInfo $ " " ++ genCabal2NixCmdline (Pkg name newVersion undefined noHaddock plats maints path regenerate) return () genCabal2NixCmdline :: Pkg -> String-genCabal2NixCmdline (Pkg name vers _ plats maints path) = unwords $ ["cabal2nix"] ++ opts ++ [">"++path']+genCabal2NixCmdline (Pkg name vers _ noHaddock plats maints path _) = unwords $ ["cabal2nix"] ++ opts ++ [">"++path'] where- opts = [cabal] ++ maints' ++ plats'+ opts = [cabal] ++ maints' ++ plats' ++ if noHaddock then ["--no-haddock"] else [] cabal = "cabal://" ++ name ++ "-" ++ vers maints' = [ "--maintainer=" ++ m | m <- maints ] plats'- | ["self.ghc.meta.platforms"] == plats = []- | otherwise = [ "--platform=" ++ p | p <- plats ]+ | ["self.ghc.meta.platforms"] == plats = []+ | otherwise = [ "--platform=" ++ p | p <- plats ] path'- | pack path `regmatch` "/[0-9\\.]+\\.nix$" = replaceFileName path (vers <.> "nix")- | otherwise = path+ | path =~ "/[0-9\\.]+\\.nix$" = replaceFileName path (vers <.> "nix")+ | otherwise = path data CliOption = PrintHelp | Verbose | HackageDB FilePath deriving (Eq)@@ -242,53 +227,48 @@ flip evalStateT cfg (updateNixPkgs args) +-- Packages that we cannot parse. +badPackagePaths :: [FilePath]+badPackagePaths = ["haskell-platform/2011.2.0.1.nix"]+ -- Packages that we cannot regenerate automatically yet. This list -- should be empty. -badPackages :: [String]-badPackages = [ "/"++p++"/" | p <- names ]- where names =- [ "alex"- , "cairo"- , "citeproc"- , "citeproc-hs"- , "editline"- , "flapjax"- , "ghc-events"- , "glade"- , "glib"- , "glut"- , "GLUT"- , "gtk"- , "gtksourceview2"- , "haddock"- , "haskell-platform"- , "haskell-src"- , "hfuse"- , "hmatrix"- , "hp2any-graph"- , "idris"- , "LambdaHack"- , "lhs2tex"- , "MazesOfMonad"- , "OpenAL"- , "OpenGL"- , "pango"- , "readline"- , "repa-examples"- , "scion"- , "SDL"- , "SDL-image"- , "SDL-mixer"- , "SDL-ttf"- , "svgcairo"- , "tar"- , "terminfo"- , "threadscope"- , "vacuum"- , "wxHaskell"- , "X11"- , "X11-xft"- , "xmobar"- ]+patchedPackages :: [String]+patchedPackages =+ [ "alex" -- undeclared dependencies+ , "cairo" -- undeclared dependencies+ , "citeproc-hs" -- undeclared dependencies+ , "editline" -- undeclared dependencies+ , "glade" -- undeclared dependencies+ , "glib" -- undeclared dependencies+ , "epic" -- undeclared dependencies+ , "GLUT" -- undeclared dependencies+ , "gtk" -- undeclared dependencies+ , "gtksourceview2" -- undeclared dependencies+ , "haddock" -- undeclared dependencies+ , "haskell-src" -- undeclared dependencies+ , "hmatrix" -- undeclared dependencies+ , "hp2any-graph" -- undeclared dependencies+ , "lhs2tex" -- undeclared dependencies+ , "OpenAL" -- undeclared dependencies+ , "OpenGL" -- undeclared dependencies+ , "pango" -- undeclared dependencies+ , "idris" -- undeclared dependencies+ , "readline" -- undeclared dependencies+ , "repa-examples" -- undeclared dependencies+ , "scion" -- expects non-existent networkBytestring+ , "SDL" -- undeclared dependencies+ , "SDL-image" -- undeclared dependencies+ , "SDL-mixer" -- undeclared dependencies+ , "SDL-ttf" -- undeclared dependencies+ , "svgcairo" -- undeclared dependencies+ , "terminfo" -- undeclared dependencies+ , "xmonad" -- undeclared dependencies+ , "xmonad-extras" -- undeclared dependencies+ , "vacuum" -- undeclared dependencies+ , "wxcore" -- undeclared dependencies+ , "X11" -- undeclared dependencies+ , "X11-xft" -- undeclared dependencies+ ]