git.iko.soy/typeable/cabal2nix
on master help sign in
hackage2nix.hs: add --hackage command line option
1cb6ddbPeter Simons
src/hackage2nix.hs+28−3
@@ -1,3 +1,5 @@
1+{-# LANGUAGE RecordWildCards #-}
2+
1module Main ( main ) where
3module Main ( main ) where
2
4
3import Cabal2Nix.Flags ( configureCabalFlags )
5import Cabal2Nix.Flags ( configureCabalFlags )
@@ -25,11 +27,13 @@ import Distribution.Nixpkgs.Meta
25import Distribution.Nixpkgs.PackageMap
27import Distribution.Nixpkgs.PackageMap
26import Distribution.Nixpkgs.Util.PrettyPrinting hiding ( attr, (<>) )
28import Distribution.Nixpkgs.Util.PrettyPrinting hiding ( attr, (<>) )
27import Distribution.Package
29import Distribution.Package
28−import Distribution.PackageDescription hiding ( buildDepends, extraLibs, buildTools )
30+import Distribution.PackageDescription hiding ( options, buildDepends, extraLibs, buildTools )
29import Distribution.PackageDescription.Configuration
31import Distribution.PackageDescription.Configuration
30import Distribution.System
32import Distribution.System
31import Distribution.Text
33import Distribution.Text
32import Distribution.Version
34import Distribution.Version
35+import Options.Applicative
36+import Cabal2Nix.Version
33
37
34type Nixpkgs = PackageMap -- Map String (Set [String])
38type Nixpkgs = PackageMap -- Map String (Set [String])
35type PackageSet = Map String Version
39type PackageSet = Map String Version
@@ -77,9 +81,30 @@ data Configuration = Configuration
77 }
81 }
78 deriving (Read, Show)
82 deriving (Read, Show)
79
83
84+data Options = Options
85+ { hackageRepository :: FilePath
86+ }
87+ deriving (Show)
88+
89+options :: Parser Options
90+options = Options
91+ <$> (strOption $ long "hackage" <> help "path to Hackage git repository" <> value "hackage" <> showDefault)
92+
93+pinfo :: ParserInfo Options
94+pinfo = info
95+ ( helper
96+ <*> infoOption ("hackage2nix " ++ version) (long "version" <> help "Show version number")
97+ <*> options
98+ )
99+ ( fullDesc
100+ <> header "hackage2nix converts a Hackage database into a haskell-packages.nix file."
101+ )
102+
80main :: IO ()
103main :: IO ()
81main = do
104main = do
105+ Options {..} <- execParser pinfo
106+
82− hackage <- readHackage "hackage"
107+ hackage <- readHackage hackageRepository
83 nixpkgs <- readNixpkgPackageMap
108 nixpkgs <- readNixpkgPackageMap
84 let fixup = Map.delete "acme-everything" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
109 let fixup = Map.delete "acme-everything" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
85 . Map.delete "som" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
110 . Map.delete "som" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
@@ -166,7 +191,7 @@ generatePackageSet config hackage nixpkgs = do
166 formatOverride n Nothing = space <> text n <> text " = null;" -- missing attribute
191 formatOverride n Nothing = space <> text n <> text " = null;" -- missing attribute
167 formatOverride n (Just []) -- Haskell package:
192 formatOverride n (Just []) -- Haskell package:
168 | n == name = formatOverride n Nothing -- refers to a missing system library
193 | n == name = formatOverride n Nothing -- refers to a missing system library
169− | otherwise = empty -- found by callPackage
194+ | otherwise = mempty -- found by callPackage
170 formatOverride n (Just p) = (text " inherit" <+> parens (text (intercalate "." p)) <+> text n) <> semi
195 formatOverride n (Just p) = (text " inherit" <+> parens (text (intercalate "." p)) <+> text n) <> semi
171
196
172 overrides :: Doc
197 overrides :: Doc