Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Behavior changes:
* Following a change to the Stackage project's server API, the default value of
the `urls` key includes
`recent-snapshots: https://stackage.org/api/v1/snapshots`.
* The `--[no-]keep-ghc-rts` flag of Stack's `config env` command is now enabled
by default, consistent with Stack's `exec` command.

Other enhancements:

Expand Down Expand Up @@ -58,6 +60,9 @@ Bug fixes:
* Stack's `config set` commands will recreate the `global-project` directory
contents, if Stack needs to consult its project-level configuration file and
there is no file.
* The output of Stack's `path --bin-path` command is now consistent with the
Stack environment in Stack's `exec` command and includes the `bin` directory
of Stack's local install root directory.

## v3.9.3 - 2026-02-19

Expand Down
2 changes: 1 addition & 1 deletion doc/commands/config_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ script that is output:
or not
* `--[no-]locale-utf8` (disabled by default) set the `GHC_CHARENC`
environment variable to `UTF-8` or not
* `--[no-]keep-ghc-rts` (disabled by default) keep/discard any `GHCRTS`
* `--[no-]keep-ghc-rts` (enabled by default) keep/discard any `GHCRTS`
environment variable

The command also accepts flags and options of the
Expand Down
8 changes: 2 additions & 6 deletions doc/topics/stack_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

Command
[`stack config env`](../commands/config_command.md#the-stack-config-env-command)
to see how the PATH is defined in the Stack environment.

Alternatively, command
[`stack path --bin-path`](../commands/path_command.md) to see the PATH
excluding the project Stack work directory's `bin` directory (see further
below).
or [`stack path --bin-path`](../commands/path_command.md) to see how the PATH is
defined in the Stack environment.

In that environment, Stack adds certain directories to the start of the PATH.
The directories added are set out below, in order of search priority.
Expand Down
39 changes: 29 additions & 10 deletions src/Stack/Options/ConfigEnvParser.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedRecordDot #-}

{-|
Module : Stack.Options.ConfigEnvParser
Expand All @@ -14,16 +15,34 @@ module Stack.Options.ConfigEnvParser
import qualified Options.Applicative as OA
import Options.Applicative.Builder.Extra ( boolFlags )
import Stack.Prelude
import Stack.Types.EnvSettings ( EnvSettings (..) )
import Stack.Types.EnvSettings
( EnvSettings (..), defaultEnvSettings )

-- | Parse command line arguments for Stack's @config env@ command.
configCmdEnvParser :: OA.Parser EnvSettings
configCmdEnvParser = EnvSettings
<$> boolFlags True "locals" "include information about local packages" mempty
<*> boolFlags True
"ghc-package-path" "set GHC_PACKAGE_PATH environment variable" mempty
<*> boolFlags True "stack-exe" "set STACK_EXE environment variable" mempty
<*> boolFlags False
"locale-utf8" "set the GHC_CHARENC environment variable to UTF-8" mempty
<*> boolFlags False
"keep-ghc-rts" "keep any GHCRTS environment variable" mempty
<$> boolFlags
defaultEnvSettings.includeLocals
"locals"
"include information about local packages"
mempty
<*> boolFlags
defaultEnvSettings.includeGhcPackagePath
"ghc-package-path"
"set GHC_PACKAGE_PATH environment variable"
mempty
<*> boolFlags
defaultEnvSettings.stackExe
"stack-exe"
"set STACK_EXE environment variable"
mempty
<*> boolFlags
defaultEnvSettings.localeUtf8
"locale-utf8"
"set the GHC_CHARENC environment variable to UTF-8"
mempty
<*> boolFlags
defaultEnvSettings.keepGhcRts
"keep-ghc-rts"
"keep any GHCRTS environment variable"
mempty
16 changes: 9 additions & 7 deletions src/Stack/Options/ExecParser.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedRecordDot #-}

{-|
Module : Stack.Options.ExecParser
Expand All @@ -23,7 +24,8 @@ import Stack.Exec
( ExecOpts (..), ExecOptsExtra (..), SpecialExecCmd (..) )
import Stack.Options.Completion ( projectExeCompleter )
import Stack.Prelude
import Stack.Types.EnvSettings ( EnvSettings (..) )
import Stack.Types.EnvSettings
( EnvSettings (..), defaultEnvSettings )

-- | Parse command line arguments for Stack's @exec@, @ghc@, @run@,
-- @runghc@ and @runhaskell@ commands.
Expand Down Expand Up @@ -57,18 +59,18 @@ execOptsExtraParser = ExecOptsExtra
<*> eoCwdParser
where
eoEnvSettingsParser :: Parser EnvSettings
eoEnvSettingsParser = EnvSettings True
<$> boolFlags True
eoEnvSettingsParser = EnvSettings defaultEnvSettings.includeLocals
<$> boolFlags defaultEnvSettings.includeGhcPackagePath
"ghc-package-path"
"setting the GHC_PACKAGE_PATH variable for the subprocess."
idm
<*> boolFlags True
<*> boolFlags defaultEnvSettings.stackExe
"stack-exe"
"setting the STACK_EXE environment variable to the path for the \
\stack executable."
idm
<*> pure False
<*> pure True
<*> pure defaultEnvSettings.localeUtf8
<*> pure defaultEnvSettings.keepGhcRts

eoPackagesParser :: Parser [String]
eoPackagesParser = many (strOption
Expand Down
14 changes: 8 additions & 6 deletions src/Stack/Path.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Stack.Types.EnvConfig
, packageDatabaseLocal
)
import qualified Stack.Types.EnvConfig as EnvConfig
import Stack.Types.EnvSettings ( defaultEnvSettings )
import Stack.Types.GHCVariant ( HasGHCVariant (..) )
import Stack.Types.GlobalOpts
( GlobalOpts (..), globalOptsBuildOptsMonoidL )
Expand Down Expand Up @@ -123,7 +124,13 @@ printKeys extractors single info = do
T.putStrLn $ prefix <> extractPath info

runHaddockWithEnvConfig :: Bool -> RIO EnvConfig () -> RIO Runner ()
runHaddockWithEnvConfig x action = runHaddock x (withDefaultEnvConfig action)
runHaddockWithEnvConfig x action = runHaddock x $
withDefaultEnvConfig $ do
config <- view configL
menv <- liftIO $ config.processContextSettings defaultEnvSettings
-- Required, as otherwise (due to withDefaultEnvConfig) the environment is
-- based on Stack.Type.EnvSettings.minimalEnvSettings.
withProcessContext menv action

runHaddockWithConfig :: RIO Config () -> RIO Runner ()
runHaddockWithConfig = runHaddock False
Expand All @@ -140,11 +147,6 @@ fillEnvConfigPathInfo = do
-- We must use a BuildConfig from an EnvConfig to ensure that it contains the
-- full environment info including GHC paths etc.
buildConfig <- view $ envConfigL . buildConfigL
-- This is the modified 'bin-path',
-- including the local GHC or MSYS if not configured to operate on
-- global GHC.
-- It was set up in 'withBuildConfigAndLock -> withBuildConfigExt -> setupEnv'.
-- So it's not the *minimal* override path.
snapDb <- packageDatabaseDeps
localDb <- packageDatabaseLocal
extraDbs <- packageDatabaseExtra
Expand Down
Loading