diff --git a/ChangeLog.md b/ChangeLog.md index ca593c00e5..bb6918ff3c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -71,6 +71,9 @@ Other enhancements: e.g. `stack unpack packagename`. * Git repos are shared across multiple projects. See [#3551](https://github.com/commercialhaskell/stack/issues/3551) +* Use en_US.UTF-8 locale by default in pure Nix mode so programs won't + crash because of Unicode in their output + [#4095](https://github.com/commercialhaskell/stack/issues/4095) Bug fixes: diff --git a/src/Stack/Nix.hs b/src/Stack/Nix.hs index ea4cdbe657..6c0b7536d6 100644 --- a/src/Stack/Nix.hs +++ b/src/Stack/Nix.hs @@ -100,6 +100,8 @@ runShellAndExit mprojectRoot getCompilerVersion getCmdArgs = do ,"LD_LIBRARY_PATH = libPath;" -- LD_LIBRARY_PATH is set because for now it's -- needed by builds using Template Haskell ,"STACK_IN_NIX_EXTRA_ARGS = stackExtraArgs; " + -- overriding default locale so Unicode output using base won't be broken + ,"LANG=\"en_US.UTF-8\";" ,"} \"\""]] -- glibcLocales is necessary on Linux to avoid warnings about GHC being incapable to set the locale. fullArgs = concat [if pureShell then ["--pure"] else [] diff --git a/test/integration/tests/4095-utf8-pure-nix/Main.hs b/test/integration/tests/4095-utf8-pure-nix/Main.hs new file mode 100644 index 0000000000..f8999ddc47 --- /dev/null +++ b/test/integration/tests/4095-utf8-pure-nix/Main.hs @@ -0,0 +1,6 @@ +import StackTest + +main :: IO () +main = do + stack ["build", "--nix-pure"] + stack ["exec", "--nix-pure", "ShowUnicode"] diff --git a/test/integration/tests/4095-utf8-pure-nix/files/ShowUnicode.hs b/test/integration/tests/4095-utf8-pure-nix/files/ShowUnicode.hs new file mode 100644 index 0000000000..91011a6576 --- /dev/null +++ b/test/integration/tests/4095-utf8-pure-nix/files/ShowUnicode.hs @@ -0,0 +1,5 @@ +import System.IO (stdout) +import Text.Printf (hPrintf) + +main :: IO () +main = hPrintf stdout "平和" diff --git a/test/integration/tests/4095-utf8-pure-nix/files/package.yaml b/test/integration/tests/4095-utf8-pure-nix/files/package.yaml new file mode 100644 index 0000000000..5ee0230a5f --- /dev/null +++ b/test/integration/tests/4095-utf8-pure-nix/files/package.yaml @@ -0,0 +1,4 @@ +executables: + ShowUnicode: + dependencies: [base] + main: ShowUnicode.hs diff --git a/test/integration/tests/4095-utf8-pure-nix/files/stack.yaml b/test/integration/tests/4095-utf8-pure-nix/files/stack.yaml new file mode 100644 index 0000000000..9673b65de3 --- /dev/null +++ b/test/integration/tests/4095-utf8-pure-nix/files/stack.yaml @@ -0,0 +1 @@ +resolver: lts-11.19