Skip to content

stack list-dependencies: use --system-ghc #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/Stack2nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ import System.FilePath.Glob (glob)
import System.IO.Temp (withSystemTempDirectory)

data Args = Args
{ argRev :: Maybe String
, argOutFile :: Maybe FilePath
, argUri :: String
{ argRev :: Maybe String
, argOutFile :: Maybe FilePath
, argSystemGHC :: Bool
, argUri :: String
}
deriving (Show)

Expand Down Expand Up @@ -100,8 +101,12 @@ packageRenameMap =
, ("servant-server", "servant-server_0_10")
]

stackConfigOpts :: Args -> [String]
stackConfigOpts args =
[ "--system-ghc" | argSystemGHC args ]

stack2nix :: Args -> IO ()
stack2nix Args{..} = do
stack2nix args@Args{..} = do
isLocalRepo <- doesFileExist $ argUri </> "stack.yaml"
if isLocalRepo
then handleStackConfig Nothing argUri
Expand All @@ -119,10 +124,11 @@ stack2nix Args{..} = do
handleStackConfig remoteUri localDir = do
let fname = localDir </> "stack.yaml"
alreadyExists <- doesFileExist fname
unless alreadyExists $ runCmdFrom localDir "stack" ["init"] >> return ()
unless alreadyExists $ runCmdFrom localDir "stack" (["init"] ++ stackConfigOpts args)
>> return ()
contents <- BS.readFile fname
case parseStackYaml contents of
Just config -> toNix remoteUri localDir argOutFile argRev config
Just config -> toNix args remoteUri localDir config
Nothing -> error $ "Failed to parse " <> (localDir </> "stack.yaml")

applyRenameMap :: Map.Map Text Text -> [FilePath] -> IO ()
Expand Down Expand Up @@ -165,8 +171,8 @@ mapPool max' f xs = do
c2nPoolSize :: Int
c2nPoolSize = 4

toNix :: Maybe String -> FilePath -> Maybe FilePath -> Maybe String -> StackConfig -> IO ()
toNix remoteUri baseDir outFile rev StackConfig{..} =
toNix :: Args -> Maybe String -> FilePath -> StackConfig -> IO ()
toNix args@Args{..} remoteUri baseDir StackConfig{..} =
withSystemTempDirectory "s2n" $ \outDir -> do
_ <- mapPool c2nPoolSize (genNixFile outDir) packages
overrides <- mapPool c2nPoolSize overrideFor =<< updateDeps outDir
Expand All @@ -177,15 +183,16 @@ toNix remoteUri baseDir outFile rev StackConfig{..} =
nf <- parseNixFile $ outDir </> "initialPackages.nix"
case nf of
Success expr ->
case outFile of
case argOutFile of
Just fname -> writeFile fname $ defaultNix expr
Nothing -> putStrLn $ defaultNix expr
_ -> error "failed to parse intermediary initialPackages.nix file"
where
updateDeps :: FilePath -> IO [FilePath]
updateDeps outDir = do
putStrLn $ "Updating deps from " ++ baseDir
result <- runCmdFrom baseDir "stack" ["list-dependencies", "--separator", "-"]
result <- runCmdFrom baseDir "stack" (["list-dependencies", "--separator", "-"]
++ stackConfigOpts args)
case result of
Right pkgs -> do
putStrLn "Haskell dependencies:"
Expand All @@ -201,7 +208,7 @@ toNix remoteUri baseDir outFile rev StackConfig{..} =

genNixFile :: FilePath -> Package -> IO ()
genNixFile outDir (LocalPkg relPath) =
cabal2nix (fromMaybe baseDir remoteUri) (pack <$> rev) (Just relPath) (Just outDir)
cabal2nix (fromMaybe baseDir remoteUri) (pack <$> argRev) (Just relPath) (Just outDir)
genNixFile outDir (RemotePkg RemotePkgConf{..}) =
cabal2nix (unpack gitUrl) (Just commit) Nothing (Just outDir)

Expand Down
1 change: 1 addition & 0 deletions stack2nix/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ args :: Parser Args
args = Args
<$> optional (strOption $ long "revision" <> help "revision to use when fetching from VCS")
<*> optional (strOption $ short 'o' <> help "output file for generated nix expression")
<*> (flag False True $ long "system-ghc" <> help "pass --system-ghc to stack invocations")
<*> strArgument (metavar "URI")

main :: IO ()
Expand Down