on master help sign in
Merge pull request #843 from obsidiansystems/fix-project-shells
60d56bcAli Abrar
lib/command/src/Obelisk/Command/Project.hs+17−4
@@ -14,6 +14,7 @@ module Obelisk.Command.Project
14 , nixShellRunProc
14 , nixShellRunProc
15 , nixShellWithHoogle
15 , nixShellWithHoogle
16 , nixShellWithoutPkgs
16 , nixShellWithoutPkgs
17+ , mkObNixShellProc
17 , obeliskDirName
18 , obeliskDirName
18 , toImplDir
19 , toImplDir
19 , toObeliskDir
20 , toObeliskDir
@@ -317,7 +318,7 @@ bashEscape = BSU.toString . bytes . bash . BSU.fromString
317nixShellRunProc :: NixShellConfig -> ProcessSpec
318nixShellRunProc :: NixShellConfig -> ProcessSpec
318nixShellRunProc cfg = setDelegateCtlc True $ proc nixShellPath $ runNixShellConfig cfg
319nixShellRunProc cfg = setDelegateCtlc True $ proc nixShellPath $ runNixShellConfig cfg
319
320
320−nixShellWithoutPkgs
321+mkObNixShellProc
321 :: MonadObelisk m
322 :: MonadObelisk m
322 => FilePath -- ^ Path to project root
323 => FilePath -- ^ Path to project root
323 -> Bool -- ^ Should this be a pure shell?
324 -> Bool -- ^ Should this be a pure shell?
@@ -325,12 +326,12 @@ nixShellWithoutPkgs
325 -> Map Text FilePath -- ^ Package names mapped to their paths
326 -> Map Text FilePath -- ^ Package names mapped to their paths
326 -> String -- ^ Shell attribute to use (e.g. @"ghc"@, @"ghcjs"@, etc.)
327 -> String -- ^ Shell attribute to use (e.g. @"ghc"@, @"ghcjs"@, etc.)
327 -> Maybe String -- ^ If 'Just' run the given command; otherwise just open the interactive shell
328 -> Maybe String -- ^ If 'Just' run the given command; otherwise just open the interactive shell
328− -> m ()
329+ -> m ProcessSpec
329−nixShellWithoutPkgs root isPure chdirToRoot packageNamesAndPaths shellAttr command = do
330+mkObNixShellProc root isPure chdirToRoot packageNamesAndPaths shellAttr command = do
330 packageNamesAndAbsPaths <- liftIO $ for packageNamesAndPaths makeAbsolute
331 packageNamesAndAbsPaths <- liftIO $ for packageNamesAndPaths makeAbsolute
331 defShellConfig <- nixShellRunConfig root isPure command
332 defShellConfig <- nixShellRunConfig root isPure command
332 let setCwd_ = if chdirToRoot then setCwd (Just root) else id
333 let setCwd_ = if chdirToRoot then setCwd (Just root) else id
333− runProcess_ $ setCwd_ $ nixShellRunProc $ defShellConfig
334+ pure $ setCwd_ $ nixShellRunProc $ defShellConfig
334 & nixShellConfig_common . nixCmdConfig_target . target_expr ?~
335 & nixShellConfig_common . nixCmdConfig_target . target_expr ?~
335 "{root, pkgs, shell}: ((import root {}).passthru.__unstable__.self.extend (_: _: {\
336 "{root, pkgs, shell}: ((import root {}).passthru.__unstable__.self.extend (_: _: {\
336 \shellPackages = builtins.fromJSON pkgs;\
337 \shellPackages = builtins.fromJSON pkgs;\
@@ -341,6 +342,18 @@ nixShellWithoutPkgs root isPure chdirToRoot packageNamesAndPaths shellAttr comma
341 , strArg "shell" shellAttr
342 , strArg "shell" shellAttr
342 ]
343 ]
343
344
345+nixShellWithoutPkgs
346+ :: MonadObelisk m
347+ => FilePath -- ^ Path to project root
348+ -> Bool -- ^ Should this be a pure shell?
349+ -> Bool -- ^ Should we chdir to the package root in the shell?
350+ -> Map Text FilePath -- ^ Package names mapped to their paths
351+ -> String -- ^ Shell attribute to use (e.g. @"ghc"@, @"ghcjs"@, etc.)
352+ -> Maybe String -- ^ If 'Just' run the given command; otherwise just open the interactive shell
353+ -> m ()
354+nixShellWithoutPkgs root isPure chdirToRoot packageNamesAndPaths shellAttr command = do
355+ runProcess_ =<< mkObNixShellProc root isPure chdirToRoot packageNamesAndPaths shellAttr command
356+
344nixShellWithHoogle :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
357nixShellWithHoogle :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
345nixShellWithHoogle root isPure shell' command = do
358nixShellWithHoogle root isPure shell' command = do
346 defShellConfig <- nixShellRunConfig root isPure command
359 defShellConfig <- nixShellRunConfig root isPure command
lib/command/src/Obelisk/Command/Run.hs+5−14
@@ -72,16 +72,12 @@ import System.Directory
72import System.Environment (getExecutablePath)
72import System.Environment (getExecutablePath)
73import System.FilePath
73import System.FilePath
74import qualified System.Info
74import qualified System.Info
75−import System.IO (hClose, hGetLine)
76import System.IO.Temp (withSystemTempDirectory)
75import System.IO.Temp (withSystemTempDirectory)
77−import System.Process (CreateProcess (..), StdStream (..))
78
76
79import Obelisk.App (MonadObelisk, getObelisk, runObelisk)
77import Obelisk.App (MonadObelisk, getObelisk, runObelisk)
80import Obelisk.CliApp (
78import Obelisk.CliApp (
81 Severity (..),
79 Severity (..),
82− createProcess_,
83 failWith,
80 failWith,
84− overCreateProcess,
85 proc,
81 proc,
86 putLog,
82 putLog,
87 readCreateProcessWithExitCode,
83 readCreateProcessWithExitCode,
@@ -481,7 +477,7 @@ getGhciSessionSettings (toList -> packageInfos) pathBase useRelativePaths = do
481 -- all paths to 'pathBase'.
477 -- all paths to 'pathBase'.
482 selfExe <- liftIO $ canonicalizePath =<< getExecutablePath
478 selfExe <- liftIO $ canonicalizePath =<< getExecutablePath
483 canonicalPathBase <- liftIO $ canonicalizePath pathBase
479 canonicalPathBase <- liftIO $ canonicalizePath pathBase
484− installedPackageIndex <- loadPackageIndex pathBase
480+ installedPackageIndex <- loadPackageIndex packageInfos pathBase
485
481
486 (pkgFiles, pkgSrcPaths :: [NonEmpty FilePath]) <- fmap unzip $ liftIO $ for packageInfos $ \pkg -> do
482 (pkgFiles, pkgSrcPaths :: [NonEmpty FilePath]) <- fmap unzip $ liftIO $ for packageInfos $ \pkg -> do
487 canonicalSrcDirs <- traverse canonicalizePath $ (_cabalPackageInfo_packageRoot pkg </>) <$> _cabalPackageInfo_sourceDirs pkg
483 canonicalSrcDirs <- traverse canonicalizePath $ (_cabalPackageInfo_packageRoot pkg </>) <$> _cabalPackageInfo_sourceDirs pkg
@@ -514,8 +510,8 @@ getGhciSessionSettings (toList -> packageInfos) pathBase useRelativePaths = do
514 _ -> error $ "Couldn't resolve dependency for " <> prettyShow dep
510 _ -> error $ "Couldn't resolve dependency for " <> prettyShow dep
515
511
516-- Load the package index used by the GHC in this path's nix project
512-- Load the package index used by the GHC in this path's nix project
517−loadPackageIndex :: (MonadObelisk m) => FilePath -> m InstalledPackageIndex
513+loadPackageIndex :: MonadObelisk m => [CabalPackageInfo] -> FilePath -> m InstalledPackageIndex
518−loadPackageIndex root = do
514+loadPackageIndex packageInfos root = do
519 ghcPath <- getPathInNixEnvironment "bash -c 'type -p ghc'"
515 ghcPath <- getPathInNixEnvironment "bash -c 'type -p ghc'"
520 ghcPkgPath <- getPathInNixEnvironment "bash -c 'type -p ghc-pkg'"
516 ghcPkgPath <- getPathInNixEnvironment "bash -c 'type -p ghc-pkg'"
521 (compiler, _platform, programDb) <- liftIO
517 (compiler, _platform, programDb) <- liftIO
@@ -523,13 +519,8 @@ loadPackageIndex root = do
523 liftIO $ getInstalledPackages Verbosity.silent compiler [GlobalPackageDB] programDb
519 liftIO $ getInstalledPackages Verbosity.silent compiler [GlobalPackageDB] programDb
524 where
520 where
525 getPathInNixEnvironment cmd = do
521 getPathInNixEnvironment cmd = do
526− procSpec <- runProc <$> nixShellRunConfig root True (Just cmd)
522+ path <- readProcessAndLogStderr Debug =<< mkObNixShellProc root False True (packageInfoToNamePathMap packageInfos) "ghc" (Just cmd)
527− (_,Just h,_,_) <- createProcess_ "loadPackageIndex" procSpec
528− path <- liftIO $ hGetLine h >>= canonicalizePath
523+ liftIO $ canonicalizePath $ T.unpack $ T.strip path
529− liftIO $ hClose h
530− pure path
531− runProc =
532− overCreateProcess (\cs -> cs { std_out = CreatePipe }) . nixShellRunProc
533
524
534baseGhciOptions :: [String]
525baseGhciOptions :: [String]
535baseGhciOptions =
526baseGhciOptions =