Skip to content

[WIP]: Nix env support for the wrapper #490

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

Closed
Closed
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
20 changes: 17 additions & 3 deletions exe/Wrapper.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{-# LANGUAGE RecordWildCards #-}
-- | This module is based on the hie-wrapper.sh script in
-- https://github.com/alanz/vscode-hie-server
module Main where

import Control.Monad.Extra
Expand Down Expand Up @@ -42,9 +40,25 @@ main = do
VersionMode PrintNumericVersion ->
putStrLn haskellLanguageServerNumericVersion

NixMode nixModeArgs -> loadNixEnv nixArgs

LspMode lspArgs ->
launchHaskellLanguageServer lspArgs

loadNixEnv :: NixArguments -> IO ()
loadNixEnv nixModeArgs = do
s <- doesFileExist $ "shell.nix"
if s then loadNixShell s else do
d <- doesFileExist $ "default.nix"
if d then loadNixShell d else do
die $ "Nix environment requires `shell.nix` or `default.nix`, but none of them was found. Nix environment can be bootstrapped by `cabal2nix --shell . > default.nix`."
where
loadNixShell nixModeArgs = do
nixShell <- findExecutable "nix-shell"
case nixShell of
Nothing -> die $ "`--nix` option was provided, which requires `nix-shell` to load Nix enviroment, but this executable was not found."
Just nsexe -> callProcess nsexe nixModArgs

launchHaskellLanguageServer :: LspArguments -> IO ()
launchHaskellLanguageServer LspArguments{..} = do
whenJust argsCwd setCurrentDirectory
Expand Down Expand Up @@ -104,6 +118,7 @@ getRuntimeGhcVersion' cradle = do
case actionName (cradleOptsProg cradle) of
Stack -> checkToolExists "stack"
Cabal -> checkToolExists "cabal"
Nix -> checkToolExists "nix"
Default -> checkToolExists "ghc"
Direct -> checkToolExists "ghc"
_ -> pure ()
Expand Down Expand Up @@ -143,4 +158,3 @@ findLocalCradle fp = do
Nothing -> loadImplicitCradle fp
hPutStrLn stderr $ "Module \"" ++ fp ++ "\" is loaded by Cradle: " ++ show crdl
return crdl

1 change: 1 addition & 0 deletions src/Ide/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ findProgramVersions :: IO ProgramsOfInterest
findProgramVersions = ProgramsOfInterest
<$> findVersionOf "cabal"
<*> findVersionOf "stack"
<*> findVersionOf "nix"
<*> findVersionOf "ghc"

-- | Find the version of the given program.
Expand Down