git.iko.soy/typeable/cabal2nix
on master help sign in
Pretty-print the meta.maintainer section as

maintainers = with self.stdenv.lib.maintainers; [ foo ]; to make maintainer lists with multiple entries less verbose.

commita2ffb9b5ef4e50d5ae49c6f0743823f4ddfc68a7 authorPeter Simons <simons@cryp.to> dateSat 9 Aug 2014, 13:44 (12 years ago) parente82ffbf
7 files changed+65−28
cabal2nix.cabal+2 src/Cabal2Nix/Normalize.hs+11−1 src/Distribution/NixOS/Derivation/Cabal.hs+8−13 src/Distribution/NixOS/Derivation/Meta.hs+15−11 src/Distribution/NixOS/PrettyPrinting.hs+3−3 src/Distribution/NixOS/Regex.hs+25 test/doc-test.hs+1
cabal2nix.cabal+2
@@ -67,6 +67,7 @@ Executable cabal2nix
6767 Distribution.NixOS.Derivation.License
6868 Distribution.NixOS.Derivation.Meta
6969 Distribution.NixOS.PrettyPrinting
70+ Distribution.NixOS.Regex
7071
7172Executable hackage4nix
7273 main-is: hackage4nix.hs
@@ -86,6 +87,7 @@ Executable hackage4nix
8687 Distribution.NixOS.Derivation.License
8788 Distribution.NixOS.Derivation.Meta
8889 Distribution.NixOS.PrettyPrinting
90+ Distribution.NixOS.Regex
8991
9092Test-Suite doctest-cabal2nix
9193 type: exitcode-stdio-1.0
src/Cabal2Nix/Normalize.hs+11−1
@@ -8,6 +8,7 @@ import Cabal2Nix.CorePackages
88import Data.List
99import Data.Char
1010import Data.Function
11+import Distribution.NixOS.Regex ( regsubmatch )
1112
1213normalize :: Derivation -> Derivation
1314normalize deriv@(MkDerivation {..}) = deriv
@@ -50,9 +51,18 @@ normalizeNixLibs = normalizeList . concatMap libNixName
5051normalizeNixBuildTools :: [String] -> [String]
5152normalizeNixBuildTools = normalizeList . concatMap buildToolNixName
5253
54+-- |Strip the "self.ghc.meta.platforms" prefix from platform names, filter
55+-- duplicates, and sort the resulting list alphabetically.
56+--
57+-- >>> normalizeMaintainers ["self.stdenv.lib.maintainers.foobar", "foobar"]
58+-- ["foobar"]
59+--
60+-- >>> normalizeMaintainers ["any.prefix.is.recognized.yo", "abc.def"]
61+-- ["def","yo"]
62+
5363normalizeMaintainers :: [String] -> [String]
5464normalizeMaintainers maints = normalizeList
55− [ if '.' `elem` m then m else "self.stdenv.lib.maintainers." ++ m | m <- maints ]
65+ [ (m `regsubmatch` "^([^.].*\\.)?([^.]+)$") !! 1 | m <- maints ]
5666
5767normalizePlatforms :: [String] -> [String]
5868normalizePlatforms [] = ["self.ghc.meta.platforms"]
src/Distribution/NixOS/Derivation/Cabal.hs+8−13
@@ -21,6 +21,7 @@ module Distribution.NixOS.Derivation.Cabal
2121
2222import Distribution.NixOS.Derivation.Meta
2323import Distribution.NixOS.PrettyPrinting
24+import Distribution.NixOS.Regex hiding ( empty )
2425import Distribution.Text
2526import Distribution.Package
2627#ifdef __HADDOCK__
@@ -31,7 +32,6 @@ import Data.Version
3132import Data.List
3233import Data.Char
3334import Data.Function
34−import Text.Regex.Posix hiding ( empty )
3535
3636-- | A represtation of Nix expressions for building Haskell packages.
3737-- The data type correspond closely to the definition of
@@ -84,11 +84,11 @@ renderDerivation deriv =
8484 , attr "sha256" $ string (sha256 deriv)
8585 , boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
8686 , boolattr "isExecutable" (not (isLibrary deriv) || isExecutable deriv) (isExecutable deriv)
87− , listattr "buildDepends" (buildDepends deriv)
88− , listattr "testDepends" (testDepends deriv)
89− , listattr "buildTools" (buildTools deriv)
90− , listattr "extraLibraries" (extraLibs deriv)
91− , listattr "pkgconfigDepends" (pkgConfDeps deriv)
87+ , listattr "buildDepends" empty (buildDepends deriv)
88+ , listattr "testDepends" empty (testDepends deriv)
89+ , listattr "buildTools" empty (buildTools deriv)
90+ , listattr "extraLibraries" empty (extraLibs deriv)
91+ , listattr "pkgconfigDepends" empty (pkgConfDeps deriv)
9292 , onlyIf renderedFlags $ attr "configureFlags" $ doubleQuotes (sep renderedFlags)
9393 , boolattr "noHaddock" (not (runHaddock deriv)) (not (runHaddock deriv))
9494 , boolattr "jailbreak" (jailbreak deriv) (jailbreak deriv)
@@ -120,7 +120,7 @@ parseDerivation buf
120120 , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
121121 , hplats <- buf `regsubmatch` "hydraPlatforms *= *([^;]+);"
122122 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
123− , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
123+ , maint <- buf `regsubmatch` "maintainers *= *(with [^;]+;)? \\[([^\"]+)]"
124124 , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
125125 , jailBreak <- buf `regsubmatch` "jailbreak *= *(true|false) *;"
126126 , docheck <- buf `regsubmatch` "doCheck *= *(true|false) *;"
@@ -149,14 +149,9 @@ parseDerivation buf
149149 { homepage = ""
150150 , description = ""
151151 , license = Unknown Nothing
152− , maintainers = concatMap words maint
152+ , maintainers = if null maint then [] else concatMap words (tail maint)
153153 , platforms = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats)
154154 , hydraPlatforms = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) hplats)
155155 }
156156 }
157157 | otherwise = Nothing
158−
159−regsubmatch :: String -> String -> [String]
160−regsubmatch buf patt = let (_,_,_,x) = f in x
161− where f :: (String,String,String,[String])
162− f = match (makeRegexOpts compExtended execBlank patt) buf
src/Distribution/NixOS/Derivation/Meta.hs+15−11
@@ -23,16 +23,20 @@ import Distribution.Text
2323
2424-- | A representation of the @meta@ section used in Nix expressions.
2525--
26−-- > > putStrLn (display (Meta "http://example.org" "an example package" (Unknown Nothing)
27−-- > > ["stdenv.lib.platforms."++x | x<-["unix","cygwin"]]
28−-- > > ["stdenv.lib.maintainers."++x | x<-["joe","jane"]]))
29−-- > meta = {
30−-- > homepage = "http://example.org";
31−-- > description = "an example package";
32−-- > license = "unknown";
33−-- > platforms = stdenv.lib.platforms.unix ++ stdenv.lib.platforms.cygwin;
34−-- > maintainers = [ stdenv.lib.maintainers.joe stdenv.lib.maintainers.jane ];
35−-- > };
26+-- >>> :{
27+-- putStrLn (display (Meta "http://example.org" "an example package" (Unknown Nothing)
28+-- ["stdenv.lib.platforms."++x | x <- ["unix","cygwin"]]
29+-- ["stdenv.lib.platforms.none"]
30+-- ["joe","jane"]))
31+-- :}
32+-- meta = {
33+-- homepage = "http://example.org";
34+-- description = "an example package";
35+-- license = "unknown";
36+-- platforms = stdenv.lib.platforms.unix ++ stdenv.lib.platforms.cygwin;
37+-- hydraPlatforms = stdenv.lib.platforms.none;
38+-- maintainers = with self.stdenv.lib.maintainers; [ joe jane ];
39+-- };
3640--
3741-- Note that the "Text" instance definition provides pretty-printing,
3842-- but no parsing as of now!
@@ -62,7 +66,7 @@ renderMeta meta = vcat
6266 [ text "platforms" <+> equals, renderPlatformList (platforms meta) ]
6367 , onlyIf (hydraPlatforms meta) $ sep
6468 [ text "hydraPlatforms" <+> equals, renderPlatformList (hydraPlatforms meta) ]
65− , listattr "maintainers" (maintainers meta)
69+ , listattr "maintainers" (text "with self.stdenv.lib.maintainers;") (maintainers meta)
6670 ]
6771 , rbrace <> semi
6872 ]
src/Distribution/NixOS/PrettyPrinting.hs+3−3
@@ -31,9 +31,9 @@ onlyIf p d = if not (null p) then d else empty
3131boolattr :: String -> Bool -> Bool -> Doc
3232boolattr n p v = if p then attr n (bool v) else empty
3333
34−listattr :: String -> [String] -> Doc
35−listattr n vs = onlyIf vs $
36− sep [ text n <+> equals <+> lbrack,
34+listattr :: String -> Doc -> [String] -> Doc
35+listattr n prefix vs = onlyIf vs $
36+ sep [ text n <+> equals <+> prefix <+> lbrack,
3737 nest 2 $ fsep $ map text vs,
3838 rbrack <> semi
3939 ]
src/Distribution/NixOS/Regex.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# LANGUAGE PatternGuards, CPP #-}
2+{- |
3+ Module : Distribution.NixOS.Derivation.Cabal
4+ License : BSD3
5+
6+ Maintainer : nix-dev@cs.uu.nl
7+ Stability : provisional
8+ Portability : PatternGuards
9+
10+ A represtation of Nix expressions based on Cabal builder defined in
11+ @pkgs\/development\/libraries\/haskell\/cabal\/cabal.nix@.
12+-}
13+
14+module Distribution.NixOS.Regex
15+ ( module Text.Regex.Posix
16+ , regsubmatch
17+ )
18+ where
19+
20+import Text.Regex.Posix
21+
22+regsubmatch :: String -> String -> [String]
23+regsubmatch buf patt = let (_,_,_,x) = f in x
24+ where f :: (String,String,String,[String])
25+ f = match (makeRegexOpts compExtended execBlank patt) buf
test/doc-test.hs+1
@@ -28,6 +28,7 @@ main = do
2828 , "src/Distribution/NixOS/Derivation/Cabal.hs"
2929 , "src/Distribution/NixOS/Derivation/Meta.hs"
3030 , "src/Distribution/NixOS/PrettyPrinting.hs"
31+ , "src/Distribution/NixOS/Regex.hs"
3132 ]
3233 doctest $ "src/cabal2nix.hs" : libs
3334 doctest $ "src/hackage4nix.hs" : libs