nix-shell 无法更改语言环境警告

标签 nix

在没有 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

最佳答案

您可以在 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

关于nix-shell 无法更改语言环境警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62287269/

相关文章:

nix - 如何在 Nix 环境中安装 PostGIS

linux - NixOps:如何部署到现有的 NixOS VM?

macos - 安装在 OSX 上时 nix.conf 位于何处?

haskell - 如何通过 Nix 覆盖 nixpkgs 中的 Haskell 包?

nix - 将 nixpkgs 结账传播到 NixOps 机器

python - 最小化使用Nix的 `dockertools.buildImage`构建的docker容器大小

nix - 如何找到 Nix channel 指向的提交?

haskell - 使用 nix-shell 查找带有 cabal 的外国库

nix - 从 Nix 模块选项部分引用 pkgs.system 时无限递归

r - 如何用nix创建一个可以启动Rstudio的环境