git.iko.soy/typeable/cabal2nix
on master help sign in
hackage2nix: accept path to nixpkgs repository on the command line

Resolves https://github.com/NixOS/cabal2nix/issues/120.

commit99eae7bfbca43232798efce7e3fbe00716061606 authorPeter Simons <simons@cryp.to> dateMon 10 Aug 2015, 15:34 (11 years ago) parent1cb6ddb
2 files changed+9−7
src/Distribution/Nixpkgs/PackageMap.hs+5−5 src/hackage2nix.hs+4−2
src/Distribution/Nixpkgs/PackageMap.hs+5−5
@@ -12,9 +12,9 @@ import System.Process
1212type Attribute = String
1313type Path = [Attribute]
1414
15−readNixpkgAttributeSet :: IO (Set Attribute)
16−readNixpkgAttributeSet = do
17− buf <- readProcess "nix-env" ["-qaP", "--json", "-f<nixpkgs>"] ""
15+readNixpkgAttributeSet :: FilePath -> IO (Set Attribute)
16+readNixpkgAttributeSet nixpkgs = do
17+ buf <- readProcess "nix-env" ["-qaP", "--json", "-f"++nixpkgs] ""
1818 let pkgmap :: Either String (Map Attribute JSON.Object)
1919 pkgmap = JSON.eitherDecodeStrict (UTF8.toRep (UTF8.fromString buf))
2020 either fail (return . Map.keysSet) pkgmap
@@ -34,5 +34,5 @@ attributeSet2PackageMap pkgset = foldr (uncurry insertAttribute) Map.empty pkgli
3434 insertAttribute :: Attribute -> Path -> PackageMap -> PackageMap
3535 insertAttribute attr = Map.insertWith Set.union attr . Set.singleton
3636
37−readNixpkgPackageMap :: IO PackageMap
38−readNixpkgPackageMap = fmap attributeSet2PackageMap readNixpkgAttributeSet
37+readNixpkgPackageMap :: FilePath -> IO PackageMap
38+readNixpkgPackageMap nixpkgs = fmap attributeSet2PackageMap (readNixpkgAttributeSet nixpkgs)
src/hackage2nix.hs+4−2
@@ -83,12 +83,14 @@ data Configuration = Configuration
8383
8484data Options = Options
8585 { hackageRepository :: FilePath
86+ , nixpkgsRepository :: FilePath
8687 }
8788 deriving (Show)
8889
8990options :: Parser Options
9091options = Options
91− <$> (strOption $ long "hackage" <> help "path to Hackage git repository" <> value "hackage" <> showDefault)
92+ <$> (strOption $ long "hackage" <> help "path to Hackage git repository" <> value "hackage" <> showDefault <> metavar "PATH")
93+ <*> (strOption $ long "nixpkgs" <> help "path to Nixpkgs repository" <> value "<nixpkgs>" <> showDefault <> metavar "PATH")
9294
9395pinfo :: ParserInfo Options
9496pinfo = info
@@ -105,7 +107,7 @@ main = do
105107 Options {..} <- execParser pinfo
106108
107109 hackage <- readHackage hackageRepository
108− nixpkgs <- readNixpkgPackageMap
110+ nixpkgs <- readNixpkgPackageMap nixpkgsRepository
109111 let fixup = Map.delete "acme-everything" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
110112 . Map.delete "som" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
111113 . Map.delete "type" -- TODO: https://github.com/NixOS/cabal2nix/issues/163