DavHau / nix-portable

Nix - Static, Permissionless, Installation-free, Pre-configured
MIT License
902 stars 32 forks source link

set LOCALE_ARCHIVE for nix-shell #119

Open milahu opened 5 months ago

milahu commented 5 months ago

in some environments LOCALE_ARCHIVE can be unset and the default file can be "empty"

$ du -sh /usr/lib/locale/locale-archive
2.2M

$ du -sh ~/.nix-portable/nix/store/xx5an8dhxd4a5qxgdsk3xqz5zmngj4y2-glibc-locales-2.39-5/lib/locale/locale-archive
220M

this happens when /etc/locale.conf is missing or empty and/or when /etc/locale.gen is read-only

$ ls /etc/locale.conf
ls: cannot access '/etc/locale.conf': No such file or directory

$ stat -c%a /etc/locale.gen
600

... in other words, no locales were generated and only the default locale C.UTF-8 is available

$ ls /usr/lib/locale/
C.UTF-8  locale-archive

problem is, this breaks qt-based programs like qbittorrent

$ nix-shell -p qbittorrent-nox

$ qbittorrent-nox
Detected locale "C" with character encoding "ANSI_X3.4-1968", which is not UTF-8.
Qt depends on a UTF-8 locale, and has switched to "C.UTF-8" instead.
If this causes problems, reconfigure your locale. See the locale(1) manual
for more information.

the debian solution for this problem is

  1. add your locale (en_US.UTF-8) to /etc/locale.conf
  2. run sudo locale-gen

in debian, the files in /usr/lib/locale/ are generated by locale-gen

https://packages.debian.org/sid/locales

This package contains tools to generate locale definitions from source files (included in this package). It allows you to customize which definitions actually get generated. This is a space-saver over how this package used to be, with all locales generated by default. This created a package that unpacked to an excess of 30 megs.

in nixos, LOCALE_ARCHIVE is set by the i18n module nixos/modules/config/i18n.nix

LOCALE_ARCHIVE = "${config.i18n.glibcLocales}/lib/locale/locale-archive";

quickfix: use this wrapper as nix-shell

#!/usr/bin/env bash
export LOCALE_ARCHIVE=$(nix-portable nix-build '<nixpkgs>' -A glibcLocales)/lib/locale/locale-archive
exec nix-portable nix-shell "$@"

edit:

this breaks qt-based programs

not really, this is just a warning