@@ -1,3 +1,5 @@
1+{-# LANGUAGE RecordWildCards #-}
2+
13module Main ( main ) where
24
35import Cabal2Nix.Flags ( configureCabalFlags )
@@ -25,11 +27,13 @@ import Distribution.Nixpkgs.Meta
2527import Distribution.Nixpkgs.PackageMap
2628import Distribution.Nixpkgs.Util.PrettyPrinting hiding ( attr, (<>) )
2729import Distribution.Package
28−import Distribution.PackageDescription hiding ( buildDepends, extraLibs, buildTools )
30+import Distribution.PackageDescription hiding ( options, buildDepends, extraLibs, buildTools )
2931import Distribution.PackageDescription.Configuration
3032import Distribution.System
3133import Distribution.Text
3234import Distribution.Version
35+import Options.Applicative
36+import Cabal2Nix.Version
3337
3438type Nixpkgs = PackageMap -- Map String (Set [String])
3539type PackageSet = Map String Version
@@ -77,9 +81,30 @@ data Configuration = Configuration
7781 }
7882 deriving (Read, Show)
7983
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+
80103main :: IO ()
81104main = do
82− hackage <- readHackage "hackage"
105+ Options {..} <- execParser pinfo
106+
107+ hackage <- readHackage hackageRepository
83108 nixpkgs <- readNixpkgPackageMap
84109 let fixup = Map.delete "acme-everything" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
85110 . Map.delete "som" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
@@ -166,7 +191,7 @@ generatePackageSet config hackage nixpkgs = do
166191 formatOverride n Nothing = space <> text n <> text " = null;" -- missing attribute
167192 formatOverride n (Just []) -- Haskell package:
168193 | n == name = formatOverride n Nothing -- refers to a missing system library
169− | otherwise = empty -- found by callPackage
194+ | otherwise = mempty -- found by callPackage
170195 formatOverride n (Just p) = (text " inherit" <+> parens (text (intercalate "." p)) <+> text n) <> semi
171196
172197 overrides :: Doc