git.iko.soy/typeable/stackage2nix
on master help sign in
Generate subset of Stackage packages
commit75cbdd3109e506a6e589831f7701cd10f20ee8ac authorDmitry Bushev <bushevdv@gmail.com> dateTue 20 Jun 2017, 00:24 (9 years ago) parent9fb6fbd
5 files changed+25−11
nix-test+4−5 src/Runner.hs+17−3 src/Runner/Cli.hs+2−2 stack.yaml+1−1 stack2nix.cabal+1
nix-test+4−5
@@ -1,11 +1,10 @@
11#!/usr/bin/env bash
22
3−LTS_VERSION=${VERSION:-8.15}
4−STACKAGE_BUILD_PLAN_DIR=${STACKAGE_BUILD_PLAN_DIR:-~/lts-haskell}
3+LTS_HASKELL_DIR=${LTS_HASKELL_DIR:-~/lts-haskell}
54ALL_CABAL_HASHES_DIR=${ALL_CABAL_HASHES_DIR:-~/all-cabal-hashes}
65
7−if [ ! -d "$STACKAGE_BUILD_PLAN_DIR" ]; then
8− git clone --depth 1 https://github.com/fpco/lts-haskell.git "$STACKAGE_BUILD_PLAN_DIR"
6+if [ ! -d "$LTS_HASKELL_DIR" ]; then
7+ git clone --depth 1 https://github.com/fpco/lts-haskell.git "$LTS_HASKELL_DIR"
98fi
109
1110if [ ! -d "$ALL_CABAL_HASHES_DIR" ]; then
@@ -14,7 +13,7 @@ fi
1413
1514set -x
1615stack exec -- stack2nix \
17− --stackage-build-plan "$STACKAGE_BUILD_PLAN_DIR/lts-$LTS_VERSION.yaml" \
16+ --lts-haskell "$LTS_HASKELL_DIR" \
1817 --all-cabal-hashes "$ALL_CABAL_HASHES_DIR"
1918set +x
2019
src/Runner.hs+17−3
@@ -1,6 +1,8 @@
11module Runner ( run ) where
22
33import Control.Lens
4+import Distribution.Nixpkgs.Haskell.FromStack
5+import Distribution.Nixpkgs.Haskell.FromStack.Package
46import Distribution.Nixpkgs.Haskell.Stack
57import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
68import Distribution.Version (Version(..))
@@ -8,7 +10,10 @@ import Options.Applicative
810import Runner.Cli
911import Stack.Config
1012import Stackage.Types
13+import System.IO (withFile, IOMode(..), hPutStrLn)
14+import Text.PrettyPrint.HughesPJClass (render)
1115
16+import qualified Data.Map as Map
1217import qualified Stackage2nix as S2n
1318
1419
@@ -16,8 +21,7 @@ run :: IO ()
1621run = do
1722 opts <- execParser pinfo
1823 stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
19− -- generate stackage packages
20− buildPlan <- S2n.run $ mkS2nOptions opts
24+ (buildPlan, packageSetConfig) <- S2n.run $ mkS2nOptions opts
2125 -- generate haskell packages override
2226 let
2327 pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
@@ -27,7 +31,17 @@ run = do
2731 let
2832 out = PP.overrideHaskellPackages overrideConfig packages
2933 writeFile (opts ^. optOutFile) (show out)
30− putStrLn $ "\nDerivation was written to " ++ opts ^. optOutFile
34+ -- generate stackage packages
35+ allNodes <- traverse (uncurry $ buildNodeM packageSetConfig)
36+ $ Map.toList (bpPackages buildPlan)
37+ let nodes = reachableDependencies (mkNode <$> packages) allNodes
38+ withFile (opts ^. optStackageOutPackages) WriteMode $ \h -> do
39+ hPutStrLn h ("# Generated by stack2nix from " ++ opts ^. optStackageBuildPlan)
40+ hPutStrLn h $ render $ pPrintOutPackages (nodeDerivation <$> nodes)
41+ withFile (opts ^. optStackageOutConfig) WriteMode $ \h -> do
42+ hPutStrLn h ("# Generated by stack2nix from " ++ opts ^. optStackageBuildPlan)
43+ hPutStrLn h $ render $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
44+ putStrLn $ "Derivation was written to " ++ opts ^. optOutFile
3145
3246mkOverrideConfig :: Options -> Version -> OverrideConfig
3347mkOverrideConfig opts ghcVersion = OverrideConfig
src/Runner/Cli.hs+2−2
@@ -90,7 +90,7 @@ stackageOutPackages = option str
9090 ( long "nix-stackage-packages"
9191 <> metavar "STACKAGE_PACKAGES"
9292 <> help "name of the output file for the package set"
93− <> value "configuration-packages.nix"
93+ <> value "packages.nix"
9494 <> showDefaultWith id)
9595
9696stackageOutConfig :: Parser FilePath
@@ -98,7 +98,7 @@ stackageOutConfig = option str
9898 ( long "nix-stackage-config"
9999 <> metavar "STACKAGE_CONFIG"
100100 <> help "name of the output file for the package set configuration"
101− <> value "packages.nix"
101+ <> value "configuration-packages.nix"
102102 <> showDefaultWith id)
103103
104104stackYamlArg :: Parser FilePath
stack.yaml+1−1
@@ -3,7 +3,7 @@ packages:
33- '.'
44- location:
55 git: https://github.com/4e6/cabal2nix.git
6− commit: 0e72390addd0a246a7a6cc8640f25b8759fd4e4e
6+ commit: dc21f53c7b5ca36035fc369b13b43507becb80fb
77 extra-dep: true
88extra-deps:
99- distribution-nixpkgs-1.1
stack2nix.cabal+1
@@ -29,6 +29,7 @@ library
2929 , aeson
3030 , bytestring
3131 , cabal2nix >= 2.3
32+ , containers
3233 , deepseq
3334 , distribution-nixpkgs >= 1.1
3435 , filepath