git.iko.soy/typeable/cabal2nix
on master help sign in
Support local-only projects
commit1a871eb23791d5696fb845369feeb7c3f11f184c authorBenno Fünfstück <benno.fuenfstueck@gmail.com> dateMon 6 Jan 2014, 17:58 (13 years ago) parent28c7211
3 files changed+27−16
src/Cabal2Nix/Generate.hs+5−5 src/Distribution/NixOS/Derivation/Cabal.hs+13−7 src/cabal2nix.hs+9−4
src/Cabal2Nix/Generate.hs+5−5
@@ -1,23 +1,23 @@
11module Cabal2Nix.Generate ( cabal2nix ) where
22
3+import Cabal2Nix.Flags
34import Cabal2Nix.License
4−import Cabal2Nix.PostProcess
55import Cabal2Nix.Normalize
6−import Cabal2Nix.Flags
6+import Cabal2Nix.PostProcess
77import Data.Maybe
88import Distribution.Compiler
9+import Distribution.NixOS.Derivation.Cabal
910import qualified Distribution.Package as Cabal
1011import qualified Distribution.PackageDescription as Cabal
1112import Distribution.PackageDescription.Configuration
1213import Distribution.System
13−import Distribution.Version
14−import Distribution.NixOS.Derivation.Cabal
1514
1615cabal2nix :: Cabal.GenericPackageDescription -> Derivation
1716cabal2nix cabal = normalize $ postProcess MkDerivation
1817 { pname = let Cabal.PackageName x = Cabal.pkgName pkg in x
1918 , version = Cabal.pkgVersion pkg
20− , sha256 = "cabal2nix left the sha256 field undefined"
19+ , sha256 = error "cabal2nix left the sha256 field undefined"
20+ , src = Nothing
2121 , isLibrary = isJust (Cabal.library tpkg)
2222 , isExecutable = not (null (Cabal.executables tpkg))
2323 , buildDepends = map unDep deps
src/Distribution/NixOS/Derivation/Cabal.hs+13−7
@@ -19,10 +19,11 @@ module Distribution.NixOS.Derivation.Cabal
1919 )
2020 where
2121
22+import Data.Maybe
2223import Distribution.NixOS.Derivation.Meta
2324import Distribution.NixOS.PrettyPrinting
24−import Distribution.Text
2525import Distribution.Package
26+import Distribution.Text
2627#ifdef __HADDOCK__
2728import Distribution.PackageDescription ( PackageDescription )
2829#endif
@@ -43,7 +44,8 @@ import Text.Regex.Posix hiding ( empty )
4344data Derivation = MkDerivation
4445 { pname :: String
4546 , version :: Version
46− , sha256 :: String
47+ , sha256 :: Maybe String
48+ , src :: Maybe String
4749 , isLibrary :: Bool
4850 , isExecutable :: Bool
4951 , buildDepends :: [String]
@@ -73,11 +75,13 @@ renderDerivation :: Derivation -> Doc
7375renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
7476 [ text ""
7577 , text "cabal.mkDerivation" <+> lparen <> text "self" <> colon <+> lbrace
76− , nest 2 $ vcat
78+ , nest 2 $ vcat $
7779 [ attr "pname" $ string (pname deriv)
7880 , attr "version" $ doubleQuotes (disp (version deriv))
79− , attr "sha256" $ string (sha256 deriv)
80− , boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
81+ ] ++ maybeToList (fmap (attr "sha256" . string) $ sha256 deriv)
82+ ++ maybeToList (fmap (attr "src" . string) $ src deriv)
83+ ++
84+ [ boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
8185 , boolattr "isExecutable" (not (isLibrary deriv) || isExecutable deriv) (isExecutable deriv)
8286 , listattr "buildDepends" (buildDepends deriv)
8387 , listattr "testDepends" (testDepends deriv)
@@ -111,7 +115,8 @@ parseDerivation buf
111115 , [name] <- buf `regsubmatch` "pname *= *\"([^\"]+)\""
112116 , [vers'] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
113117 , Just vers <- simpleParse vers'
114− , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
118+ , sha <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
119+ , sr <- buf `regsubmatch` "src *= *([^;]+);"
115120 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
116121 , hplats <- buf `regsubmatch` "hydraPlatforms *= *([^;]+);"
117122 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
@@ -121,7 +126,8 @@ parseDerivation buf
121126 = Just MkDerivation
122127 { pname = name
123128 , version = vers
124− , sha256 = sha
129+ , sha256 = listToMaybe sha
130+ , src = listToMaybe sr
125131 , isLibrary = False
126132 , isExecutable = False
127133 , buildDepends = []
src/cabal2nix.hs+9−4
@@ -1,7 +1,7 @@
11module Main ( main ) where
22
3−import Cabal2Nix.Hackage ( hashPackage, readCabalFile )
43import Cabal2Nix.Generate ( cabal2nix )
4+import Cabal2Nix.Hackage ( hashPackage, readCabalFile )
55import Cabal2Nix.Normalize ( normalize )
66import Distribution.NixOS.Derivation.Cabal
77
@@ -24,6 +24,7 @@ data Configuration = Configuration
2424 , optHaddock :: Bool
2525 , optDoCheck :: Bool
2626 , optJailbreak :: Bool
27+ , optLocal :: Bool
2728 }
2829 deriving (Show)
2930
@@ -37,17 +38,19 @@ defaultConfiguration = Configuration
3738 , optHaddock = True
3839 , optDoCheck = True
3940 , optJailbreak = False
41+ , optLocal = False
4042 }
4143
4244options :: [OptDescr (Configuration -> Configuration)]
4345options =
4446 [ Option "h" ["help"] (NoArg (\o -> o { optPrintHelp = True })) "show this help text"
45− , Option "" ["sha256"] (ReqArg (\x o -> o { optSha256 = Just x }) "HASH") "sha256 hash of source tarball"
47+ , Option "" ["sha256"] (ReqArg (\x o -> o { optSha256 = Just x }) "HASH") "sha256 hash of source tarball"
4648 , Option "m" ["maintainer"] (ReqArg (\x o -> o { optMaintainer = x : optMaintainer o }) "MAINTAINER") "maintainer of this package (may be specified multiple times)"
4749 , Option "p" ["platform"] (ReqArg (\x o -> o { optPlatform = x : optPlatform o }) "PLATFORM") "supported build platforms (may be specified multiple times)"
4850 , Option "" ["no-haddock"] (NoArg (\o -> o { optHaddock = False })) "don't run Haddock when building this package"
4951 , Option "" ["no-check"] (NoArg (\o -> o { optDoCheck = False })) "don't run regression test suites of this package"
5052 , Option "" ["jailbreak"] (NoArg (\o -> o { optJailbreak = True })) "don't honor version restrictions on build inputs"
53+ , Option "" ["local"] (NoArg (\o -> o { optLocal = True })) "assume a local package that is not on hackage yet. "
5154 ]
5255
5356usage :: String
@@ -85,8 +88,9 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
8588
8689 let packageId = package (packageDescription cabal)
8790 sha <- case optSha256 cfg of
88− Just hash -> return hash
89− Nothing -> hashPackage packageId
91+ Just hash -> return $ Just hash
92+ Nothing | optLocal cfg -> return Nothing
93+ Nothing -> fmap Just $ hashPackage packageId
9094
9195 let deriv = (cabal2nix cabal) { sha256 = sha, runHaddock = optHaddock cfg, jailbreak = optJailbreak cfg }
9296 deriv' = deriv { metaSection = (metaSection deriv)
@@ -94,6 +98,7 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
9498 , platforms = optPlatform cfg
9599 }
96100 , doCheck = doCheck deriv && optDoCheck cfg
101+ , src = if optLocal cfg then Just "./." else Nothing
97102 }
98103
99104 putStr (show (disp (normalize deriv')))