@@ -15,6 +15,7 @@ import Distribution.Text
1515import Distribution.Version (Version)
1616import qualified Language.Nix.FilePath as Nix
1717import Language.Nix.PrettyPrinting as PP
18+import Stack.Config (StackResolver, unStackResolver)
1819
1920
2021data OverrideConfig = OverrideConfig
@@ -87,6 +88,28 @@ overrideHaskellPackages oc packages =
8788 , "}"
8889 ]
8990
91+overrideStackage :: StackResolver -> OverrideConfig -> NonEmpty Derivation -> Doc
92+overrideStackage stackResolver oc packages =
93+ let
94+ nixpkgs = if oc ^. ocNixpkgs . to fromString == systemNixpkgs
95+ then systemNixpkgs
96+ else (disp . (fromString :: FilePath -> Nix.FilePath)) (oc ^. ocNixpkgs)
97+ in vcat
98+ [ funargs
99+ [ "nixpkgs ? import " <> nixpkgs <> " {}"
100+ ]
101+ , ""
102+ , "let"
103+ , nest 2 $ vcat
104+ [ "stackPackages ="
105+ , nest 2 $ overridePackages packages <> semi
106+ ]
107+ , "in nixpkgs.haskell.packages.stackage." <> toNixStackResolver stackResolver <> ".override {"
108+ , nest 2
109+ $ attr "packageSetConfig" "self: super: stackPackages { inherit (nixpkgs) pkgs stdenv; inherit (self) callPackage; } super"
110+ , "}"
111+ ]
112+
90113pPrintHaskellPackages :: OverrideConfig -> Doc
91114pPrintHaskellPackages oc =
92115 let
@@ -114,5 +137,10 @@ pPrintHaskellPackages oc =
114137 ]
115138
116139toNixGhcVersion :: Version -> Doc
117−toNixGhcVersion =
118− (<>) "ghc" . text . L.filter (/= '.') . show . disp
140+toNixGhcVersion = (<>) "ghc" . toNixVersion . show . disp
141+
142+toNixStackResolver :: StackResolver -> Doc
143+toNixStackResolver = toNixVersion . unStackResolver
144+
145+toNixVersion :: String -> Doc
146+toNixVersion = text . L.filter (/= '.')