git.iko.soy/typeable/cabal2nix
on master help sign in
PackageList.hs: don't try to guess the Nix attribute -- nix-env can tell us what it is
commit7919758309b106ebc9078b23bce9aedc349da0fc authorPeter Simons <simons@cryp.to> dateTue 16 Aug 2011, 12:34 (15 years ago) parentb472d83
1 file changed+32−32
src/PackageList.hs+32−32
src/PackageList.hs+32−32
@@ -1,51 +1,51 @@
11module Main ( main ) where
22
3−import Text.Regex.Posix
4−import System.Process
5−import Data.Maybe
63import Data.List
4+import Data.Maybe
75import Data.Version
86import Distribution.Text
9−import Distribution.Package
10−import Cabal2Nix.Name
7+import System.Process
8+import Text.Regex.Posix
119
12−regsubmatch :: String -> String -> [String]
13−regsubmatch buf patt = let (_,_,_,x) = f in x
14− where f :: (String,String,String,[String])
15− f = match (makeRegexOpts compExtended execBlank patt) buf
10+type Pkg = (String,Version,String) -- (Name, Version, Attribute)
11+type Pkgset = [Pkg]
1612
17−parseHaskellPackageName :: String -> Maybe (String,Version)
13+parseHaskellPackageName :: String -> Maybe Pkg
1814parseHaskellPackageName name =
19− case name `regsubmatch` "^haskell-(.*)-ghc[0-9.]+-(.*)$" of
20− [name',version] -> case simpleParse version of
21− Just version' -> Just (name',version')
22− _ -> Nothing
15+ case name `regsubmatch` "^(haskellPackages[^ \t]+)[ \t]+haskell-(.*)-ghc[0-9.]+-(.*)$" of
16+ [attr,name',version] -> case simpleParse version of
17+ Just version' -> Just (name',version',attr)
18+ _ -> Nothing
2319 _ -> Nothing
2420
25−stripProfilingTag :: Version -> Version
26−stripProfilingTag (Version v tags) = Version v (filter (/="profiling") tags)
27−
28−getHaskellPackageList :: IO [(String,Version)]
21+getHaskellPackageList :: IO Pkgset
2922getHaskellPackageList = do
30− allPkgs <- fmap lines (readProcess "bash" ["-c", "exec nix-env -qa \\* 2>/dev/tty"] "")
31− let hsPkgs = map parseHaskellPackageName allPkgs
32− pkglist = [ (name, stripProfilingTag version) | Just (name,version) <- hsPkgs ]
33− return (sort (nub pkglist))
23+ allPkgs <- fmap lines (readProcess "bash" ["-c", "exec nix-env -qaP \\* 2>/dev/tty"] "")
24+ let pkgset = map parseHaskellPackageName allPkgs
25+ return (sort (nub (catMaybes pkgset)))
3426
35−selectLatestVersion :: [(String,Version)] -> [(String,Version)]
36−selectLatestVersion = nubBy f2 . sortBy f1
27+stripProfilingVersions :: Pkgset -> Pkgset
28+stripProfilingVersions pkgs = [ p | p@(_,_,attr) <- pkgs , not ("ghc[0-9.]+_profiling" =~ attr) ]
29+
30+selectLatestVersions :: Pkgset -> Pkgset
31+selectLatestVersions = nubBy f2 . sortBy f1
3732 where
38− f1 (n1,v1) (n2,v2)
39− | n1 == n2 = compare v2 v1
40− | otherwise = compare n1 n2
41− f2 (n1,v1) (n2,v2) = n1 == n2
33+ f1 (n1,v1,a1) (n2,v2,a2)
34+ | n1 == n2 = compare v2 v1
35+ | otherwise = compare n1 n2
36+ f2 (n1,_,_) (n2,_,_) = n1 == n2
4237
43−formatPackageLine :: (String,Version) -> String
44−formatPackageLine (n,v) = show (n, showVersion v, Just url)
38+formatPackageLine :: Pkg -> String
39+formatPackageLine (name,version,attr) = show (name, showVersion version, Just url)
4540 where
46− url = "http://hydra.nixos.org/job/nixpkgs/trunk/haskellPackages_ghc704_no_profiling."++toNixName n
41+ url = "http://hydra.nixos.org/job/nixpkgs/trunk/" ++ attr
42+
43+regsubmatch :: String -> String -> [String]
44+regsubmatch buf patt = let (_,_,_,x) = f in x
45+ where f :: (String,String,String,[String])
46+ f = match (makeRegexOpts compExtended execBlank patt) buf
4747
4848main :: IO ()
4949main = do
50− pkgs <- fmap selectLatestVersion getHaskellPackageList
50+ pkgs <- fmap (selectLatestVersions . stripProfilingVersions) getHaskellPackageList
5151 mapM_ (putStrLn . formatPackageLine) pkgs