NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.19k stars 1.47k forks source link

Nix broken by having LANG and LC_* set #599

Closed seschwar closed 8 years ago

seschwar commented 9 years ago

I just tried installing Nix for the first time ever. I have my locale configured are as follows:

$ locale
LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_DK.UTF-8
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES=en_US.UTF-8
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=

Trying to install Nix under Arch Linux as follows fails:

$ curl https://nixos.org/nix/install | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1330  100  1330    0     0   6323      0 --:--:-- --:--:-- --:--:--  6333
unpacking Nix binary tarball for x86_64-linux from `https://nixos.org/releases/nix/nix-1.9/nix-1.9-x86_64-linux.tar.bz2'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 69.4M  100 69.4M    0     0  2837k      0  0:00:25  0:00:25 --:--:-- 2964k 
performing a single-user installation of Nix...
directory /nix does not exist; creating it by running ‘mkdir -m 0755 /nix && chown seschwar /nix’ using sudo
copying Nix to /nix/store...........................
initialising Nix database...
creating /home/seschwar/.nix-profile
ln: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_COLLATE) / sizeof (_nl_value_type_LC_COLLATE[0]))' failed.
/nix/store/l598bgyrflylmfxr7c889jcs5amflrsp-nix-1.9/etc/profile.d/nix.sh: line 36: 11062 Aborted                 (core dumped) /nix/store/wc472nw0kyw0iwgl6352ii5czxd97js2-coreutils-8.23/bin/ln -s "$_NIX_DEF_LINK" "$NIX_LINK"

Rerunning the installer with my locale variables unset succeeds, after having cleaned up the previous failed install (sudo rm -fr /nix):

$ curl https://nixos.org/nix/install | env -u LANG -u LC_MESSAGES -u LC_TIME -u LC_NUMERIC sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1330  100  1330    0     0   6627      0 --:--:-- --:--:-- --:--:--  6650
unpacking Nix binary tarball for x86_64-linux from `https://nixos.org/releases/nix/nix-1.9/nix-1.9-x86_64-linux.tar.bz2'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 69.4M  100 69.4M    0     0  2930k      0  0:00:24  0:00:24 --:--:-- 2937k
performing a single-user installation of Nix...
directory /nix does not exist; creating it by running ‘mkdir -m 0755 /nix && chown seschwar /nix’ using sudo
copying Nix to /nix/store...........................
initialising Nix database...
creating /home/seschwar/.nix-profile
installing ‘nix-1.9’
building path(s) ‘/nix/store/9d63rdn1mszsy5h4fd9x0s215ry6hkrh-user-environment’
created 6 symlinks in user environment
Wide character in print at /nix/store/l598bgyrflylmfxr7c889jcs5amflrsp-nix-1.9/bin/nix-pull line 55.
fetching list of Nix archives at ‘https://nixos.org/releases/nixpkgs/nixpkgs-15.07pre66732.e190a70//MANIFEST.bz2’...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 9354k  100 9354k    0     0  2756k      0  0:00:03  0:00:03 --:--:-- 2758k
caching /nix/store/c4sxj5jz1q2snp67kcdnn18gm8x7x04m-MANIFEST.bz2...
downloading Nix expressions from ‘https://nixos.org/releases/nixpkgs/nixpkgs-15.07pre66732.e190a70//nixexprs.tar.xz’...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5058k  100 5058k    0     0  2440k      0  0:00:02  0:00:02 --:--:-- 2442k
unpacking channels...
created 1 symlinks in user environment

Installation finished!  To ensure that the necessary environment
variables are set, either log in again, or type

  . /home/seschwar/.nix-profile/etc/profile.d/nix.sh

in your shell.

The same thing happens when I'm trying to install a package:

