git.iko.soy/typeable/cabal2nix
on master help sign in
Cleaned up our representation of licenses.
commit1bccb4ea5420d58c9847fa25340d078d5502657e authorPeter Simons <simons@cryp.to> dateMon 15 Aug 2011, 11:11 (15 years ago) parent6bba006
3 files changed+27−47
src/Cabal2Nix/License.hs+20 src/Cabal2Nix/Package.hs+1 src/Distribution/NixOS/Derivation/License.hs+6−47
src/Cabal2Nix/License.hsnew file+20
@@ -0,0 +1,20 @@
1+module Cabal2Nix.License ( fromCabalLicense ) where
2+
3+import Distribution.NixOS.Derivation.License
4+import Distribution.License ( License(..) )
5+import Data.Version
6+
7+fromCabalLicense :: Distribution.License.License -> Distribution.NixOS.Derivation.License.License
8+fromCabalLicense (GPL Nothing) = Unknown (Just "GPL")
9+fromCabalLicense (GPL (Just (Version [2] []))) = Known "self.stdenv.lib.licenses.gpl2"
10+fromCabalLicense (GPL (Just (Version [3] []))) = Known "self.stdenv.lib.licenses.gpl3"
11+fromCabalLicense (LGPL Nothing) = Unknown (Just "LGPL")
12+fromCabalLicense (LGPL (Just (Version [2,1] []))) = Known "self.stdenv.lib.licenses.lgpl21"
13+fromCabalLicense (LGPL (Just (Version [3] []))) = Known "self.stdenv.lib.licenses.gpl3"
14+fromCabalLicense BSD3 = Known "self.stdenv.lib.licenses.bsd3"
15+fromCabalLicense BSD4 = Known "self.stdenv.lib.licenses.bsd4"
16+fromCabalLicense MIT = Known "self.stdenv.lib.licenses.mit"
17+fromCabalLicense PublicDomain = Known "self.stdenv.lib.licenses.publicDomain"
18+fromCabalLicense AllRightsReserved = Known "self.stdenv.lib.licenses.proprietary"
19+fromCabalLicense OtherLicense = Unknown Nothing
20+fromCabalLicense l = error $ "Cabal2Nix.License.fromCabalLicense: unknown license " ++ show l
src/Cabal2Nix/Package.hs+1
@@ -1,5 +1,6 @@
11module Cabal2Nix.Package ( cabal2nix ) where
22
3+import Cabal2Nix.License
34import Data.Maybe
45import Distribution.Compiler
56import qualified Distribution.Package as Cabal
src/Distribution/NixOS/Derivation/License.hs+6−47
@@ -8,57 +8,16 @@
88 Portability : portable
99-}
1010
11−module Distribution.NixOS.Derivation.License
12− ( License(..)
13− , fromCabalLicense
14− )
15− where
11+module Distribution.NixOS.Derivation.License ( License(..) ) where
1612
17−import qualified Distribution.License as Cabal ( License(..) )
18−import Data.Version ( Version(..) )
13+import Distribution.NixOS.PrettyPrinting
1914import Distribution.Text
20−import Text.PrettyPrint
2115
22−data License
23− = GPL2
24− | GPL3
25− | LGPL21
26− | LGPL3
27− | BSD3
28− | BSD4
29− | MIT
30− | PublicDomain
31− | Proprietary
32− | Unknown (Maybe String)
33− deriving (Eq, Ord)
34−
35−instance Show License where
36− show GPL2 = "self.stdenv.lib.licenses.gpl2"
37− show GPL3 = "self.stdenv.lib.licenses.gpl3"
38− show LGPL21 = "self.stdenv.lib.licenses.lgpl21"
39− show LGPL3 = "self.stdenv.lib.licenses.gpl3"
40− show BSD3 = "self.stdenv.lib.licenses.bsd3"
41− show BSD4 = "self.stdenv.lib.licenses.bsd4"
42− show MIT = "self.stdenv.lib.licenses.mit"
43− show PublicDomain = "self.stdenv.lib.licenses.publicDomain"
44− show Proprietary = "self.stdenv.lib.licenses.proprietary"
45− show (Unknown lic) = show (maybe "unknown" id lic)
16+data License = Known String | Unknown (Maybe String)
17+ deriving (Show, Eq, Ord)
4618
4719instance Text License where
48− disp = text . show
20+ disp (Known x) = text x
21+ disp (Unknown x) = string (maybe "unknown" id x)
4922 parse = error "parsing Distribution.NixOS.Derivation.License is not supported yet"
5023
51−fromCabalLicense :: Cabal.License -> License
52−fromCabalLicense (Cabal.GPL Nothing) = Unknown (Just "GPL")
53−fromCabalLicense (Cabal.GPL (Just (Version [2] []))) = GPL2
54−fromCabalLicense (Cabal.GPL (Just (Version [3] []))) = GPL3
55−fromCabalLicense (Cabal.LGPL Nothing) = Unknown (Just "LGPL")
56−fromCabalLicense (Cabal.LGPL (Just (Version [2,1] []))) = LGPL21
57−fromCabalLicense (Cabal.LGPL (Just (Version [3] []))) = LGPL3
58−fromCabalLicense Cabal.BSD3 = BSD3
59−fromCabalLicense Cabal.BSD4 = BSD4
60−fromCabalLicense Cabal.MIT = MIT
61−fromCabalLicense Cabal.PublicDomain = PublicDomain
62−fromCabalLicense Cabal.AllRightsReserved = Proprietary
63−fromCabalLicense Cabal.OtherLicense = Unknown Nothing
64−fromCabalLicense l = error $ "Distribution.NixOS.Derivation.License.fromCabalLicense: unknown license " ++ show l