@@ -1,73 +0,0 @@
1−module Main ( main ) where
2−
3−import Control.Exception ( assert )
4−import Control.Monad ( when, filterM )
5−import Data.Char ( toLower )
6−import Data.List ( nubBy, sortBy )
7−import Data.Ord ( comparing )
8−import Data.Version ( Version(..) )
9−import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
10−import Distribution.Text ( simpleParse, display )
11−import System.Directory ( doesDirectoryExist, doesFileExist )
12−import System.FilePath ( (</>), (<.>) )
13−import System.Process ( readProcess )
14−import Text.Regex.Posix ( (=~), match, makeRegexOpts, compExtended, execBlank )
15−
16−type Pkg = (String,Version,String) -- (Name, Version, Attribute)
17−type Pkgset = [Pkg]
18−
19−comparePkgByVersion :: Pkg -> Pkg -> Ordering -- prefers the latest version
20−comparePkgByVersion (n1,v1,a1) (n2,v2,a2)
21− | a1 == a2 = assert (n1 == n2) (compare v2 v1)
22− | otherwise = compare a2 a1
23−
24−comparePkgByName :: Pkg -> Pkg-> Ordering
25−comparePkgByName (n1,_,_) (n2,_,_) = comparing (map toLower) n1 n2
26−
27−parseHaskellPackageName :: String -> Maybe Pkg
28−parseHaskellPackageName name =
29− case name `regsubmatch` "^(haskellPackages[^ \t]+)[ \t]+(.+)$" of
30− [attr,name'] -> case name' `regsubmatch` "^haskell-(.+)-ghc[0-9.]+-(.+)$" of
31− [name'',version] -> case simpleParse version of
32− Just version' -> Just (name'',version',attr)
33− _ -> error ("cannot parse " ++ show name)
34− _ -> case simpleParse name' of
35− Just (PackageIdentifier (PackageName n) v) -> Just (n,v,attr)
36− _ -> error ("cannot parse " ++ show name)
37− _ -> Nothing
38−
39−getHaskellPackageList :: IO Pkgset
40−getHaskellPackageList = do
41− allPkgs <- fmap lines (readProcess "bash" ["-c", "exec nix-env -qaP \\* 2>/dev/tty"] "")
42− return [ p | Just p <- map parseHaskellPackageName allPkgs ]
43−
44−stripProfilingVersions :: Pkgset -> Pkgset
45−stripProfilingVersions pkgs = [ p | p@(_,_,attr) <- pkgs , not (attr =~ "ghc[0-9.]+_profiling") ]
46−
47−stripGhc721Versions :: Pkgset -> Pkgset
48−stripGhc721Versions pkgs = [ p | p@(_,_,attr) <- pkgs , not (attr =~ "ghc721") ]
49−
50−selectLatestVersions :: Pkgset -> Pkgset
51−selectLatestVersions = nubBy (\x y -> comparePkgByName x y == EQ) . sortBy comparePkgByVersion
52−
53−isHackagePackage :: Pkg -> IO Bool
54−isHackagePackage (name,version,_) = doesFileExist path
55− where path = "/dev/shm/hackage/" </> name </> display version </> name <.> "cabal"
56−
57−formatPackageLine :: Pkg -> String
58−formatPackageLine (name,version,attr) = show (name, display version, Just url)
59− where
60− url = "http://hydra.nixos.org/job/nixpkgs/trunk/" ++ attr
61−
62−regsubmatch :: String -> String -> [String]
63−regsubmatch buf patt = let (_,_,_,x) = f in x
64− where f :: (String,String,String,[String])
65− f = match (makeRegexOpts compExtended execBlank patt) buf
66−
67−main :: IO ()
68−main = do
69− haveHackage <- doesDirectoryExist "/dev/shm/hackage"
70− when (not haveHackage) (fail "cannot find hackage database at /dev/shm/hackage")
71− pkgset' <- fmap (selectLatestVersions . stripGhc721Versions . stripProfilingVersions) getHaskellPackageList
72− pkgset <- filterM isHackagePackage pkgset'
73− mapM_ (putStrLn . formatPackageLine) (sortBy comparePkgByName pkgset)