cabal2nix 1.29 → 1.30
raw patch · 10 files changed
+51/−35 lines, 10 files
Files
- cabal2nix.cabal +3/−3
- src/Cabal2Nix.hs +1/−2
- src/Cabal2Nix/Generate.hs +2/−1
- src/Cabal2Nix/Hackage.hs +6/−6
- src/Cabal2Nix/Normalize.hs +5/−4
- src/Cabal2Nix/PostProcess.hs +14/−1
- src/Distribution/NixOS/Derivation/Cabal.hs +8/−4
- src/Distribution/NixOS/Derivation/Meta.hs +1/−1
- src/Distribution/NixOS/PrettyPrinting.hs +1/−2
- src/Hackage4Nix.hs +10/−11
cabal2nix.cabal view
@@ -1,5 +1,5 @@ Name: cabal2nix-Version: 1.29+Version: 1.30 Copyright: Peter Simons, Andres Loeh License: BSD3 License-File: LICENSE@@ -31,8 +31,8 @@ . The only required argument is the path to the cabal file. For example: .- > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.29/cabal2nix.cabal- > cabal2nix cabal://cabal2nix-1.29+ > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.30/cabal2nix.cabal+ > cabal2nix cabal://cabal2nix-1.30 . If the @--sha256@ option has not been specified, cabal2nix calls @nix-prefetch-url@ to determine the hash automatically. This causes
src/Cabal2Nix.hs view
@@ -4,7 +4,6 @@ import Cabal2Nix.Generate ( cabal2nix ) import Cabal2Nix.Normalize ( normalize ) import Distribution.NixOS.Derivation.Cabal-import Distribution.NixOS.Derivation.Meta import Control.Exception ( bracket ) import Control.Monad ( when )@@ -87,4 +86,4 @@ } } - putStr (show (disp (normalize (deriv'))))+ putStr (show (disp (normalize deriv')))
src/Cabal2Nix/Generate.hs view
@@ -14,7 +14,7 @@ import Distribution.NixOS.Derivation.Cabal cabal2nix :: Cabal.GenericPackageDescription -> Derivation-cabal2nix cabal = normalize $ postProcess $ MkDerivation+cabal2nix cabal = normalize $ postProcess MkDerivation { pname = let Cabal.PackageName x = Cabal.pkgName pkg in x , version = Cabal.pkgVersion pkg , sha256 = "cabal2nix left the she256 field undefined"@@ -27,6 +27,7 @@ , configureFlags = [] , cabalFlags = configureCabalFlags pkg , runHaddock = True+ , postInstall = "" , metaSection = Meta { homepage = Cabal.homepage descr , description = Cabal.synopsis descr
src/Cabal2Nix/Hackage.hs view
@@ -1,6 +1,6 @@ module Cabal2Nix.Hackage ( hashPackage, readCabalFile ) where -import Control.Monad ( when )+import Control.Monad ( unless ) import Data.List ( isPrefixOf ) import Data.Version ( showVersion ) import Distribution.Package ( PackageIdentifier(..), PackageName(..) )@@ -21,7 +21,7 @@ hackagePath (PackageIdentifier (PackageName name) version') ext = "http://hackage.haskell.org/packages/archive/" ++ name ++ "/" ++ version ++ "/" ++ name ++- (if ext == TarGz then "-" ++ version else "") +++ (if ext == TarGz then '-' : version else "") ++ showExt ext where version = showVersion version'@@ -30,11 +30,11 @@ hashPackage pkg = do cachePath <- hashCachePath pkg exists <- doesFileExist cachePath- hash' <- case exists of- True -> readFile cachePath- False -> readProcess "bash" ["-c", "exec nix-prefetch-url 2>/dev/tty " ++ hackagePath pkg TarGz] ""+ hash' <- if exists+ then readFile cachePath+ else readProcess "bash" ["-c", "exec nix-prefetch-url 2>/dev/tty " ++ hackagePath pkg TarGz] "" let hash = reverse (dropWhile (=='\n') (reverse hash'))- when (not exists) $ do+ unless exists $ do createDirectoryIfMissing True (dropFileName cachePath) writeFile cachePath hash return hash
src/Cabal2Nix/Normalize.hs view
@@ -7,11 +7,12 @@ import Cabal2Nix.CorePackages import Data.List import Data.Char+import Data.Function normalize :: Derivation -> Derivation normalize deriv@(MkDerivation {..}) = deriv- { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) $ buildDepends)- , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) $ buildTools)+ { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) buildDepends)+ , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) buildTools) , extraLibs = normalizeNixLibs extraLibs , pkgConfDeps = normalizeNixLibs pkgConfDeps , metaSection = normalizeMeta metaSection@@ -27,7 +28,7 @@ normalizeDescription :: String -> String normalizeDescription desc | null desc = []- | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (reverse (tail (reverse desc)))+ | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (init desc) | otherwise = quote (unwords (words desc)) quote :: String -> String@@ -37,7 +38,7 @@ quote [] = [] normalizeList :: [String] -> [String]-normalizeList = nub . sortBy (\x y -> compare (map toLower x) (map toLower y))+normalizeList = nub . sortBy (compare `on` map toLower) normalizeNixNames :: [String] -> [String] normalizeNixNames = normalizeList . map toNixName
src/Cabal2Nix/PostProcess.hs view
@@ -11,7 +11,8 @@ | pname == "cairo" = deriv { extraLibs = "pkgconfig":"libc":"cairo":"zlib":extraLibs } | pname == "editline" = deriv { extraLibs = "libedit":extraLibs } | pname == "epic" = deriv { extraLibs = "gmp":"boehmgc":extraLibs, buildTools = "happy":buildTools }- | pname == "glade" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, pkgConfDeps = "gtkC":(delete "gtk" pkgConfDeps) }+ | pname == "ghc-mod" = deriv { postInstall = ghcModPostInstall, buildTools = "emacs":buildTools }+ | pname == "glade" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, pkgConfDeps = "gtkC":delete "gtk" pkgConfDeps } | pname == "glib" = deriv { extraLibs = "pkgconfig":"libc":extraLibs } | pname == "GLUT" = deriv { extraLibs = "glut":"libSM":"libICE":"libXmu":"libXi":"mesa":extraLibs } | pname == "gtk" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, buildDepends = delete "gio" buildDepends }@@ -42,3 +43,15 @@ , configureFlags = "--extra-include-dirs=${freetype}/include/freetype2":configureFlags } | otherwise = deriv++ghcModPostInstall :: String+ghcModPostInstall = unlines+ [ "postInstall = ''"+ , " cd $out/share/$pname-$version"+ , " make"+ , " rm Makefile"+ , " cd .."+ , " ensureDir \"$out/share/emacs\""+ , " mv $pname-$version emacs/site-lisp"+ , " '';"+ ]
src/Distribution/NixOS/Derivation/Cabal.hs view
@@ -30,6 +30,7 @@ import Data.Version import Data.List import Data.Char+import Data.Function import Text.Regex.Posix hiding ( empty ) -- | A represtation of Nix expressions for building Haskell packages.@@ -52,6 +53,7 @@ , configureFlags :: [String] , cabalFlags :: FlagAssignment , runHaddock :: Bool+ , postInstall :: String , metaSection :: Meta } deriving (Show, Eq, Ord)@@ -71,21 +73,22 @@ [ 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)+ , 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) , onlyIf renderedFlags $ attr "configureFlags" $ doubleQuotes (sep renderedFlags) , boolattr "noHaddock" (not (runHaddock deriv)) (not (runHaddock deriv))+ , onlyIf (postInstall deriv) $ text (postInstall deriv) , disp (metaSection deriv) ] , rbrace <> rparen , text "" ] where- inputs = nub $ sortBy (\x y -> compare (map toLower x) (map toLower y)) $ filter (/="cabal") $+ inputs = nub $ sortBy (compare `on` map toLower) $ filter (/="cabal") $ buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ] ++ map text (configureFlags deriv)@@ -104,7 +107,7 @@ , plats <- buf `regsubmatch` "platforms *= *([^;]+);" , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]" , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"- = Just $ MkDerivation+ = Just MkDerivation { pname = name , version = vers , sha256 = sha@@ -118,6 +121,7 @@ , cabalFlags = [] , runHaddock = case noHaddock of "true":[] -> False _ -> True+ , postInstall = "" , metaSection = Meta { homepage = "" , description = ""
src/Distribution/NixOS/Derivation/Meta.hs view
@@ -60,7 +60,7 @@ , attr "license" $ disp (license meta) , onlyIf (platforms meta) $ sep [ text "platforms" <+> equals- , nest 2 ((fsep $ punctuate (text " ++") $ map text (platforms meta))) <> semi+ , nest 2 (fsep $ punctuate (text " ++") $ map text (platforms meta)) <> semi ] , listattr "maintainers" (maintainers meta) ]
src/Distribution/NixOS/PrettyPrinting.hs view
@@ -51,7 +51,6 @@ funargs :: [Doc] -> Doc funargs xs = sep [- lbrace <+> (fcat $ prepunctuate (comma <> text " ") $- map (nest 2) xs),+ lbrace <+> fcat (prepunctuate (comma <> text " ") $ map (nest 2) xs), rbrace <> colon ]
src/Hackage4Nix.hs view
@@ -10,7 +10,6 @@ import Data.Version import qualified Distribution.Hackage.DB as DB import Distribution.NixOS.Derivation.Cabal-import Distribution.NixOS.Derivation.Meta import Distribution.Package import Distribution.PackageDescription ( GenericPackageDescription() ) import Distribution.Text@@ -72,7 +71,7 @@ (False,_) -> io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>)) regenerateDerivation :: Derivation -> String -> Bool-regenerateDerivation deriv buf = not (pname deriv `elem` patchedPackages) &&+regenerateDerivation deriv buf = (pname deriv `notElem` patchedPackages) && not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches") parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg)@@ -104,7 +103,7 @@ updateNixPkgs :: [FilePath] -> Hackage4Nix () updateNixPkgs paths = do msgDebug $ "updating = " ++ show paths- flip mapM_ paths $ \fileOrDir ->+ forM_ paths $ \fileOrDir -> flip discoverNixFiles fileOrDir $ \file -> do nix' <- io (readFile file) >>= parseNixFile file flip (maybe (return ())) nix' $ \nix -> do@@ -123,26 +122,26 @@ , platforms = plats' } }- io $ writeFile path (show (disp (normalize (deriv''))))+ io $ writeFile path (show (disp (normalize deriv''))) pkgset <- gets selectLatestVersions- updates' <- flip mapM (Set.elems pkgset) $ \pkg -> do+ updates' <- forM (Set.elems pkgset) $ \pkg -> do let Pkg deriv _ _ = pkg updates <- discoverUpdates (pname deriv) (version deriv) return (pkg,updates)- let updates = [ u | u@(_,(_:_)) <- updates' ]- when (not (null updates)) $ do+ let updates = [ u | u@(_,_:_) <- updates' ]+ unless (null updates) $ do msgInfo "The following updates are available:"- flip mapM_ updates $ \(pkg,versions) -> do+ forM_ updates $ \(pkg,versions) -> do let Pkg deriv path regenerate = pkg msgInfo ""- msgInfo $ (display (packageId deriv)) ++ ":"- flip mapM_ versions $ \newVersion -> do+ msgInfo $ display (packageId deriv) ++ ":"+ forM_ versions $ \newVersion -> do let deriv' = deriv { version = newVersion } msgInfo $ " " ++ genCabal2NixCmdline (Pkg deriv' path regenerate) return () genCabal2NixCmdline :: Pkg -> String-genCabal2NixCmdline (Pkg deriv path _) = unwords $ ["cabal2nix"] ++ opts ++ [">"++path']+genCabal2NixCmdline (Pkg deriv path _) = unwords $ ["cabal2nix"] ++ opts ++ ['>':path'] where meta = metaSection deriv opts = [cabal] ++ maints' ++ plats' ++ if runHaddock deriv then [] else ["--no-haddock"]