nix package manager: perl warning: Setting locale failed

Whenever I run a command for the nix package manager (e.g. nix-channel –update) I get the following warning:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "",
        LC_ALL = "en_US.UTF-8",
        LC_CTYPE = "en_US.UTF-8",
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

I suspect it’s somehow related to nix since other perl scripts don’t show this behaviour (I tried perl -e exit and something using WWW::Curl).

Changing the locale settings does reflect in the output of the warning, but the warning is still shown with every configuration I could think of.

OS is openSUSE.

What can I do?

Asked By: hrantzsch

||

With export LC_ALL=C I actually got rid of the warning.

This is more of a workaround (as LC_ALL is also strongly discouraged), but my guess is the reason for this behaviour lies in assumptions nix makes about locales on the system which don’t apply on openSUSE.

Answered By: hrantzsch

Apparently this is a problem in nix. There is an issue on GitHub with a proposed workaround by setting the LOCALE_ARCHIVE variable.

If you already have nix installed just do:

  1. nix-env -iA nixpkgs.glibcLocales

  2. And in your bash profile:

    export LOCALE_ARCHIVE="$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive"

    (all as one line).

Answered By: cyraxjoe

Found this during a search and thought I’d give the solution.

You just need to provide the variable LOCALE_ARCHIVE in the environment pointing to a locale-archive.

Option 1

Use a previously installed system locale-archive.

Make sure it’s actually there

# should find the file
ls /lib/locale/locale-archive

Add this to your /etc/.profile and/or ~/.bashrc/ and/or ~/.zshrc to have it always set in your shell:

export LOCALE_ARCHIVE="/lib/locale/locale-archive"

Option 2a : Without flake + sub-command support

(source: cyraxjoe above https://unix.stackexchange.com/a/243189/119561)

Install locale support from nix.

nix-env -iA nixpkgs.glibcLocales

Make sure you can find it:

# should give you a path to a folder in your /nix/store
nix-env --installed --no-name --out-path --query glibc-locales

# should find the file
ls $(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive

Add this to your /etc/.profile and/or ~/.bashrc/ and/or ~/.zshrc to have it always set in your shell:

export LOCALE_ARCHIVE="$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive"

Option 2b : With flake + sub-command support

Install locale support from nix.

nix profile install nixpkgs#glibcLocales

Make sure you can find it:

# should give you a path to a folder in your /nix/store
nix profile list | grep glibcLocales | tail -n1 | cut -d ' ' -f4

# should find the file
ls $(nix profile list | grep glibcLocales | tail -n1 | cut -d ' ' -f4)/lib/locale/locale-archive

Add this to your /etc/.profile and/or ~/.bashrc/ and/or ~/.zshrc to have it always set in your shell:

export LOCALE_ARCHIVE="$(nix profile list | grep glibcLocales | tail -n1 | cut -d ' ' -f4)/lib/locale/locale-archive"
Answered By: mtalexan
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.