@@ -1,6 +1,7 @@
1{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TemplateHaskell #-}
4module Obelisk.Command.Project
5module Obelisk.Command.Project
5 ( InitSource (..)
6 ( InitSource (..)
6 , initProject
7 , initProject
@@ -23,12 +24,14 @@ import Data.Bits
23import Data.Function (on)
24import Data.Function (on)
24import qualified Data.Text as T
25import qualified Data.Text as T
25import System.Directory
26import System.Directory
27+import System.Environment (lookupEnv)
26import System.FilePath
28import System.FilePath
27import System.IO.Temp
29import System.IO.Temp
28import System.IO.Unsafe (unsafePerformIO)
30import System.IO.Unsafe (unsafePerformIO)
29import System.Posix (FileStatus, FileMode, CMode (..), UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
31import System.Posix (FileStatus, FileMode, CMode (..), UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
30import System.Posix.Files
32import System.Posix.Files
31import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
33import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
34+import System.Which (staticWhich)
33import GitHub.Data.GitData (Branch)
36import GitHub.Data.GitData (Branch)
34import GitHub.Data.Name (Name)
37import GitHub.Data.Name (Name)
@@ -241,16 +244,23 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
242projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
245projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
243projectShell root isPure shellName command = do
246projectShell 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"
244 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
250 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
245 [ "default.nix"] <>
251 [ "default.nix"] <>
246− -- Keep $NIX_PATH in the env for --pure shells so '<nixpkgs>' works in sub-commands
252+ ["--pure" | isPure] <>
247− -- TODO: Don't use <nixpkgs> for anything!
248− (if isPure then [ "--pure", "--keep", "NIX_PATH" ] else []) <>
250 , "shells." <> shellName
254 , "shells." <> shellName
251 ] <> case command of
255 ] <> case command of
252 Nothing -> []
256 Nothing -> []
253− Just c -> ["--run", c]
257+ Just c ->
258+ -- TODO: Escape nixpkgsPath and nixRemote
260+ , "export NIX_PATH=nixpkgs=" <> T.unpack nixpkgsPath <> "; " <>
261+ maybe "" (\v -> "export NIX_REMOTE=" <> v <> "; ") nixRemote <>
254 void $ liftIO $ waitForProcess ph
264 void $ liftIO $ waitForProcess ph
256setCtlc :: CreateProcess -> CreateProcess
266setCtlc :: CreateProcess -> CreateProcess