git.iko.soy/typeable/cabal2nix
on master help sign in
Distribution.NixOS.Derivation: added Haddock documentation
708f83ePeter Simons
src/Distribution/NixOS/Derivation/Cabal.hs+20−4
@@ -1,19 +1,21 @@
1−{-# LANGUAGE PatternGuards #-}
1+{-# LANGUAGE PatternGuards, CPP #-}
2{- |
2{- |
3 Module : Distribution.NixOS.Derivation.Cabal
3 Module : Distribution.NixOS.Derivation.Cabal
4− Copyright : Peter Simons, Andres Loeh
5 License : BSD3
4 License : BSD3
6
5
7 Maintainer : nix-dev@cs.uu.nl
6 Maintainer : nix-dev@cs.uu.nl
8 Stability : provisional
7 Stability : provisional
9− Portability : portable
8+ Portability : PatternGuards
9+
10+ A represtation of Nix expressions based on Cabal builder defined in
11+ @pkgs\/development\/libraries\/haskell\/cabal\/cabal.nix@.
10-}
12-}
11
13
12module Distribution.NixOS.Derivation.Cabal
14module Distribution.NixOS.Derivation.Cabal
13 ( Derivation(..)
15 ( Derivation(..)
14 , parseDerivation
16 , parseDerivation
15 , module Distribution.NixOS.Derivation.Meta
17 , module Distribution.NixOS.Derivation.Meta
16− , Version(..)
18+ , module Data.Version
17 )
19 )
18 where
20 where
19
21
@@ -21,11 +23,21 @@ import Distribution.NixOS.Derivation.Meta
21import Distribution.NixOS.PrettyPrinting
23import Distribution.NixOS.PrettyPrinting
22import Distribution.Text
24import Distribution.Text
23import Distribution.Package
25import Distribution.Package
26+#ifdef __HADDOCK__
27+import Distribution.PackageDescription ( PackageDescription )
28+#endif
24import Data.Version
29import Data.Version
25import Data.List
30import Data.List
26import Data.Char
31import Data.Char
27import Text.Regex.Posix
32import Text.Regex.Posix
28
33
34+-- | A represtation of Nix expressions for building Haskell packages.
35+-- The data type correspond closely to the definition of
36+-- 'PackageDescription' from Cabal.
37+--
38+-- Note that the "Text" instance definition provides pretty-printing,
39+-- but no parsing as of now!
40+
29data Derivation = MkDerivation
41data Derivation = MkDerivation
30 { pname :: String
42 { pname :: String
31 , version :: Version
43 , version :: Version
@@ -73,6 +85,10 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
73 filter (/="cabal") $ filter (/="Cabal") $
85 filter (/="cabal") $ filter (/="Cabal") $
74 buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
86 buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
75
87
88+-- | A very incomplete parser that extracts 'pname', 'version',
89+-- 'sha256', 'platforms', 'maintainers', and 'runHaddock' from the given
90+-- Nix expression.
91+
76parseDerivation :: String -> Maybe Derivation
92parseDerivation :: String -> Maybe Derivation
77parseDerivation buf
93parseDerivation buf
78 | buf =~ "cabal.mkDerivation"
94 | buf =~ "cabal.mkDerivation"
src/Distribution/NixOS/Derivation/License.hs+31−3
@@ -1,19 +1,47 @@
1{- |
1{- |
2 Module : Distribution.NixOS.Derivation.License
2 Module : Distribution.NixOS.Derivation.License
3− Copyright : Peter Simons, Andres Loeh
4 License : BSD3
3 License : BSD3
5
4
6 Maintainer : nix-dev@cs.uu.nl
5 Maintainer : nix-dev@cs.uu.nl
7 Stability : provisional
6 Stability : provisional
8 Portability : portable
7 Portability : portable
8+
9+ Known licenses in Nix expressions are represented using the
10+ attributes defined in @pkgs\/lib\/licenses.nix@, and unknown licenses
11+ are represented as a literal string.
9−-}
12+ -}
10
13
11module Distribution.NixOS.Derivation.License ( License(..) ) where
14module Distribution.NixOS.Derivation.License ( License(..) ) where
12
15
13import Distribution.NixOS.PrettyPrinting
16import Distribution.NixOS.PrettyPrinting
14import Distribution.Text
17import Distribution.Text
15
18
19+-- | The representation for licenses used in Nix derivations. Known
20+-- licenses are Nix expressions -- such as @stdenv.lib.licenses.bsd3@
21+-- --, so their exact \"name\" is not generally known, because the path
22+-- to @stdenv@ depends on the context defined in the expression. In
23+-- Cabal expressions, for example, the BSD3 license would have to be
24+-- referred to as @self.stdenv.lib.licenses.bsd3@. Other expressions,
25+-- however, use different paths to the @licenses@ record.. Because of
26+-- this station, this library cannot provide an abstract data type that
27+-- encompasses all known licenses. Instead, the @License@ type just
28+-- distinguishes references to known and unknown licenses. The
29+-- difference between the two is in the way they are pretty-printed:
30+--
31+-- > > putStrLn (display (Known "stdenv.lib.license.gpl2"))
32+-- > stdenv.lib.license.gpl2
33+-- >
34+-- > > putStrLn (display (Unknown (Just "GPL")))
35+-- > "GPL"
36+-- >
37+-- > > putStrLn (display (Unknown Nothing))
38+-- > "unknown"
39+--
40+-- Note that the "Text" instance definition provides pretty-printing,
41+-- but no parsing as of now!
42+
16−data License = Known String | Unknown (Maybe String)
43+data License = Known String
44+ | Unknown (Maybe String)
17 deriving (Show, Eq, Ord)
45 deriving (Show, Eq, Ord)
18
46
19instance Text License where
47instance Text License where
src/Distribution/NixOS/Derivation/Meta.hs+27−7
@@ -1,12 +1,15 @@
1{- |
1{- |
2 Module : Distribution.NixOS.Derivation.Meta
2 Module : Distribution.NixOS.Derivation.Meta
3− Copyright : Peter Simons, Andres Loeh
4 License : BSD3
3 License : BSD3
5
4
6 Maintainer : nix-dev@cs.uu.nl
5 Maintainer : nix-dev@cs.uu.nl
7 Stability : provisional
6 Stability : provisional
8 Portability : portable
7 Portability : portable
8+
9+ A representation of the @meta@ section used in Nix expressions. A
10+ detailed description can be found in section 4, \"Meta-attributes\",
11+ of the Nixpkgs manual at <http://nixos.org/nixpkgs/docs.html>.
9−-}
12+ -}
10
13
11module Distribution.NixOS.Derivation.Meta
14module Distribution.NixOS.Derivation.Meta
12 ( Meta(..)
15 ( Meta(..)
@@ -18,12 +21,29 @@ import Distribution.NixOS.PrettyPrinting
18import Distribution.NixOS.Derivation.License
21import Distribution.NixOS.Derivation.License
19import Distribution.Text
22import Distribution.Text
20
23
24+-- | A representation of the @meta@ section used in Nix expressions.
25+--
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 =
34+-- > stdenv.lib.platforms.unix ++ stdenv.lib.platforms.cygwin;
35+-- > maintainers = [ stdenv.lib.maintainers.joe stdenv.lib.maintainers.jane ];
36+-- > };
37+--
38+-- Note that the "Text" instance definition provides pretty-printing,
39+-- but no parsing as of now!
40+
21data Meta = Meta
41data Meta = Meta
22− { homepage :: String
42+ { homepage :: String -- ^ URL of the package homepage
23− , description :: String
43+ , description :: String -- ^ short description of the package
24− , license :: License
44+ , license :: License -- ^ licensing terms
25− , platforms :: [String]
45+ , platforms :: [String] -- ^ list of supported platforms from @pkgs\/lib\/platforms.nix@
26− , maintainers :: [String]
46+ , maintainers :: [String] -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
27 }
47 }
28 deriving (Show, Eq, Ord)
48 deriving (Show, Eq, Ord)
29
49
src/Distribution/NixOS/PrettyPrinting.hs−1
@@ -1,6 +1,5 @@
1{- |
1{- |
2 Module : Distribution.NixOS.PrettyPrinting
2 Module : Distribution.NixOS.PrettyPrinting
3− Copyright : Peter Simons, Andres Loeh
4 License : BSD3
3 License : BSD3
5
4
6 Maintainer : nix-dev@cs.uu.nl
5 Maintainer : nix-dev@cs.uu.nl