$ nix-env -i nix-repl
installing ‘nix-repl-1.9-57aeef0’
download-using-manifests.pl: perl: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_COLLATE) / sizeof (_nl_value_type_LC_COLLATE[0]))' failed.
error: substituter ‘download-using-manifests.pl’ died unexpectedly
$ env -u LANG -u LC_MESSAGES -u LC_TIME -u LC_NUMERIC nix-env -i nix-repl
installing ‘nix-repl-1.9-57aeef0’
these paths will be fetched (56.22 MiB download, 226.81 MiB unpacked):
  /nix/store/2jhsvzb11ybswkq07a835ab8xjwf7m1y-openssl-1.0.1p
  /nix/store/3a45nb37s0ndljp68228snsqr3qsyp96-bzip2-1.0.6
  /nix/store/5fxl43xvrvs3am2cagddn1b3wsk97w9d-libsodium-1.0.3
  /nix/store/664kxr14kfgx4dl095crvmr7pbh9xlh5-nix-1.9
  /nix/store/90kk1lksk1d4i39hpxidfbnrdk341789-perl-WWW-Curl-4.17
  /nix/store/99z3lmh0cscbidgldzww3ndr2dxmmm10-linux-headers-3.12.32
  /nix/store/9jpnrd6zvqpnhvaqzyyvhvsribpwrc8y-curl-7.43.0
  /nix/store/a457ywa1haa0sgr9g7a1pgldrg3s798d-coreutils-8.24
  /nix/store/ai6xabmvklqgkqji1b9dybmrvcw6ahcb-ncurses-5.9
  /nix/store/az2scrkb88l2q09xa0g6lpbv2mh8lxjl-zlib-1.2.8
  /nix/store/b5kdnhvyyrqgcdlswf3jz32h9idj5zzb-readline-6.3p08
  /nix/store/b6zs8832pl1y1rvpl0dkwhf0ksw2c5j8-attr-2.4.47
  /nix/store/caa7csilm0jrxissf994c1dmw6ri7dp7-gcc-4.9.3
  /nix/store/g33gb293p9azw9l5y14zii2xq7p8i104-perl-5.20.2
  /nix/store/h9ffja30df6arwmpzjwqhji9h69lwji6-boehm-gc-7.2f
  /nix/store/mvvkmwv3jzdxqb30fa6haibf01x3qnik-perl-DBD-SQLite-1.48
  /nix/store/nw6diqy1n4xbq7az3r38mc09i3bf8alm-xz-5.2.1
  /nix/store/q0m70q5wg21hxrixkp1xk4x95sfs2fln-glibc-2.21
  /nix/store/rsinzxmvhcng9gggixrvkbs8j9ah24f1-gnutar-1.28
  /nix/store/s97gkc9bm44b7i44pddvyckg9srlivzz-gzip-1.6
  /nix/store/sn6hkxphm2xkar53j6y52wbivr4z5lfr-perl-DBI-1.633
  /nix/store/xdpasnbq5c4q2v0bya1cyghz6pxki9ia-acl-2.2.52
  /nix/store/yijns3m4bpd5xnkiyds44b2ijp8map04-sqlite-3.8.10.2
  /nix/store/yllvrc74nik3c02xaknahx90psrbkr9r-nix-repl-1.9-57aeef0
  /nix/store/zmd4jk4db5lgxb8l93mhkvr3x92g2sx2-bash-4.3-p39
  /nix/store/zqwwn2iglsrmac314azkgwhyyc2jn0y4-libssh2-1.6.0
fetching path ‘/nix/store/99z3lmh0cscbidgldzww3ndr2dxmmm10-linux-headers-3.12.32’...

*** Trying to download/patch ‘/nix/store/99z3lmh0cscbidgldzww3ndr2dxmmm10-linux-headers-3.12.32’

*** Step 1/1: downloading ‘https://cache.nixos.org/nar/10x1knfa7pfrx1m2jj4rnflm1qd2xr7ydc0nda16f6ynkva9abx0.nar.xz’ to ‘/nix/store/99z3lmh0cscbidgldzww3ndr2dxmmm10-linux-headers-3.12.32’
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  680k  100  680k    0     0   768k      0 --:--:-- --:--:-- --:--:--  770k

fetching path ‘/nix/store/q0m70q5wg21hxrixkp1xk4x95sfs2fln-glibc-2.21’...

*** Trying to download/patch ‘/nix/store/q0m70q5wg21hxrixkp1xk4x95sfs2fln-glibc-2.21’

(...)

building path(s) ‘/nix/store/64k4bjgrasc13l5c7jcz8v58vkxvxqnb-user-environment’
created 23 symlinks in user environment

How am I supposed to set up my locale so that it doesn't break Nix? Would I have to call localedef in each glibc package? But weren't these supposed to be read only?

And shouldn't the installer take care of all that? Producing a broken installation is not very helpful. :wink:

vcunat commented 9 years ago

It might be enough to set LOCALE_ARCHIVE=/usr/lib/locale/locale-archive. But I know little about issues with nix(pkgs) outside nixos.

edolstra commented 9 years ago

@vcunat I believe that's the default even for the Nixpkgs Glibc. But maybe it doesn't exist on Arch.

dezgeg commented 9 years ago

Relevant ML post, and probably the root cause: https://www.sourceware.org/ml/libc-alpha/2015-08/msg00515.html

> > I have seen several reports of this in Arch Linux when people use locale
> > definition files make with localdef from glibc-2.22 on a system with
> > glibc-2.21.
> 
> Not the other way around? glibc 2.22 with locales made with old 2.21 
> localedef?
>
We only support localedef from same version of glibc. So both cause problems. 
wshallum commented 9 years ago

I was trying Nix for the first time today and experienced the same error on Arch Linux. Using LANG=C temporarily works. Also, generating a locale-archive inside the Nix store (/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/locale) using the binaries from the Nix libc and a lightly edited locale-gen script works although I'm not sure that's the proper way to do it.

