【问题标题】:nix-shell cannot change locale warningnix-shell 无法更改语言环境警告
【发布时间】:2020-09-28 21:44:40
【问题描述】:

在没有shell.nix 文件的情况下运行nix-shell 时会弹出以下警告:

$ nix-shell -p glibcLocales
bash: warning: setlocale: LC_TIME: cannot change locale (en_GB.UTF-8): No such file or directory

[nix-shell:~]$

如果发现几篇关于将环境变量 LOCALE_ARCHIVE_2_27 设置为某个路径的帖子。如何自动将这样的环境变量设置为正确的路径?使用一些shell.nix 文件会有帮助吗?

编辑:我的语言环境设置如下:

$ cat /etc/locale.conf
LANG="en_US.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_TIME="en_GB.UTF-8"

如果我从/etc/locale.conf 中删除LC_TIME="en_GB.UTF-8",那么即使使用了LC_TIME="en_GB.UTF-8" nix-shell -p glibcLocales,警告也不会出现。

在 Fedora 32 上使用 nix-2.3.6

$ nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable

【问题讨论】:

  • 你好!只是为了确保我在查看之前尝试在正确的平台上进行复制——这是 NixOS,还是其他平台上的 Nix?哪个 nixpkgs 发布/频道? (Nix 版本远不如频道重要,因为这是 glibcLocales 定义的来源)。
  • 你好@CharlesDuffy,我已经更新了我的问题。这能回答你的问题吗?
  • 是的,这是一个不错的起点;不幸的是,我可用的环境都不是很接近的(不能在 NixOS 19.09 或 20.03 上重现,手头上没有 Fedora)。您能否将运行locale 的输出添加到问题中? (所有相关变量是设置为en_GB.UTF-8,还是只是一个子集?)
  • 我更新了我的问题,反映了关于 /etc/locale.conf 的一件奇怪的事情。
  • 顺便说一句。 /etc/locale.conf 似乎来自 systemd。

标签: nix


【解决方案1】:

您可以使用 shell.nix 中的有效路径填充 $LOCALE_ARCHIVE_2_27,如下所示:

❯ cat shell.nix
with import <nixpkgs> {};
mkShell {
  LOCALE_ARCHIVE_2_27 = "${glibcLocales}/lib/locale/locale-archive";
  buildInputs = [
    hello
  ];
}
❯ nix-shell

[nix-shell:~]$ echo $LOCALE_ARCHIVE_2_27
/nix/store/r24xc904amrdwfrzyijxmylxnxmwacm9-glibc-locales-2.31/lib/locale/locale-archive

或将表达式作为参数传递

❯ nix-shell -E 'with import <nixpkgs> { }; runCommand "dummy" { LOCALE_ARCHIVE_2_27 = "${glibcLocales}/lib/locale/locale-archive"; buildInputs = [ hello ]; } ""'

[nix-shell:~]$ echo $LOCALE_ARCHIVE_2_27
/nix/store/r24xc904amrdwfrzyijxmylxnxmwacm9-glibc-locales-2.31/lib/locale/locale-archive

更多详情在这里https://gist.github.com/peti/2c818d6cb49b0b0f2fd7c300f8386bc3

【讨论】:

    猜你喜欢
    • 2018-09-21
    • 2019-07-31
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 2017-06-07
    • 1970-01-01
    相关资源
    最近更新 更多