@@ -1,6 +1,7 @@
11{-# LANGUAGE FlexibleContexts #-}
22{-# LANGUAGE LambdaCase #-}
33{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TemplateHaskell #-}
45module Obelisk.Command.Project
56 ( InitSource (..)
67 , initProject
@@ -29,6 +30,7 @@ import System.IO.Unsafe (unsafePerformIO)
2930import System.Posix (FileStatus, FileMode, CMode (..), UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
3031import System.Posix.Files
3132import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
33+import System.Which (staticWhich)
3234
3335import GitHub.Data.GitData (Branch)
3436import GitHub.Data.Name (Name)
@@ -241,16 +243,16 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
241243
242244projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
243245projectShell root isPure shellName command = do
246+ let nixPath = $(staticWhich "nix")
247+ nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ proc nixPath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
244248 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
245249 [ "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 []) <>
250+ ["--pure" | isPure] <>
249251 [ "-A"
250252 , "shells." <> shellName
251253 ] <> case command of
252254 Nothing -> []
253− Just c -> ["--run", c]
255+ Just c -> ["--run", "export NIX_PATH=nixpkgs=" <> T.unpack nixpkgsPath <> "; " <> c] -- TODO: Escape nixpkgsPath
254256 void $ liftIO $ waitForProcess ph
255257
256258setCtlc :: CreateProcess -> CreateProcess