vcunat commented 9 years ago

Right, @dezgeg, nice reference. This is a general nixpkgs (and nixos) issue then. I don't yet see how to handle this best. It seems clear we might be forced to have multiple locale archives to support running stuff linked against multiple glibc versions. Our glibc already does respond to a versioned variable, but the version wasn't bumped during the last few years ($LOCALE_ARCHIVE_2_11).

For a fast work-around on non-nixos, you can nix-env -i glibc-locales (for all locales or a re-configured version of it, the attribute glibcLocales) and then point $LOCALE_ARCHIVE to the corresponding lib/locale/locale-archive location (e.g. the one linked in a profile after installation).

niko commented 9 years ago

Just ran into this, also on Arch.

Is there any way to fix this on my system or is the nix installer ultimately broken for systems affected?

vcunat commented 9 years ago

Ah, I guess it isn't easy to get glibc-locales without having a working nix. To bootstrap this, it should work to download http://lipa.ms.mff.cuni.cz/~cunav5am/nix/locale-archive and point $LOCALE_ARCHIVE to it.

niko commented 9 years ago

@vcunat thanks, that helped.

YPares commented 8 years ago

Aside from forcing the use of LANG=C everytime, I couldn't install nix on ArchLinux and get it to work. People who succeeded, what procedure did you follow?

vyp commented 8 years ago

Same. Though my locale is:

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

+1

seschwar commented 8 years ago

While avoiding all locale related errors the following unfortunately no longer works for me:

$ curl https://nixos.org/nix/install | env `locale | sed 's/=.*//; s/^/-u /'` sh
unpacking Nix binary tarball for x86_64-linux from `https://nixos.org/releases/nix/nix-1.10/nix-1.10-x86_64-linux.tar.bz2'...
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100 67.0M  100 67.0M    0     0  2917k      0  0:00:23  0:00:23 --:--:-- 2953k
performing a single-user installation of Nix...
directory /nix does not exist; creating it by running ‘mkdir -m 0755 /nix && chown seschwar /nix’ using sudo
copying Nix to /nix/store...........................
initialising Nix database...
creating /home/seschwar/.nix-profile
installing ‘nix-1.10’
download-from-binary-cache.pl: could not download ‘https://cache.nixos.org/nix-cache-info’ (Curl error 6)
building path(s) ‘/nix/store/3a8f4srrxamqlz6irbqqzzj4kzijqvif-user-environment’
created 6 symlinks in user environment
/nix/store/na9pnc5pj9d63xn5z8v4wbc35fm4m9y1-nix-1.10/bin/nix-channel: unable to check ‘https://nixos.org/channels/nixpkgs-unstable’

It seems that something about nix-channel is broken:

$ nix-channel --update
/home/seschwar/.nix-profile/bin/nix-channel: unable to check ‘https://nixos.org/channels/nixpkgs-unstable
’

Is there spurious newline?

If the first step worked then this should allow you to install glibc-locales:

$ env `locale | sed 's/=.*//; s/^/-u /'` nix-env -i glibc-locales

This is what i have in my ~/.profile to use nix:

if test -r "${NIX_PROFILE:-$HOME/.nix-profile}/etc/profile.d/nix.sh"; then
    . "${NIX_PROFILE:-$HOME/.nix-profile}/etc/profile.d/nix.sh"
elif test -r "${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/etc/profile.d/nix.sh"; then
    . "${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/etc/profile.d/nix.sh"
fi
if type nix-env > /dev/null; then
    export LOCALE_ARCHIVE=`nix-env --installed --no-name --out-path --query glibc-locales`/lib/locale/locale-archive
fi

This was all with nix 1.9, which still works. However I can neither upgrade to 1.10 nor reinstall it.

abbradar commented 8 years ago

I already have two friends whom I had to recommend not using Nix for now because of this -- it seems impossible to get an environment right so that both system apps and Nix (and Nix-compiled ones) work on glibc-2.22 systems. D:

Can we perhaps compile our LOCALE_ARCHIVE path into our glibc? This should make it independent off host's glibc if I understand correctly.

vcunat commented 8 years ago

The archive depends on locales that you choose, because it's rather large if you generate all (~100 MB IIRC).

How come it's difficult to get an environment for both Arch and Nix packages? AFAIK $LOCALE_ARCHIVE and $LOCALE_ARCHIVE_2_11 are nix-specific variables.

abbradar commented 8 years ago

@vcunat Strange, they reported it didn't work for them -- maybe we've done something the wrong way. Either way I forgot that it's Nix-specific when we tried to resolve this today -- thanks for reminding!

BTW, why don't we upgrade to glibc-2.22? I remember you mentioned somewhere that we can't do this precisely because of this bug, but I can't connect the dots...

vcunat commented 8 years ago

BTW, why don't we upgrade to glibc-2.22?

When we do, nixos installation will often contain both versions controlled by the same environment variable(s). We will probably have to introduce a new one and (optionally) generate locales for both versions, assuming we want to support mixing the glibc versions (given the nix philosophy).

abbradar commented 8 years ago

Understood, thanks for the explanation!

aaronang commented 8 years ago

This problem also occurs on Fedora 23.

EDIT: I got it to work! Thanks @vcunat and @wshallum :smile:

vbgl commented 8 years ago

@aaronang Could you please elaborate on how you “got it to work”? I face the same issue with Fedora 23. I’ve successfully installed nix using the locale-archive linked by vcunat, then glibc-locales and set the LOCALE_ARCHIVE environment variable. Many things do work but I sometimes (e.g., when building numpy) hit an error like: python2.7: loadlocale.c:130: _nl_intern_locale_data: Assertioncnt < (sizeof (_nl_value_type_LC_COLLATE) / sizeof (_nl_value_type_LC_COLLATE[0]))'` Thanks.

