I have the following simple haskell file (with some nix-shell goodness):
#! /usr/bin/env nix-shell
#! nix-shell --pure -i runghc -p ghc
main = putStrLn "🎉"
but when I run it:
❯ ./emoji.hs
?
I also tried the demo code for the emoji package (https://hackage.haskell.org/package/emoji ), and it’s the same issue. Am I missing something here? What should I do in order to get emojis printing correctly?
gilmi
April 3, 2021, 6:43am
2
works on my machine (without nix stuff). Maybe it’s your terminal or locale settings?
1 Like
Hmm, interesting… I tried a python script with an emoji in the same terminal and it works without issue. Perhaps it’s a nix issue?
juhp
April 3, 2021, 8:53am
4
Maybe check the locale first
This seems to happen because nix-shell --pure
removes the locale env.
You need both an environment variable like LC_ALL
and the locale archive provided by the glibc, e.g. using this command instead: nix-shell --pure -p glibcLocale -i "env LC_ALL=en_US.UTF-8 runghc" -p ghc
3 Likes
Nice! The --pure
does seem to be the issue. I’m a little confused though because
#!/usr/bin/env nix-shell
(*
#!nix-shell --pure -i ocaml -p ocaml
*)
print_string "Hello world! 🚀 \n";;
and
#!/usr/bin/env nix-shell
#!nix-shell --pure -i python3 -p python3
print("🚀")
both work fine…
Is this on non-NixOS? There was an issue about how locales work with relation to non-NixOS and GHC:
opened 07:55PM - 10 Jul 19 UTC
closed 02:14AM - 06 Apr 21 UTC
6.topic: haskell
2.status: stale
## Issue description
I installed `ghc` via Nix and also via Stack. With the `… ghc` binaries provided by Stack, I can easily do Unicode IO. But the Nix `ghc` errors out and pretends to know nothing about Unicode.
### Steps to reproduce
% ghc -e 'putStrLn "x"'
x
% ghc -e 'putStrLn "λ"'
<interactive>:0:11: error:
lexical error in string/character literal at character '\56526'
% stack ghc -- -e 'putStrLn "λ"'
λ
% ghci
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
Prelude> import System.IO
Prelude System.IO> localeEncoding
ASCII
% stack repl
...
Configuring GHCi with the following packages:
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /run/user/1000/haskell-stack-ghci/2a3bbd58/ghci-script
Prelude> import System.IO
Prelude System.IO> localeEncoding
UTF-8
% echo $LANG
en_US.UTF-8
% which stack
/home/kindaro/.nix-profile/bin/stack
% which ghci
/nix/store/67g6vwr5mx26h5mickgw17k2irdx1c0d-ghc-8.6.5/bin/ghci
## Technical details
- system: `"x86_64-linux"`
- host os: `Linux 5.1.16-arch1-1-ARCH, Arch Linux, noversion`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.2.2`
- channels(kindaro): `"nixpkgs-19.09pre184803.d567c486ca5"`
- nixpkgs: `/home/kindaro/.nix-defexpr/channels/nixpkgs`
I’m running on NixOS, but I could imagine that the issues might be related somehow.