@@ -1,22 +1,60 @@
1+{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-}
2+{-# LANGUAGE RecordWildCards #-}
3+
14module Distribution.Nixpkgs.Haskell.Stack where
25
3−import Text.PrettyPrint
6+import Language.Nix
7+import Language.Nix.PrettyPrinting
8+
9+data StackConfig = StackConfig
10+ { stackageVersion :: String }
11+
12+data OverrideConfig = OverrideConfig
13+ { stackageCompilerConfig :: FilePath
14+ -- ^ Nixpkgs compiler config for Stackage packages set
15+ , stackagePackagesConfig :: FilePath
16+ -- ^ Nixpkgs packages config for Stackage packages set
17+ , haskellPackagesOverride :: Identifier
18+ -- ^ 'pkgs.haskell.packages.<compiler>' to override
19+ }
20+
21+overrideConfigFixture :: OverrideConfig
22+overrideConfigFixture = OverrideConfig
23+ { stackageCompilerConfig = "./haskell-modules/configuration-6_30.nix"
24+ , stackagePackagesConfig = "./haskell-modules/packages-6_30.nix"
25+ , haskellPackagesOverride = "ghc7103" }
26+
27+stackageCompilerConfigFun :: FilePath -> Doc
28+stackageCompilerConfigFun p =
29+ funargs [text "superPkgs"] $$ "import" <+> string p
30+ <+> lbrace
31+ <+> text "inherit (superPkgs) pkgs;"
32+ <+> rbrace
33+
34+nixLet :: [Doc] -> Doc
35+nixLet ls = vcat
36+ [ text "let"
37+ , nest 2 $ vcat ls
38+ ]
439
5−nixpkgsOverride :: Doc
6−nixpkgsOverride = vcat
40+nixpkgsOverride :: OverrideConfig -> Doc
41+nixpkgsOverride OverrideConfig {..} = vcat
742 [ text "{ nixpkgs ? import <nixpkgs> {}, compiler ? \"default\" }: "
843 , text ""
9− , text "let"
10− , text " inherit (nixpkgs.stdenv.lib) extends;"
11− , text " packageOverrides = super: let self = super.pkgs; in"
12− , text " {"
13− , text " pkgs = super.pkgs // {"
14− , text " haskell = super.pkgs.haskell // {"
15− , text " packages = super.pkgs.haskell.packages // {"
16− , text " ${compiler} = super.pkgs.haskell.packages.ghc7103.override {};"
17− , text " };"
18− , text " };"
19− , text " };"
20− , text " };"
21− , text "in packageOverrides nixpkgs"
44+ , nixLet
45+ [ text "inherit (nixpkgs.stdenv.lib) extends;"
46+ , attr "stackageCompilerConfig" $ stackageCompilerConfigFun stackageCompilerConfig
47+ , attr "stackagePackagesConfig" $ stackageCompilerConfigFun stackagePackagesConfig
48+ , text "packageOverrides = super: let self = super.pkgs; in"
49+ , text "{"
50+ , text " pkgs = super.pkgs // {"
51+ , text " haskell = super.pkgs.haskell // {"
52+ , text " packages = super.pkgs.haskell.packages // {"
53+ , text " \"${compiler}\" = super.pkgs.haskell.packages." <> disp haskellPackagesOverride <> ".override {};"
54+ , text " };"
55+ , text " };"
56+ , text " };"
57+ , text "};"
58+ , text "in packageOverrides nixpkgs"
59+ ]
2260 ]