cabal2nix 1.67 → 1.68
raw patch · 11 files changed
+123/−67 lines, 11 files
Files
- cabal2nix.cabal +5/−3
- src/Cabal2Nix/Flags.hs +2/−4
- src/Cabal2Nix/Generate.hs +1/−0
- src/Cabal2Nix/Normalize.hs +11/−1
- src/Cabal2Nix/PostProcess.hs +5/−2
- src/Distribution/NixOS/Derivation/Cabal.hs +12/−13
- src/Distribution/NixOS/Derivation/Meta.hs +15/−11
- src/Distribution/NixOS/PrettyPrinting.hs +3/−3
- src/Distribution/NixOS/Regex.hs +25/−0
- src/hackage4nix.hs +43/−30
- test/doc-test.hs +1/−0
cabal2nix.cabal view
@@ -1,5 +1,5 @@ Name: cabal2nix-Version: 1.67+Version: 1.68 Copyright: Peter Simons, Andres Loeh License: BSD3 License-File: LICENSE@@ -37,8 +37,8 @@ . The only required argument is the path to the cabal file. For example: .- > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.67/cabal2nix.cabal- > cabal2nix cabal://cabal2nix-1.67+ > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.68/cabal2nix.cabal+ > cabal2nix cabal://cabal2nix-1.68 . If the @--sha256@ option has not been specified, cabal2nix calls @nix-prefetch-url@ to determine the hash automatically. This causes@@ -67,6 +67,7 @@ Distribution.NixOS.Derivation.License Distribution.NixOS.Derivation.Meta Distribution.NixOS.PrettyPrinting+ Distribution.NixOS.Regex Executable hackage4nix main-is: hackage4nix.hs@@ -86,6 +87,7 @@ Distribution.NixOS.Derivation.License Distribution.NixOS.Derivation.Meta Distribution.NixOS.PrettyPrinting+ Distribution.NixOS.Regex Test-Suite doctest-cabal2nix type: exitcode-stdio-1.0
src/Cabal2Nix/Flags.hs view
@@ -7,10 +7,8 @@ configureCabalFlags (PackageIdentifier (PackageName name) _) | name == "arithmoi" = [disable "llvm"] | name == "accelerate-examples"= [disable "opencl"]- | name == "git-annex" = [ enable "S3", enable "WebDAV", enable "Inotify"- , enable "Dbus", enable "Assistant", enable "Webapp"- , enable "Pairing", enable "XMPP", enable "DNS"- , enable "Production", enable "TDFA"]+ | name == "folds" = [disable "test-hlint"]+ | name == "git-annex" = [enable "Assistant" , enable "Production"] | name == "haskeline" = [enable "terminfo"] | name == "hslua" = [enable "system-lua"] | name == "idris" = [enable "llvm", enable "gmp", enable "ffi"]
src/Cabal2Nix/Generate.hs view
@@ -33,6 +33,7 @@ , doCheck = True , testTarget = "" , hyperlinkSource = True+ , enableSplitObjs = True , phaseOverrides = "" , metaSection = Meta { homepage = Cabal.homepage descr
src/Cabal2Nix/Normalize.hs view
@@ -8,6 +8,7 @@ import Data.List import Data.Char import Data.Function+import Distribution.NixOS.Regex ( regsubmatch ) normalize :: Derivation -> Derivation normalize deriv@(MkDerivation {..}) = deriv@@ -50,9 +51,18 @@ normalizeNixBuildTools :: [String] -> [String] normalizeNixBuildTools = normalizeList . concatMap buildToolNixName +-- |Strip the "self.ghc.meta.platforms" prefix from platform names, filter+-- duplicates, and sort the resulting list alphabetically.+--+-- >>> normalizeMaintainers ["self.stdenv.lib.maintainers.foobar", "foobar"]+-- ["foobar"]+--+-- >>> normalizeMaintainers ["any.prefix.is.recognized.yo", "abc.def"]+-- ["def","yo"]+ normalizeMaintainers :: [String] -> [String] normalizeMaintainers maints = normalizeList- [ if '.' `elem` m then m else "self.stdenv.lib.maintainers." ++ m | m <- maints ]+ [ (m `regsubmatch` "^([^.].*\\.)?([^.]+)$") !! 1 | m <- maints ] normalizePlatforms :: [String] -> [String] normalizePlatforms [] = ["self.ghc.meta.platforms"]
src/Cabal2Nix/PostProcess.hs view
@@ -19,6 +19,7 @@ | pname == "cabal-install" && version >= Version [0,14] [] = deriv { phaseOverrides = cabalInstallPostInstall } | pname == "cairo" = deriv { extraLibs = "pkgconfig":"libc":"cairo":"zlib":extraLibs }+ | pname == "cookie" = deriv { phaseOverrides = cookieDoCheckHook } | pname == "cuda" = deriv { phaseOverrides = cudaConfigurePhase, extraLibs = "cudatoolkit":"nvidia_x11":"self.stdenv.gcc":extraLibs } | pname == "darcs" = deriv { phaseOverrides = darcsInstallPostInstall } | pname == "dns" = deriv { testTarget = "spec" }@@ -46,12 +47,11 @@ | pname == "haskeline" = deriv { buildDepends = "utf8String":buildDepends } | pname == "haskell-src" = deriv { buildTools = "happy":buildTools } | pname == "haskell-src-meta" = deriv { buildDepends = "uniplate":buildDepends }- | pname == "hfsevents" = deriv { buildTools = "gccApple":buildTools, phaseOverrides = "configureFlags = \"--ghc-option=-pgmc=${gccApple}/bin/gcc\";" } | pname == "HFuse" = deriv { phaseOverrides = hfusePreConfigure } | pname == "highlighting-kate"= highlightingKatePostProcessing deriv | pname == "hlibgit2" = deriv { testDepends = "git":testDepends } | pname == "HList" = deriv { buildTools = "diffutils":buildTools }- | pname == "hmatrix" = deriv { extraLibs = "gsl":"liblapack":"blas":extraLibs }+ | pname == "hmatrix" = deriv { extraLibs = "liblapack":"blas": filter (/= "lapack") extraLibs } | pname == "hoogle" = deriv { testTarget = "--test-option=--no-net" } | pname == "hspec" = deriv { doCheck = False } | pname == "HTTP" && version >= Version [4000,2,14] []@@ -253,6 +253,9 @@ cabal2nixDoCheckHook :: String cabal2nixDoCheckHook = "doCheck = self.stdenv.lib.versionOlder \"7.6\" self.ghc.version;"++cookieDoCheckHook :: String+cookieDoCheckHook = "doCheck = self.stdenv.lib.versionOlder \"7.8\" self.ghc.version;" textIcuDoCheckHook :: String textIcuDoCheckHook = "doCheck = !self.stdenv.isDarwin;"
src/Distribution/NixOS/Derivation/Cabal.hs view
@@ -21,6 +21,7 @@ import Distribution.NixOS.Derivation.Meta import Distribution.NixOS.PrettyPrinting+import Distribution.NixOS.Regex hiding ( empty ) import Distribution.Text import Distribution.Package #ifdef __HADDOCK__@@ -31,7 +32,6 @@ import Data.List import Data.Char import Data.Function-import Text.Regex.Posix hiding ( empty ) -- | A represtation of Nix expressions for building Haskell packages. -- The data type correspond closely to the definition of@@ -59,6 +59,7 @@ , doCheck :: Bool , testTarget :: String , hyperlinkSource :: Bool+ , enableSplitObjs :: Bool , phaseOverrides :: String , metaSection :: Meta }@@ -84,12 +85,13 @@ , 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 "testDepends" (testDepends deriv)- , listattr "buildTools" (buildTools deriv)- , listattr "extraLibraries" (extraLibs deriv)- , listattr "pkgconfigDepends" (pkgConfDeps deriv)+ , listattr "buildDepends" empty (buildDepends deriv)+ , listattr "testDepends" empty (testDepends deriv)+ , listattr "buildTools" empty (buildTools deriv)+ , listattr "extraLibraries" empty (extraLibs deriv)+ , listattr "pkgconfigDepends" empty (pkgConfDeps deriv) , onlyIf renderedFlags $ attr "configureFlags" $ doubleQuotes (sep renderedFlags)+ , boolattr "enableSplitObjs" (not (enableSplitObjs deriv)) (enableSplitObjs deriv) , boolattr "noHaddock" (not (runHaddock deriv)) (not (runHaddock deriv)) , boolattr "jailbreak" (jailbreak deriv) (jailbreak deriv) , boolattr "doCheck" (not (doCheck deriv)) (doCheck deriv)@@ -120,11 +122,12 @@ , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\"" , hplats <- buf `regsubmatch` "hydraPlatforms *= *([^;]+);" , plats <- buf `regsubmatch` "platforms *= *([^;]+);"- , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"+ , maint <- buf `regsubmatch` "maintainers *= *(with [^;]+;)? \\[([^\"]+)]" , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;" , jailBreak <- buf `regsubmatch` "jailbreak *= *(true|false) *;" , docheck <- buf `regsubmatch` "doCheck *= *(true|false) *;" , hyperlSrc <- buf `regsubmatch` "hyperlinkSource *= *(true|false) *;"+ , splitObj <- buf `regsubmatch` "enableSplitObjs *= *(true|false) *;" = Just MkDerivation { pname = name , version = vers@@ -144,19 +147,15 @@ , doCheck = docheck == ["true"] || null docheck , testTarget = "" , hyperlinkSource = hyperlSrc == ["true"] || null hyperlSrc+ , enableSplitObjs = splitObj /= ["false"] , phaseOverrides = "" , metaSection = Meta { homepage = "" , description = "" , license = Unknown Nothing- , maintainers = concatMap words maint+ , maintainers = if null maint then [] else concatMap words (tail maint) , platforms = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats) , hydraPlatforms = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) hplats) } } | 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
src/Distribution/NixOS/Derivation/Meta.hs view
@@ -23,16 +23,20 @@ -- | 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 ];--- > };+-- >>> :{+-- putStrLn (display (Meta "http://example.org" "an example package" (Unknown Nothing)+-- ["stdenv.lib.platforms."++x | x <- ["unix","cygwin"]]+-- ["stdenv.lib.platforms.none"]+-- ["joe","jane"]))+-- :}+-- meta = {+-- homepage = "http://example.org";+-- description = "an example package";+-- license = "unknown";+-- platforms = stdenv.lib.platforms.unix ++ stdenv.lib.platforms.cygwin;+-- hydraPlatforms = stdenv.lib.platforms.none;+-- maintainers = with self.stdenv.lib.maintainers; [ joe jane ];+-- }; -- -- Note that the "Text" instance definition provides pretty-printing, -- but no parsing as of now!@@ -62,7 +66,7 @@ [ text "platforms" <+> equals, renderPlatformList (platforms meta) ] , onlyIf (hydraPlatforms meta) $ sep [ text "hydraPlatforms" <+> equals, renderPlatformList (hydraPlatforms meta) ]- , listattr "maintainers" (maintainers meta)+ , listattr "maintainers" (text "with self.stdenv.lib.maintainers;") (maintainers meta) ] , rbrace <> semi ]
src/Distribution/NixOS/PrettyPrinting.hs view
@@ -31,9 +31,9 @@ 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,+listattr :: String -> Doc -> [String] -> Doc+listattr n prefix vs = onlyIf vs $+ sep [ text n <+> equals <+> prefix <+> lbrack, nest 2 $ fsep $ map text vs, rbrack <> semi ]
+ src/Distribution/NixOS/Regex.hs view
@@ -0,0 +1,25 @@+{-# 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.Regex+ ( module Text.Regex.Posix+ , regsubmatch+ )+ where++import Text.Regex.Posix++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
src/hackage4nix.hs view
@@ -72,7 +72,7 @@ (False,_) -> io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>)) regenerateDerivation :: Derivation -> String -> Bool-regenerateDerivation _ buf = not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches")+regenerateDerivation _ buf = not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches|broken") parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg) parseNixFile path buf@@ -103,36 +103,50 @@ updateNixPkgs :: [FilePath] -> Hackage4Nix () updateNixPkgs paths = do- msgDebug $ "updating = " ++ show paths- forM_ paths $ \fileOrDir ->+ -- Traverse the given directorcy structure and discover all available+ -- Haskell packages.+ forM_ paths $ \fileOrDir -> do+ msgDebug $ "scanning " ++ show fileOrDir flip discoverNixFiles fileOrDir $ \file -> do nix' <- io (readFile file) >>= parseNixFile file- flip (maybe (return ())) nix' $ \nix -> do- let Pkg deriv path regenerate = nix- maints = maintainers (metaSection deriv)- plats = platforms (metaSection deriv)- hplats = hydraPlatforms (metaSection deriv)+ flip (maybe (return ())) nix' $ \nix -> modify (Set.insert nix)- when regenerate $ do- msgDebug ("re-generate " ++ path)- pkg <- getCabalPackage (pname deriv) (version deriv)- let deriv' = (cabal2nix pkg) { sha256 = sha256 deriv- , runHaddock = runHaddock deriv- , doCheck = doCheck deriv- , jailbreak = jailbreak deriv- , hyperlinkSource = hyperlinkSource deriv- }- meta = metaSection deriv'- plats' = if null plats then platforms meta else plats- deriv'' = deriv' { metaSection = meta- { maintainers = maints -- ++ ["andres","simons"]- , platforms = plats'- , hydraPlatforms = hplats- }- }- io $ writeFile path (show (disp (normalize deriv'')))- pkgset <- gets selectLatestVersions- updates' <- forM (Set.elems pkgset) $ \pkg -> do+ -- Re-generate all Haskell packages in-place (unless+ -- 'regenerateDerivation' decided that this particular package+ -- shouldn't be touched.+ latestVersions <- gets selectLatestVersions+ let latestVersionMap :: [(String,Version)]+ latestVersionMap = [ (pname deriv, version deriv) | Pkg deriv _ _ <- Set.toList latestVersions ]+ let isLatest :: Derivation -> Bool+ isLatest deriv = maybe False (version deriv ==) (lookup (pname deriv) latestVersionMap)+ get >>= \pkgset -> forM_ (Set.toList pkgset) $ \nix -> do+ let Pkg deriv path regenerate = nix+ maints = maintainers (metaSection deriv)+ plats = platforms (metaSection deriv)+ hplats = if isLatest deriv then hydraPlatforms (metaSection deriv) else ["self.stdenv.lib.platforms.none"]+ when regenerate $ do+ msgDebug ("re-generate " ++ path)+ pkg <- getCabalPackage (pname deriv) (version deriv)+ let deriv' = (cabal2nix pkg) { sha256 = sha256 deriv+ , runHaddock = runHaddock deriv+ , doCheck = doCheck deriv+ , jailbreak = jailbreak deriv+ , hyperlinkSource = hyperlinkSource deriv+ , enableSplitObjs = enableSplitObjs deriv+ }+ meta = metaSection deriv'+ plats' = if null plats then platforms meta else plats+ deriv'' = deriv' { metaSection = meta+ { maintainers = maints+ , platforms = plats'+ , hydraPlatforms = hplats+ }+ }+ io $ writeFile path (show (disp (normalize deriv'')))+ -- Discover available updates and print the appropriate cabal2nix+ -- command line to the console for the user to execute at his/her+ -- discretion.+ updates' <- forM (Set.elems latestVersions) $ \pkg -> do let Pkg deriv _ _ = pkg updates <- discoverUpdates (pname deriv) (version deriv) return (pkg,updates)@@ -233,8 +247,7 @@ -- Requires platform-specific magic that I don't want to add to cabal2nix. , "pkgs/development/libraries/haskell/fsnotify/default.nix" -- Not registered on Hackage.- , "pkgs/development/compilers/agda/stdlib-0.7.nix"- , "pkgs/development/compilers/agda/stdlib-0.8.nix"+ , "pkgs/development/compilers/agda/stdlib.nix" , "pkgs/development/compilers/cryptol/1.8.x.nix" , "pkgs/development/compilers/cryptol/2.0.x.nix" , "pkgs/development/compilers/jhc/default.nix"
test/doc-test.hs view
@@ -28,6 +28,7 @@ , "src/Distribution/NixOS/Derivation/Cabal.hs" , "src/Distribution/NixOS/Derivation/Meta.hs" , "src/Distribution/NixOS/PrettyPrinting.hs"+ , "src/Distribution/NixOS/Regex.hs" ] doctest $ "src/cabal2nix.hs" : libs doctest $ "src/hackage4nix.hs" : libs