1-- Run: cabal build -j hackage2nix && dist/build/hackage2nix/hackage2nix >~/.nix-defexpr/pkgs/development/haskell-modules/hackage-packages.nix
3module Main ( main ) where
5import Cabal2Nix.Generate
6-- import Cabal2Nix.Name
7import Cabal2Nix.Package
8import Cabal2Nix.Hackage ( readHashedHackage, Hackage )
10import Control.Monad.Par.Combinator
11import Control.Monad.Par.IO
12import Control.Monad.Trans
13import Data.Map ( Map )
14import qualified Data.Map as Map
16import Data.Set ( Set )
17import qualified Data.Set as Set
18import Distribution.NixOS.Derivation.Cabal
19import Distribution.NixOS.PrettyPrinting hiding ( (<>) )
20import Distribution.PackageDescription hiding ( buildDepends, extraLibs, buildTools )
21import Distribution.Text
24main = readHashedHackage >>= runParIO . generatePackageSet
26nixAttr :: String -> Version -> String
27nixAttr name _ = name -- ++ "_" ++ [ if c == '.' then '_' else c | c <- display ver ]
29generatePackageSet :: Hackage -> ParIO ()
30generatePackageSet db = do
31 pkgs <- parMapM generatePackage (Map.toList db)
32 liftIO $ putStrLn "/* hackage-packages.nix is an auto-generated file -- DO NOT EDIT! */"
34 liftIO $ putStrLn "{ pkgs, stdenv, callPackage }:"
36 liftIO $ putStrLn "self: {"
38 forM_ pkgs $ \(name, version, drv) -> do
39 let selectHackageNames :: Set String -> Set String
40 selectHackageNames = Set.intersection (Map.keysSet db)
42 selectMissingHackageNames :: Set String -> Set String
43 selectMissingHackageNames = flip Set.difference (Map.keysSet db)
45 conflicts :: Set String
46 conflicts = Set.difference (selectHackageNames $ Set.fromList (extraLibs drv ++ pkgConfDeps drv)) missing
48 conflictOverrides :: Doc
49 conflictOverrides | Set.null conflicts = empty
50 | otherwise = text " inherit (pkgs) " <> hsep (map text (Set.toAscList conflicts)) <> text "; "
53 missing = Set.union (Set.intersection missingSystemLibraries (Set.fromList (extraLibs drv ++ pkgConfDeps drv ++ buildTools drv)))
54 (selectMissingHackageNames (Set.fromList (buildDepends drv ++ testDepends drv)))
56 missingOverrides :: Doc
57 missingOverrides | Set.null missing = empty
58 | otherwise = fcat [ text (' ':dep++" = null;") | dep <- Set.toAscList missing ] <> space
61 overrides = conflictOverrides $+$ missingOverrides
63 let drv' = if Set.null missing then drv else drv { metaSection = (metaSection drv) { broken = True } }
64 -- when (name /= toNixName' name) $
65 -- liftIO $ print $ nest 2 $ (string (toNixName' name) <+> equals <+> text ("self." ++ show (nixAttr name version))) <> semi
66 -- liftIO $ print $ nest 2 $ (string (toNixName' name) <+> equals <+> text ("self." ++ show (nixAttr name version))) <> semi
67 -- when (name /= toNixName' name) $
68 -- liftIO $ print $ nest 2 $ (string name <+> equals <+> text ("self." ++ show (nixAttr name version))) <> semi
69 liftIO $ print $ nest 2 $ hang (string (nixAttr name version) <+> equals <+> text "callPackage") 2 (parens (disp drv')) <+> (braces overrides <> semi)
73generatePackage :: (String, Map Version GenericPackageDescription) -> ParIO (String,Version,Derivation)
74generatePackage (name, versions) = do
75 let latestVersion = Set.findMax (Map.keysSet versions)
76 pkgDescription = (Map.!) versions latestVersion
77 srcSpec <- liftIO $ sourceFromHackage Nothing (name ++ "-" ++ display latestVersion)
78 let drv' = (cabal2nix pkgDescription) { src = srcSpec }
79 Just cabalFileHash = lookup "x-cabal-file-hash" (customFieldsPD (packageDescription pkgDescription))
80 drv = drv' { editedCabalFile = if revision drv' == 0 then "" else cabalFileHash }
81 return (name, latestVersion, drv)
83-- TODO: We should obtain the list of valid attributes in Nixpkgs at
84-- runtime instead of hard-coding a list of invalid attributes here.
86-- TODO: This list is way overspecified; there are many packages in here
87-- that are referred to in the buildDepends or testDepends section, i.e.
88-- packages that we expect to be available from Hackage (but that
91missingSystemLibraries :: Set String
92missingSystemLibraries = Set.fromList
94 , "accelerate-llvm-multidev"
95 , "accelerate-llvm-native"
96 , "accelerate-llvm-ptx"
116 , "casadi_ipopt_interface"
117 , "casadi_snopt_interface"
120 , "CEGUIOgreRenderer"
192 , "gstreamer-controller"
193 , "gstreamer-dataprotocol"
195 , "gstreamer-plugins-base"
207 , "HGamer3DCAudio015"
226 , "language-css-attoparsec"
234 , "leksah-plugin-pane"
262 , "newrelic-collector-client"
264 , "newrelic-transaction"
277 , "OgreRTShaderSystem"
287 , "opencv_features2d"
312 , "quickcheck-lio-instances"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list