Emojis only print as "?"

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?

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?

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


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";;


#!/usr/bin/env nix-shell
#!nix-shell --pure -i python3 -p python3

both work fine…

Is this on non-NixOS? There was an issue about how locales work with relation to non-NixOS and GHC:

I’m running on NixOS, but I could imagine that the issues might be related somehow.