vcunat commented 8 years ago

For building problems, I suppose it's best to setup chrooted builds to avoid picking up Fedora's files.

vbgl commented 8 years ago

chrooted build, obviously. That fixed it. Thanks a lot.

hakuch commented 8 years ago

I've run into this when attempting to install Nix on Fedora 23 as well. @vbgl , could you elaborate on what you did to solve this?

vbgl commented 8 years ago

From what I recall, the following lead to a (mostly) working install of nix on Fedora23:

a) Download vcunat’s locale-archive from: http://lipa.ms.mff.cuni.cz/~cunav5am/nix/locale-archive (see comment above). b) export LOCALE_ARCHIVE=/path/to/locale-archive c) install nix d) using nix, install nixpkgs.glibcLocales and update your LOCALE_ARCHIVE environment variable (e.g., export LOCALE_ARCHIVE=$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive; see seschwar’s comment above) e) if you plan to build things locally (rather than always fetching from binary caches), enable chrooted builds. Here’s the contents of my /etc/nix/nix.conf:

build-users-group = nixbld
auto-optimise-store = true
build-use-chroot = true
build-chroot-dirs = /bin/sh=/nix/store/xag5ayq906w9zhlxs8wayv4kvpiyqphq-bash-4.3-p42/bin/sh

That being said, this is not perfect: pure shells (nix-shell --pure) do not work, as the LOCALE_ARCHIVE environment variable is not propagated from the parent shell to the nix shell.

hakuch commented 8 years ago

@vbgl That worked beautifully. Thank you kindly for the detailed instructions.

fowlay commented 8 years ago

The problem can occur on Gentoo Linux too. Summarizing the workaround: (once) env -u LANG -u LC_MESSAGES -u LC_TIME -u LC_NUMERIC nix-env -iA nixpkgs.glibcLocales (in shell init) export LOCALE_ARCHIVE=$HOME/.nix-profile/lib/locale/locale-archive

dezgeg commented 8 years ago

BTW the glibc in current/recent nixpkgs-unstable now have patches to avoid the loadlocale.c:130: _nl_intern_locale_data: Assertion 'cnt < (sizeof (_nl_value_type_LC_COLLATE) / sizeof (_nl_value_type_LC_COLLATE[0]))' failed. assert from happening, making this slightly less of a problem.

domenkozar commented 8 years ago

@dezgeg so is this fixed?

dezgeg commented 8 years ago

At least it doesn't crash. I think you can still get the annoying locale warnings from perl (like in https://github.com/NixOS/nixpkgs/issues/8398). So probably this one can be closed.

coretemp commented 5 years ago

After an upgrade from 18.03 to 18.09 of NixOS I see the same issue.

vim crashed with the message, as do htop and screen.

tmux works.

locale outputs "en_US.UTF-8" for all values except for LC_ALL (which is empty) and LANG (which is set to that value without the double quotes).

I am not very amused right now. Is "can we start vim?" part of a release channel test?

Baughn commented 5 years ago

Ditto, mosh refuses to connect to any hosts, because en_US.UTF8 apparently is no longer a UTF-8 locale.

Do we not have tests for running Nix on top of non-NixOS?

Geometer1729 commented 2 years ago

This fixed a similar issue for me: https://nixos.wiki/wiki/Locales

ForeverNooob commented 1 year ago

Can anyone please update the dead link in https://github.com/NixOS/nix/issues/599#issuecomment-153885553 ?

@vcunat maybe?

I've tried following the link posted in https://github.com/NixOS/nix/issues/599#issuecomment-1218133981 by @Geometer1729 but on Alpine Linux the path /usr/lib/locale/locale-archive does not exist for example. Hence I'd like to download the locale-archive separately, and then place it there myself.

nixos-discourse commented 1 year ago

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