git.iko.soy/typeable/cabal2nix
on master help sign in
Distribution.NixOS.Derivation: added Haddock documentation
commit708f83ec6db49d15572a5037bdbc92cce247edcc authorPeter Simons <simons@cryp.to> dateMon 15 Aug 2011, 12:25 (15 years ago) parentae12979
4 files changed+78−15
src/Distribution/NixOS/Derivation/Cabal.hs+20−4 src/Distribution/NixOS/Derivation/License.hs+31−3 src/Distribution/NixOS/Derivation/Meta.hs+27−7 src/Distribution/NixOS/PrettyPrinting.hs−1
src/Distribution/NixOS/Derivation/Cabal.hs+20−4
@@ -1,19 +1,21 @@
1−{-# LANGUAGE PatternGuards #-}
1+{-# LANGUAGE PatternGuards, CPP #-}
22{- |
33 Module : Distribution.NixOS.Derivation.Cabal
4− Copyright : Peter Simons, Andres Loeh
54 License : BSD3
65
76 Maintainer : nix-dev@cs.uu.nl
87 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@.
1012-}
1113
1214module Distribution.NixOS.Derivation.Cabal
1315 ( Derivation(..)
1416 , parseDerivation
1517 , module Distribution.NixOS.Derivation.Meta
16− , Version(..)
18+ , module Data.Version
1719 )
1820 where
1921
@@ -21,11 +23,21 @@ import Distribution.NixOS.Derivation.Meta
2123import Distribution.NixOS.PrettyPrinting
2224import Distribution.Text
2325import Distribution.Package
26+#ifdef __HADDOCK__
27+import Distribution.PackageDescription ( PackageDescription )
28+#endif
2429import Data.Version
2530import Data.List
2631import Data.Char
2732import Text.Regex.Posix
2833
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+
2941data Derivation = MkDerivation
3042 { pname :: String
3143 , version :: Version
@@ -73,6 +85,10 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
7385 filter (/="cabal") $ filter (/="Cabal") $
7486 buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
7587
88+-- | A very incomplete parser that extracts 'pname', 'version',
89+-- 'sha256', 'platforms', 'maintainers', and 'runHaddock' from the given
90+-- Nix expression.
91+
7692parseDerivation :: String -> Maybe Derivation
7793parseDerivation buf
7894 | buf =~ "cabal.mkDerivation"
src/Distribution/NixOS/Derivation/License.hs+31−3
@@ -1,19 +1,47 @@
11{- |
22 Module : Distribution.NixOS.Derivation.License
3− Copyright : Peter Simons, Andres Loeh
43 License : BSD3
54
65 Maintainer : nix-dev@cs.uu.nl
76 Stability : provisional
87 Portability : portable
9−-}
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.
12+ -}
1013
1114module Distribution.NixOS.Derivation.License ( License(..) ) where
1215
1316import Distribution.NixOS.PrettyPrinting
1417import Distribution.Text
1518
16−data License = Known String | Unknown (Maybe String)
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+
43+data License = Known String
44+ | Unknown (Maybe String)
1745 deriving (Show, Eq, Ord)
1846
1947instance Text License where
src/Distribution/NixOS/Derivation/Meta.hs+27−7
@@ -1,12 +1,15 @@
11{- |
22 Module : Distribution.NixOS.Derivation.Meta
3− Copyright : Peter Simons, Andres Loeh
43 License : BSD3
54
65 Maintainer : nix-dev@cs.uu.nl
76 Stability : provisional
87 Portability : portable
9−-}
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>.
12+ -}
1013
1114module Distribution.NixOS.Derivation.Meta
1215 ( Meta(..)
@@ -18,12 +21,29 @@ import Distribution.NixOS.PrettyPrinting
1821import Distribution.NixOS.Derivation.License
1922import Distribution.Text
2023
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+
2141data Meta = Meta
22− { homepage :: String
23− , description :: String
24− , license :: License
25− , platforms :: [String]
26− , maintainers :: [String]
42+ { homepage :: String -- ^ URL of the package homepage
43+ , description :: String -- ^ short description of the package
44+ , license :: License -- ^ licensing terms
45+ , platforms :: [String] -- ^ list of supported platforms from @pkgs\/lib\/platforms.nix@
46+ , maintainers :: [String] -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
2747 }
2848 deriving (Show, Eq, Ord)
2949
src/Distribution/NixOS/PrettyPrinting.hs−1
@@ -1,6 +1,5 @@
11{- |
22 Module : Distribution.NixOS.PrettyPrinting
3− Copyright : Peter Simons, Andres Loeh
43 License : BSD3
54
65 Maintainer : nix-dev@cs.uu.nl