@@ -1,6 +1,7 @@
11{-# LANGUAGE FlexibleContexts #-}
22{-# LANGUAGE LambdaCase #-}
33{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TemplateHaskell #-}
45module Obelisk.Command.Project
56 ( InitSource (..)
67 , initProject
@@ -23,12 +24,14 @@ import Data.Bits
2324import Data.Function (on)
2425import qualified Data.Text as T
2526import System.Directory
27+import System.Environment (lookupEnv)
2628import System.FilePath
2729import System.IO.Temp
2830import System.IO.Unsafe (unsafePerformIO)
2931import System.Posix (FileStatus, FileMode, CMode (..), UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
3032import System.Posix.Files
3133import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
34+import System.Which (staticWhich)
3235
3336import GitHub.Data.GitData (Branch)
3437import GitHub.Data.Name (Name)
@@ -241,16 +244,23 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
241244
242245projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
243246projectShell root isPure shellName command = do
247+ let nixPath = $(staticWhich "nix")
248+ nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ proc nixPath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
249+ nixRemote <- liftIO $ lookupEnv "NIX_REMOTE"
244250 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
245251 [ "default.nix"] <>
246− -- Keep $NIX_PATH in the env for --pure shells so '<nixpkgs>' works in sub-commands
247− -- TODO: Don't use <nixpkgs> for anything!
248− (if isPure then [ "--pure", "--keep", "NIX_PATH" ] else []) <>
252+ ["--pure" | isPure] <>
249253 [ "-A"
250254 , "shells." <> shellName
251255 ] <> case command of
252256 Nothing -> []
253− Just c -> ["--run", c]
257+ Just c ->
258+ -- TODO: Escape nixpkgsPath and nixRemote
259+ [ "--run"
260+ , "export NIX_PATH=nixpkgs=" <> T.unpack nixpkgsPath <> "; " <>
261+ maybe "" (\v -> "export NIX_REMOTE=" <> v <> "; ") nixRemote <>
262+ c
263+ ]
254264 void $ liftIO $ waitForProcess ph
255265
256266setCtlc :: CreateProcess -> CreateProcess