git.iko.soy/typeable/cabal2nix
on 1663fb8 help sign in
47 lines 1.8 kB history raw
1{-# LANGUAGE DeriveGeneric #-}
2{- |
3 Known licenses in Nix expressions are represented using the
4 attributes defined in @pkgs\/lib\/licenses.nix@, and unknown licenses
5 are represented as a literal string.
6 -}
8module Distribution.Nixpkgs.License ( License(..) ) where
10import Control.DeepSeq.Generics
11import Data.Maybe
12import Distribution.Nixpkgs.Util.PrettyPrinting
13import GHC.Generics ( Generic )
15-- | The representation for licenses used in Nix derivations. Known
16-- licenses are Nix expressions -- such as @stdenv.lib.licenses.bsd3@
17-- --, so their exact \"name\" is not generally known, because the path
18-- to @stdenv@ depends on the context defined in the expression. In
19-- Cabal expressions, for example, the BSD3 license would have to be
20-- referred to as @self.stdenv.lib.licenses.bsd3@. Other expressions,
21-- however, use different paths to the @licenses@ record. Because of tat
22-- situation, the library cannot provide an abstract data type that
23-- encompasses all known licenses. Instead, the @License@ type just
24-- distinguishes references to known and unknown licenses. The
25-- difference between the two is in the way they are pretty-printed:
26--
27-- > > putStrLn (display (Known "stdenv.lib.license.gpl2"))
28-- > stdenv.lib.license.gpl2
29-- >
30-- > > putStrLn (display (Unknown (Just "GPL")))
31-- > "GPL"
32-- >
33-- > > putStrLn (display (Unknown Nothing))
34-- > "unknown"
35--
36-- Note that the "Text" instance definition provides pretty-printing,
37-- but no parsing as of now!
39data License = Known String
40 | Unknown (Maybe String)
41 deriving (Show, Eq, Ord, Generic)
43instance Pretty License where
44 pPrint (Known x) = text x
45 pPrint (Unknown x) = string (fromMaybe "unknown" x)
47instance NFData License where rnf = genericRnf