@@ -6,6 +6,9 @@ module Obelisk.Command.Project
66 , findProjectObeliskCommand
77 , findProjectRoot
88 , initProject
9+ , nixShellRunConfig
10+ , nixShellRunProc
11+ , nixShellWithHoogle
912 , nixShellWithPkgs
1013 , obeliskDirName
1114 , projectShell
@@ -253,31 +256,50 @@ toNixPath :: FilePath -> FilePath
253256toNixPath root | "/" `isInfixOf` root = root
254257 | otherwise = "./" <> root
255258
256−nixShellWithPkgs :: MonadObelisk m => FilePath -> Bool -> Map Text FilePath -> Maybe String -> m ()
257−nixShellWithPkgs root isPure packageNamesAndPaths command = do
258− packageNamesAndAbsPaths <- liftIO $ for packageNamesAndPaths makeAbsolute
259+nixShellRunConfig :: MonadObelisk m => FilePath -> Bool -> Maybe String -> m NixShellConfig
260+nixShellRunConfig root isPure command = do
259261 nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ setCwd (Just root) $
260262 proc nixExePath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
261263 nixRemote <- liftIO $ lookupEnv "NIX_REMOTE"
262− (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setDelegateCtlc True $ setCwd (Just root) $ proc "nix-shell" $
263− runNixShellConfig $ def
264− & nixShellConfig_pure .~ isPure
265− & nixShellConfig_common . nixCmdConfig_target .~ (def
266− & target_path .~ Nothing
267− & target_expr ?~
268− "{root, pkgs}: ((import root {}).passthru.__unstable__.self.extend (self: super: {\
269− \shellPackages = builtins.fromJSON pkgs; })\
270− \).project.shells.ghc"
271− )
272− & nixShellConfig_common . nixCmdConfig_args .~
273− [ rawArg "root" $ toNixPath root
274− , strArg "pkgs" (T.unpack $ decodeUtf8 $ BSL.toStrict $ Json.encode packageNamesAndAbsPaths)
275− ]
276− & nixShellConfig_run .~ (command <&> \c -> mconcat
277− [ "export NIX_PATH=nixpkgs=", T.unpack nixpkgsPath, "; "
278− , maybe "" (\v -> "export NIX_REMOTE=" <> v <> "; ") nixRemote
279− , c
280− ])
264+ pure $ def
265+ & nixShellConfig_pure .~ isPure
266+ & nixShellConfig_common . nixCmdConfig_target .~ (def & target_path .~ Nothing)
267+ & nixShellConfig_run .~ (command <&> \c -> mconcat
268+ [ "export NIX_PATH=nixpkgs=", T.unpack nixpkgsPath, "; "
269+ , maybe "" (\v -> "export NIX_REMOTE=" <> v <> "; ") nixRemote
270+ , c
271+ ])
272+
273+nixShellRunProc :: FilePath -> NixShellConfig -> ProcessSpec
274+nixShellRunProc root cfg = setDelegateCtlc True $ setCwd (Just root) $ proc "nix-shell" $ runNixShellConfig cfg
275+
276+nixShellWithPkgs :: MonadObelisk m => FilePath -> Bool -> Map Text FilePath -> Maybe String -> m ()
277+nixShellWithPkgs root isPure packageNamesAndPaths command = do
278+ packageNamesAndAbsPaths <- liftIO $ for packageNamesAndPaths makeAbsolute
279+ defShellConfig <- nixShellRunConfig root isPure command
280+ (_, _, _, ph) <- createProcess_ "nixShellWithPkgs" $ nixShellRunProc root $ defShellConfig
281+ & nixShellConfig_common . nixCmdConfig_target . target_expr ?~
282+ "{root, pkgs}: ((import root {}).passthru.__unstable__.self.extend (_: _: {\
283+ \shellPackages = builtins.fromJSON pkgs;\
284+ \})).project.shells.ghc"
285+ & nixShellConfig_common . nixCmdConfig_args .~
286+ [ rawArg "root" $ toNixPath root
287+ , strArg "pkgs" (T.unpack $ decodeUtf8 $ BSL.toStrict $ Json.encode packageNamesAndAbsPaths)
288+ ]
289+ void $ liftIO $ waitForProcess ph
290+
291+nixShellWithHoogle :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
292+nixShellWithHoogle root isPure shell' command = do
293+ defShellConfig <- nixShellRunConfig root isPure command
294+ (_, _, _, ph) <- createProcess_ "nixShellWithHoogle" $ nixShellRunProc root $ defShellConfig
295+ & nixShellConfig_common . nixCmdConfig_target . target_expr ?~
296+ "{root, shell}: ((import root {}).passthru.__unstable__.self.extend (_: super: {\
297+ \userSettings = super.userSettings // { withHoogle = true; };\
298+ \})).project.shells.${shell}"
299+ & nixShellConfig_common . nixCmdConfig_args .~
300+ [ rawArg "root" $ toNixPath root
301+ , strArg "shell" shell'
302+ ]
281303 void $ liftIO $ waitForProcess ph
282304
283305projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()