git.iko.soy/typeable/cabal2nix
on master help sign in
hackage2nix: add code that reads Stackage's build plans
commitfaf50c299cf3752c1eda894d84c89be282c38a5e authorPeter Simons <simons@cryp.to> dateFri 11 Sep 2015, 23:44 (11 years ago) parenta5d25d8
4 files changed+83−1
hackage2nix/hackage2nix.cabal+2 hackage2nix/package.yaml+2 hackage2nix/src/Stackage.hs+78 release.nix+1−1
hackage2nix/hackage2nix.cabal+2
@@ -38,8 +38,10 @@ executable hackage2nix
3838 , mtl
3939 , optparse-applicative
4040 , pretty >= 1.1.2
41+ , stackage-types
4142 , text
4243 , yaml
4344 other-modules:
4445 Paths_hackage2nix
46+ Stackage
4547 default-language: Haskell2010
hackage2nix/package.yaml+2
@@ -23,6 +23,7 @@ dependencies:
2323 - mtl
2424 - optparse-applicative
2525 - pretty >= 1.1.2
26+ - stackage-types
2627 - text
2728 - yaml
2829
@@ -32,6 +33,7 @@ executables:
3233 source-dirs: src
3334 other-modules:
3435 - Paths_hackage2nix
36+ - Stackage
3537 ghc-options:
3638 - -threaded
3739 - -rtsopts
hackage2nix/src/Stackage.hsnew file+78
@@ -0,0 +1,78 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE StandaloneDeriving #-}
3+{-# OPTIONS_GHC -fno-warn-orphans #-}
4+
5+module Stackage where
6+
7+import Control.DeepSeq.Generics
8+import Control.Monad
9+import Control.Monad.Par.Combinator
10+import Control.Monad.Par.IO
11+import Control.Monad.Trans
12+import Data.Map as Map
13+import Data.Maybe
14+import Data.Yaml ( decodeFile )
15+import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
16+import Distribution.Package
17+import Distribution.PackageDescription
18+import Distribution.Version
19+import GHC.Generics ( Generic )
20+import Stackage.Types hiding ( display )
21+import System.Directory
22+import System.FilePath
23+import Text.Show.Pretty
24+import Distribution.Compiler
25+
26+yo :: IO ()
27+yo = readView "/home/simons/src/cabal2nix/hackage2nix/stackage-nightly/nightly-2015-09-11.yaml" >>= putStrLn . ppShow
28+
29+data Spec = Spec
30+ { version :: Version
31+ , flagOverrides :: (Map FlagName Bool)
32+ , runTests :: Bool
33+ , runHaddock :: Bool
34+ , runLinuxBuilds :: Bool
35+ }
36+ deriving (Show, Eq, Ord, Generic)
37+
38+data View = View
39+ { compiler :: CompilerId
40+ , corePackages :: Map PackageName Version
41+ , packages :: Map PackageName Spec
42+ }
43+ deriving (Show, Generic)
44+
45+instance NFData Spec where
46+instance NFData View where
47+
48+views :: IO [View]
49+views = runParIO $ readStackage "lts-haskell"
50+
51+readStackage :: FilePath -> ParIO [View]
52+readStackage dirPath = do
53+ filePaths <- liftIO (listFiles dirPath)
54+ parMapM (liftIO . readView) [ dirPath </> p | p <- filePaths, takeExtension p == ".yaml" ]
55+
56+readView :: FilePath -> IO View
57+readView = fmap fromBuildPlan . readBuildPlan
58+
59+fromBuildPlan :: BuildPlan -> View
60+fromBuildPlan bp = View (CompilerId GHC (siGhcVersion (bpSystemInfo bp)))
61+ (siCorePackages (bpSystemInfo bp))
62+ (Map.map fromPackagePlan (bpPackages bp))
63+
64+fromPackagePlan :: PackagePlan -> Spec
65+fromPackagePlan pp = Spec (ppVersion pp)
66+ (pcFlagOverrides ppc)
67+ (pcTests ppc == ExpectSuccess)
68+ (pcHaddocks ppc == ExpectSuccess)
69+ (pcSkipBuild ppc)
70+ where ppc = ppConstraints pp
71+
72+readBuildPlan :: FilePath -> IO BuildPlan
73+readBuildPlan = fmap fromJust . decodeFile
74+
75+listFiles :: FilePath -> IO [FilePath]
76+listFiles path = do
77+ let isFile p = doesFileExist (path </> p)
78+ getDirectoryContents path >>= filterM isFile . Prelude.filter (\x -> head x /= '.')
release.nix+1−1
@@ -15,7 +15,7 @@ let
1515 mkDerivation = args: super.mkDerivation (args // {
1616 src = cabal2nixSrc;
1717 version = cabal2nixSrc.gitTag;
18− libraryHaskellDepends = args.libraryHaskellDepends or [] ++ [self.yaml];
18+ libraryHaskellDepends = args.libraryHaskellDepends or [] ++ [self.yaml self.stackage-types];
1919 });
2020 });
2121