on 005462e help sign in
32 lines 1.0 kB history raw
1module Stackage.Init (stackageInit) where
3import Data.List (isInfixOf, isPrefixOf)
4import Stackage.Util
5import System.FilePath ((</>))
7stackageInit :: IO ()
8stackageInit = do
9 c <- getCabalRoot
10 let config = c </> "config"
11 orig <- readFile config
12 -- bypass laziness
13 _ <- return $! length orig
14 writeFile config $ unlines $ go $ lines orig
15 where
16 go = addStackage
17 . map commentHackage
18 . filter (\s -> not $ "stackage" `isInfixOf` s)
20 addStackage [] = stackageLines []
21 addStackage (l:ls)
22 | "remote-repo-cache:" `isPrefixOf` l = stackageLines $ l : ls
23 | otherwise = l : addStackage ls
25 stackageLines x =
26 "remote-repo: stackage:http://hackage.haskell.org/packages/archive"
27 : "remote-repo: stackage-extra:http://hackage.haskell.org/packages/archive"
28 : x
30 commentHackage s
31 | s == "remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive" = "--" ++ s
32 | otherwise = s