Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix does not provide en_US.UTF-8 locale #4829

Closed
gpanders opened this issue May 18, 2021 · 5 comments
Closed

Nix does not provide en_US.UTF-8 locale #4829

gpanders opened this issue May 18, 2021 · 5 comments
Labels

Comments

@gpanders
Copy link

Describe the bug

There has been some prior discussion of this (see #599), but I thought it best to open a new issue rather than resurrect an old one.

I installed nix on Red Hat 7, but I am having all kinds of difficulties with locales. I have my system locale set to en_US.UTF-8, but when I use programs installed by Nix I get errors of this form:

/nix/store/68c5b0h2w2ab57sbas1b4m073ik8hlm5-bash-4.4-p23/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = "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 asked about this on IRC and the answer I got was to simply set LC_ALL to C.UTF-8. Unfortunately, RHEL 7 does not support C.UTF-8. So I'm stuck between a rock and a hard place: if I set the locale to C.UTF-8 then Nix packages work, but system packages do not. Conversely, if I use en_US.UTF-8, system packages work, but Nix packages do not.

I have installed glibc-locales and tried setting $LOCALE_ARCHIVE, but that didn't make a difference either. Interestingly, f I install the locale package from Nix and run locale -a, en_US.UTF-8 is listed. This makes me think that the en_US.UTF-8 locale is included in the locale-archive file provided by nix; however, some programs still (apparently?) look for an actual en_US.UTF-8 directory:

$ nix-shell -p perl
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

[nix-shell:~]$ strace -e openat perl -E '1' 2>&1 | grep locale
openat(AT_FDCWD, "/nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/lib/locale/en_US.UTF-8/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/lib/locale/en_US.utf8/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/lib/locale/en_US/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/lib/locale/en.UTF-8/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/lib/locale/en.utf8/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/lib/locale/en/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
perl: warning: Falling back to the standard locale ("C").

The problem is that these files don't exist:

[nix-shell:~]$ ls -al /nix/store/vaf92wc23m067q9aig6zjkcnjvrg768n-glibc-2.32-46/lib/locale
total 1792
dr-xr-xr-x 2 greande greande      28 Dec 31  1969 .
dr-xr-xr-x 5 greande greande    4096 Dec 31  1969 ..
-r--r--r-- 1 greande greande 1829488 Dec 31  1969 locale-archive

I admit that I don't understand locales very well, so I'm not sure what exactly is needed from Nix here. But it would be nice if Nix was able to support the en_US.UTF-8 locale out of the box.

Steps To Reproduce

See above.

Expected behavior

No locale issues.

nix-env --version output

nix-env (Nix) 2.4pre20210503_6d2553a

@gpanders gpanders added the bug label May 18, 2021
@matthewbauer
Copy link
Member

The /en_US.UTF-8/LC_CTYPE is just a fallback if the locale isn't in locale-archive. It should be harmless.

Is it possible LOCALE_ARCHIVE is not getting set correctly in your nix-shell? This work correctly for me on NixOS:

env -i NIX_PATH=$NIX_PATH nix-shell -p perl glibcLocales --run 'LC_ALL=en_US.UTF-8 perl -e echo'

Does that fail on RHEL7? Adding glibcLocales to your nix-shell will export LOCALE_ARCHIVE for you.

@gpanders
Copy link
Author

I just tried setting LOCALE_ARCHIVE again and now it's working... I honestly have no idea what I did differently from yesterday. Thanks for your help.

@matthewbauer
Copy link
Member

It's possible that LOCALE_ARCHIVE could mess up your RHEL7 environment too if it's exported. That is, you probably don't want LOCALE_ARCHIVE set when you run RHEL7 commands. You could try using LOCALE_ARCHIVE_2_27 which I think will just be read by Nixpkgs.

sarcasticadmin added a commit to socallinuxexpo/scale-network that referenced this issue Dec 31, 2021
Was seeing the following error when locale failed:

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

Fix found: NixOS/nix#4829 (comment)
sarcasticadmin added a commit to socallinuxexpo/scale-network that referenced this issue Dec 31, 2021
Was seeing the following error when locale failed:

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

Fix found: NixOS/nix#4829 (comment)
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/warning-setlocale-lc-all-cannot-change-locale-de-de-utf-8-utf-8-invalid-argument/23621/1

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/dict-offline-version/33004/6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants