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