git.iko.soy/typeable/cabal2nix
on 1663fb8 help sign in
72 lines 2.9 kB history raw
1{-# LANGUAGE DeriveGeneric, RecordWildCards #-}
2{- |
3 A representation of the @meta@ section used in Nix expressions. A
4 detailed description can be found in section 4, \"Meta-attributes\",
5 of the Nixpkgs manual at <http://nixos.org/nixpkgs/docs.html>.
6 -}
8module Distribution.Nixpkgs.Meta
9 ( Meta(..)
10 , module Distribution.Nixpkgs.License
11 )
12 where
14import Control.DeepSeq.Generics
15import Distribution.Nixpkgs.License
16import Distribution.Nixpkgs.Util.PrettyPrinting
17import GHC.Generics ( Generic )
18import Data.Set ( Set )
19import qualified Data.Set as Set
21-- | A representation of the @meta@ section used in Nix expressions.
22--
23-- >>> :{
24-- print (pPrint (Meta "http://example.org" "an example package" (Unknown Nothing)
25-- (Set.singleton "stdenv.lib.platforms.unix")
26-- (Set.singleton "stdenv.lib.platforms.none")
27-- (Set.fromList ["joe","jane"])
28-- True))
29-- :}
30-- homepage = "http://example.org";
31-- description = "an example package";
32-- license = "unknown";
33-- platforms = stdenv.lib.platforms.unix;
34-- hydraPlatforms = stdenv.lib.platforms.none;
35-- maintainers = with stdenv.lib.maintainers; [ jane joe ];
36-- broken = true;
37--
38-- Note that the "Text" instance definition provides pretty-printing,
39-- but no parsing as of now!
41data Meta = Meta
42 { homepage :: String -- ^ URL of the package homepage
43 , description :: String -- ^ short description of the package
44 , license :: License -- ^ licensing terms
45 , platforms :: Set String -- ^ list of supported platforms (from @pkgs\/lib\/platforms.nix@)
46 , hydraPlatforms :: Set String -- ^ list of platforms built by Hydra (from @pkgs\/lib\/platforms.nix@)
47 , maintainers :: Set String -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
48 , broken :: Bool -- ^ set to @true@ if the build is known to fail
49 }
50 deriving (Show, Eq, Ord, Generic)
52instance Pretty Meta where
53 pPrint = renderMeta
55instance NFData Meta where rnf = genericRnf
57renderMeta :: Meta -> Doc
58renderMeta (Meta {..}) = vcat
59 [ onlyIf (not (null homepage)) $ attr "homepage" $ string homepage
60 , onlyIf (not (null description)) $ attr "description" $ string description
61 , attr "license" $ pPrint license
62 , onlyIf (not (Set.null platforms) && platforms /= Set.singleton "ghc.meta.platforms") $ sep
63 [ text "platforms" <+> equals, renderPlatformList (Set.toAscList platforms) ]
64 , onlyIf (not (Set.null hydraPlatforms)) $ sep
65 [ text "hydraPlatforms" <+> equals, renderPlatformList (Set.toAscList hydraPlatforms) ]
66 , listattr "maintainers" (text "with stdenv.lib.maintainers;") (Set.toAscList maintainers)
67 , boolattr "broken" broken broken
68 ]
70renderPlatformList :: [String] -> Doc
71renderPlatformList plats =
72 nest 2 (fsep $ punctuate (text " ++") $ map text plats) <> semi