git.iko.soy/typeable/cabal2nix
on master help sign in
Restrict export list of BuildInfo, Meta, and Derivation types to enforce access through lenses.
d63faadPeter Simons
src/Cabal2Nix/Generate.hs+2−45
@@ -37,30 +37,6 @@ cabal2nix flags' cabal = normalize $ drv & cabalFlags .~ flags
37 []
37 []
38 cabal
38 cabal
39
39
40−nullDerivation :: Derivation
41−nullDerivation = MkDerivation
42− { _pkgid = error "undefined _pkgid"
43− , _revision = error "undefined _revision"
44− , _src = error "undefined _src"
45− , _isLibrary = error "undefined _isLibrary"
46− , _isExecutable = error "undefined _isExecutable"
47− , _extraFunctionArgs = error "undefined _extraFunctionArgs"
48− , _libraryDepends = error "undefined _libraryDepends"
49− , _executableDepends = error "undefined _executableDepends"
50− , _testDepends = error "undefined _testDepends"
51− , _configureFlags = error "undefined _configureFlags"
52− , _cabalFlags = error "undefined _cabalFlags"
53− , _runHaddock = error "undefined _runHaddock"
54− , _jailbreak = error "undefined _jailbreak"
55− , _doCheck = error "undefined _doCheck"
56− , _testTarget = error "undefined _testTarget"
57− , _hyperlinkSource = error "undefined _hyperlinkSource"
58− , _enableSplitObjs = error "undefined _enableSplitObjs"
59− , _phaseOverrides = error "undefined _phaseOverrides"
60− , _editedCabalFile = error "undefined _editedCabalFile"
61− , _metaSection = error "undefined _metaSection"
62− }
63−
64cabal2nix' :: PackageDescription -> Derivation
40cabal2nix' :: PackageDescription -> Derivation
65cabal2nix' PackageDescription {..} = normalize $ postProcess $
41cabal2nix' PackageDescription {..} = normalize $ postProcess $
66 let
42 let
@@ -91,7 +67,7 @@ cabal2nix' PackageDescription {..} = normalize $ postProcess $
91 & enableSplitObjs .~ True
67 & enableSplitObjs .~ True
92 & phaseOverrides .~ mempty
68 & phaseOverrides .~ mempty
93 & editedCabalFile .~ (if xrev > 0 then fromJust (lookup "x-cabal-file-hash" customFieldsPD) else "")
69 & editedCabalFile .~ (if xrev > 0 then fromJust (lookup "x-cabal-file-hash" customFieldsPD) else "")
94− & metaSection .~ ( nullMeta
70+ & metaSection .~ ( Nix.nullMeta
95 & Nix.homepage .~ homepage
71 & Nix.homepage .~ homepage
96 & Nix.description .~ synopsis
72 & Nix.description .~ synopsis
97 & Nix.license .~ fromCabalLicense license
73 & Nix.license .~ fromCabalLicense license
@@ -101,27 +77,8 @@ cabal2nix' PackageDescription {..} = normalize $ postProcess $
101 & Nix.broken .~ False
77 & Nix.broken .~ False
102 )
78 )
103
79
104−nullBuildInfo :: Nix.BuildInfo
105−nullBuildInfo = Nix.BuildInfo
106− { _haskell = error "undefined _haskell"
107− , _pkgconfig = error "undefined _pkgconfig"
108− , _system = error "undefined _system"
109− , _tool = error "undefined _tool"
110− }
111−
112−nullMeta :: Nix.Meta
113−nullMeta = Nix.Meta
114− { Nix._homepage = error "undefined Nix._homepage"
115− , Nix._description = error "undefined Nix._description"
116− , Nix._license = error "undefined Nix._license"
117− , Nix._platforms = error "undefined Nix._platforms"
118− , Nix._hydraPlatforms = error "undefined Nix._hydraPlatforms"
119− , Nix._maintainers = error "undefined Nix._maintainers"
120− , Nix._broken = error "undefined Nix._broken"
121− }
122−
123convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
80convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
124−convertBuildInfo Cabal.BuildInfo {..} = nullBuildInfo
81+convertBuildInfo Cabal.BuildInfo {..} = mempty
125 & haskell .~ Set.fromList targetBuildDepends
82 & haskell .~ Set.fromList targetBuildDepends
126 & system .~ Set.fromList [ Dependency (PackageName y) anyVersion | x <- extraLibs, y <- libNixName x, not (null y) ]
83 & system .~ Set.fromList [ Dependency (PackageName y) anyVersion | x <- extraLibs, y <- libNixName x, not (null y) ]
127 & pkgconfig .~ Set.fromList [ Dependency (PackageName y) anyVersion | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x, not (null y) ]
84 & pkgconfig .~ Set.fromList [ Dependency (PackageName y) anyVersion | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x, not (null y) ]
src/Distribution/Nixpkgs/Haskell.hs+35−2
@@ -2,7 +2,16 @@
2{-# LANGUAGE RecordWildCards, DeriveGeneric #-}
2{-# LANGUAGE RecordWildCards, DeriveGeneric #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-} -- for FlagName below
3{-# OPTIONS_GHC -fno-warn-orphans #-} -- for FlagName below
4
4
5−module Distribution.Nixpkgs.Haskell where
5+module Distribution.Nixpkgs.Haskell
6+ ( Derivation, nullDerivation, pkgid, revision, src, isLibrary, isExecutable
7+ , extraFunctionArgs, libraryDepends, executableDepends, testDepends, configureFlags
8+ , cabalFlags, runHaddock, jailbreak, doCheck, testTarget, hyperlinkSource, enableSplitObjs
9+ , phaseOverrides, editedCabalFile, metaSection
10+ , BuildInfo, haskell, pkgconfig, system, tool
11+ , dependencies
12+ , unDep
13+ )
14+ where
6
15
7import Control.DeepSeq.Generics
16import Control.DeepSeq.Generics
8import Control.Lens
17import Control.Lens
@@ -62,12 +71,36 @@ data Derivation = MkDerivation
62 }
71 }
63 deriving (Show, Eq, Generic)
72 deriving (Show, Eq, Generic)
64
73
74+nullDerivation :: Derivation
75+nullDerivation = MkDerivation
76+ { _pkgid = error "undefined _pkgid"
77+ , _revision = error "undefined _revision"
78+ , _src = error "undefined _src"
79+ , _isLibrary = error "undefined _isLibrary"
80+ , _isExecutable = error "undefined _isExecutable"
81+ , _extraFunctionArgs = error "undefined _extraFunctionArgs"
82+ , _libraryDepends = error "undefined _libraryDepends"
83+ , _executableDepends = error "undefined _executableDepends"
84+ , _testDepends = error "undefined _testDepends"
85+ , _configureFlags = error "undefined _configureFlags"
86+ , _cabalFlags = error "undefined _cabalFlags"
87+ , _runHaddock = error "undefined _runHaddock"
88+ , _jailbreak = error "undefined _jailbreak"
89+ , _doCheck = error "undefined _doCheck"
90+ , _testTarget = error "undefined _testTarget"
91+ , _hyperlinkSource = error "undefined _hyperlinkSource"
92+ , _enableSplitObjs = error "undefined _enableSplitObjs"
93+ , _phaseOverrides = error "undefined _phaseOverrides"
94+ , _editedCabalFile = error "undefined _editedCabalFile"
95+ , _metaSection = error "undefined _metaSection"
96+ }
97+
65makeLenses ''Derivation
98makeLenses ''Derivation
66
99
67makeLensesFor [("_libraryDepends", "dependencies"), ("_executableDepends", "dependencies"), ("_testDepends", "dependencies")] ''Derivation
100makeLensesFor [("_libraryDepends", "dependencies"), ("_executableDepends", "dependencies"), ("_testDepends", "dependencies")] ''Derivation
68
101
69instance Package Derivation where
102instance Package Derivation where
70− packageId = _pkgid
103+ packageId = view pkgid
71
104
72instance NFData BuildInfo where rnf = genericRnf
105instance NFData BuildInfo where rnf = genericRnf
73
106
src/Distribution/Nixpkgs/Meta.hs+16−1
@@ -6,7 +6,11 @@
6 of the Nixpkgs manual at <http://nixos.org/nixpkgs/docs.html>.
6 of the Nixpkgs manual at <http://nixos.org/nixpkgs/docs.html>.
7 -}
7 -}
8
8
9−module Distribution.Nixpkgs.Meta where
9+module Distribution.Nixpkgs.Meta
10+ ( Meta, nullMeta
11+ , homepage, description, license, platforms, hydraPlatforms, maintainers, broken
12+ ) where
13+
10
14
11import Control.DeepSeq.Generics
15import Control.DeepSeq.Generics
12import Control.Lens
16import Control.Lens
@@ -67,3 +71,14 @@ instance Pretty Meta where
67renderPlatformList :: [String] -> Doc
71renderPlatformList :: [String] -> Doc
68renderPlatformList plats =
72renderPlatformList plats =
69 nest 2 (fsep $ punctuate (text " ++") $ map text plats) <> semi
73 nest 2 (fsep $ punctuate (text " ++") $ map text plats) <> semi
74+
75+nullMeta :: Meta
76+nullMeta = Meta
77+ { _homepage = error "undefined Nix._homepage"
78+ , _description = error "undefined Nix._description"
79+ , _license = error "undefined Nix._license"
80+ , _platforms = error "undefined Nix._platforms"
81+ , _hydraPlatforms = error "undefined Nix._hydraPlatforms"
82+ , _maintainers = error "undefined Nix._maintainers"
83+ , _broken = error "undefined Nix._broken"
84+ }
test/spec.hs+8−9
@@ -1,8 +1,8 @@
1module Main ( main ) where
1module Main ( main ) where
2
2
3+import Control.Lens
3import Control.DeepSeq
4import Control.DeepSeq
4import Control.Exception
5import Control.Exception
5−import Data.Set ( empty )
6import Distribution.Nixpkgs.License
6import Distribution.Nixpkgs.License
7import Distribution.Nixpkgs.Meta
7import Distribution.Nixpkgs.Meta
8import Test.Hspec
8import Test.Hspec
@@ -12,14 +12,13 @@ main = do
12 hspec $ do
12 hspec $ do
13 describe "DeepSeq instances work properly for" $ do
13 describe "DeepSeq instances work properly for" $ do
14 it "License" $ mapM_ hitsBottom [Known undefined, Unknown (Just undefined)]
14 it "License" $ mapM_ hitsBottom [Known undefined, Unknown (Just undefined)]
15− it "Meta" $ do let meta = Meta "" "" (Unknown Nothing) empty empty empty False
16− mapM_ hitsBottom
15+ it "Meta" $ do mapM_ hitsBottom
17− [ meta { _homepage = undefined }
16+ [ nullMeta & homepage .~ undefined
18− , meta { _description = undefined }
17+ , nullMeta & description .~ undefined
19− , meta { _license = undefined }
18+ , nullMeta & license .~ undefined
20− , meta { _platforms = undefined }
19+ , nullMeta & platforms .~ undefined
21− , meta { _maintainers = undefined }
20+ , nullMeta & maintainers .~ undefined
22− , meta { _broken = undefined }
21+ , nullMeta & broken .~ undefined
23 ]
22 ]
24
23
25hitsBottom :: NFData a => a -> Expectation
24hitsBottom :: NFData a => a -> Expectation