git.iko.soy/typeable/stackage2nix
on master help sign in
Generate subset of Stackage packages
75cbdd3Dmitry Bushev
nix-test+4−5
@@ -1,11 +1,10 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2
2
3−LTS_VERSION=${VERSION:-8.15}
3+LTS_HASKELL_DIR=${LTS_HASKELL_DIR:-~/lts-haskell}
4−STACKAGE_BUILD_PLAN_DIR=${STACKAGE_BUILD_PLAN_DIR:-~/lts-haskell}
5ALL_CABAL_HASHES_DIR=${ALL_CABAL_HASHES_DIR:-~/all-cabal-hashes}
4ALL_CABAL_HASHES_DIR=${ALL_CABAL_HASHES_DIR:-~/all-cabal-hashes}
6
5
7−if [ ! -d "$STACKAGE_BUILD_PLAN_DIR" ]; then
6+if [ ! -d "$LTS_HASKELL_DIR" ]; then
8− git clone --depth 1 https://github.com/fpco/lts-haskell.git "$STACKAGE_BUILD_PLAN_DIR"
7+ git clone --depth 1 https://github.com/fpco/lts-haskell.git "$LTS_HASKELL_DIR"
9fi
8fi
10
9
11if [ ! -d "$ALL_CABAL_HASHES_DIR" ]; then
10if [ ! -d "$ALL_CABAL_HASHES_DIR" ]; then
@@ -14,7 +13,7 @@ fi
14
13
15set -x
14set -x
16stack exec -- stack2nix \
15stack exec -- stack2nix \
17− --stackage-build-plan "$STACKAGE_BUILD_PLAN_DIR/lts-$LTS_VERSION.yaml" \
16+ --lts-haskell "$LTS_HASKELL_DIR" \
18 --all-cabal-hashes "$ALL_CABAL_HASHES_DIR"
17 --all-cabal-hashes "$ALL_CABAL_HASHES_DIR"
19set +x
18set +x
20
19
src/Runner.hs+17−3
@@ -1,6 +1,8 @@
1module Runner ( run ) where
1module Runner ( run ) where
2
2
3import Control.Lens
3import Control.Lens
4+import Distribution.Nixpkgs.Haskell.FromStack
5+import Distribution.Nixpkgs.Haskell.FromStack.Package
4import Distribution.Nixpkgs.Haskell.Stack
6import Distribution.Nixpkgs.Haskell.Stack
5import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
7import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
6import Distribution.Version (Version(..))
8import Distribution.Version (Version(..))
@@ -8,7 +10,10 @@ import Options.Applicative
8import Runner.Cli
10import Runner.Cli
9import Stack.Config
11import Stack.Config
10import Stackage.Types
12import Stackage.Types
13+import System.IO (withFile, IOMode(..), hPutStrLn)
14+import Text.PrettyPrint.HughesPJClass (render)
11
15
16+import qualified Data.Map as Map
12import qualified Stackage2nix as S2n
17import qualified Stackage2nix as S2n
13
18
14
19
@@ -16,8 +21,7 @@ run :: IO ()
16run = do
21run = do
17 opts <- execParser pinfo
22 opts <- execParser pinfo
18 stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
23 stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
19− -- generate stackage packages
20− buildPlan <- S2n.run $ mkS2nOptions opts
24+ (buildPlan, packageSetConfig) <- S2n.run $ mkS2nOptions opts
21 -- generate haskell packages override
25 -- generate haskell packages override
22 let
26 let
23 pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
27 pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
@@ -27,7 +31,17 @@ run = do
27 let
31 let
28 out = PP.overrideHaskellPackages overrideConfig packages
32 out = PP.overrideHaskellPackages overrideConfig packages
29 writeFile (opts ^. optOutFile) (show out)
33 writeFile (opts ^. optOutFile) (show out)
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
30− putStrLn $ "\nDerivation was written to " ++ opts ^. optOutFile
44+ putStrLn $ "Derivation was written to " ++ opts ^. optOutFile
31
45
32mkOverrideConfig :: Options -> Version -> OverrideConfig
46mkOverrideConfig :: Options -> Version -> OverrideConfig
33mkOverrideConfig opts ghcVersion = OverrideConfig
47mkOverrideConfig opts ghcVersion = OverrideConfig
src/Runner/Cli.hs+2−2
@@ -90,7 +90,7 @@ stackageOutPackages = option str
90 ( long "nix-stackage-packages"
90 ( long "nix-stackage-packages"
91 <> metavar "STACKAGE_PACKAGES"
91 <> metavar "STACKAGE_PACKAGES"
92 <> help "name of the output file for the package set"
92 <> help "name of the output file for the package set"
93− <> value "configuration-packages.nix"
93+ <> value "packages.nix"
94 <> showDefaultWith id)
94 <> showDefaultWith id)
95
95
96stackageOutConfig :: Parser FilePath
96stackageOutConfig :: Parser FilePath
@@ -98,7 +98,7 @@ stackageOutConfig = option str
98 ( long "nix-stackage-config"
98 ( long "nix-stackage-config"
99 <> metavar "STACKAGE_CONFIG"
99 <> metavar "STACKAGE_CONFIG"
100 <> help "name of the output file for the package set configuration"
100 <> help "name of the output file for the package set configuration"
101− <> value "packages.nix"
101+ <> value "configuration-packages.nix"
102 <> showDefaultWith id)
102 <> showDefaultWith id)
103
103
104stackYamlArg :: Parser FilePath
104stackYamlArg :: Parser FilePath
stack.yaml+1−1
@@ -3,7 +3,7 @@ packages:
3- '.'
3- '.'
4- location:
4- location:
5 git: https://github.com/4e6/cabal2nix.git
5 git: https://github.com/4e6/cabal2nix.git
6− commit: 0e72390addd0a246a7a6cc8640f25b8759fd4e4e
6+ commit: dc21f53c7b5ca36035fc369b13b43507becb80fb
7 extra-dep: true
7 extra-dep: true
8extra-deps:
8extra-deps:
9- distribution-nixpkgs-1.1
9- distribution-nixpkgs-1.1
stack2nix.cabal+1
@@ -29,6 +29,7 @@ library
29 , aeson
29 , aeson
30 , bytestring
30 , bytestring
31 , cabal2nix >= 2.3
31 , cabal2nix >= 2.3
32+ , containers
32 , deepseq
33 , deepseq
33 , distribution-nixpkgs >= 1.1
34 , distribution-nixpkgs >= 1.1
34 , filepath
35 , filepath