Unverified Commit a68028ac authored by ttuegel's avatar ttuegel
Browse files

Nix: instantiate expressions in fake Nix shell

cabal2nix recently changed its generated expressions to read the
IN_NIX_SHELL environment variable. Now we need to set this variable when
calling nix-instantiate to produce the same result as calling nix-shell.
parent b758e1ad
......@@ -14,12 +14,13 @@ module Distribution.Client.Nix
import Control.Applicative ((<$>))
import Control.Exception (catch)
import Control.Exception (bracket, catch)
import Control.Monad (filterM, when, unless)
import System.Directory
( createDirectoryIfMissing, doesDirectoryExist, doesFileExist
, makeAbsolute, removeDirectoryRecursive, removeFile )
import System.Environment (getExecutablePath, getArgs, lookupEnv)
import System.Environment
( getExecutablePath, getArgs, lookupEnv, setEnv, unsetEnv )
import System.FilePath
( (</>), (<.>), replaceExtension, takeDirectory, takeFileName )
import System.IO (IOMode(..), hClose, openFile)
......@@ -70,6 +71,18 @@ findNixExpr globalFlags config = do
else return Nothing
-- set IN_NIX_SHELL so that builtins.getEnv in Nix works as in nix-shell
inFakeNixShell :: IO a -> IO a
inFakeNixShell f =
bracket (fakeEnv "IN_NIX_SHELL" "1") (resetEnv "IN_NIX_SHELL") (\_ -> f)
fakeEnv var new = do
old <- lookupEnv var
setEnv var new
return old
resetEnv var = maybe (unsetEnv var) (setEnv var)
:: Verbosity
-> FilePath
......@@ -98,8 +111,9 @@ nixInstantiate verb dist force globalFlags config =
removeGCRoots verb dist
touchFile timestamp
_ <- getDbProgramOutput verb prog progdb
[ "--add-root", shellDrv, "--indirect", shellNix ]
_ <- inFakeNixShell
(getDbProgramOutput verb prog progdb
[ "--add-root", shellDrv, "--indirect", shellNix ])
return ()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment