-
Notifications
You must be signed in to change notification settings - Fork 0
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
Notes #1
Comments
Abstract
MWEMWE 1:LC_ALL=en_GB.utf8 date '+%c'
LC_ALL=en_US.utf8 date '+%c' nix \
run \
nixpkgs#python39 \
-- \
-c \
'
import locale
locale.setlocale(locale.LC_ALL, "pt_BR.utf8")
print(locale.currency(12345.67, grouping=True, symbol=True))
' copy/pastesCode 1:#
# nix flake metadata nixpkgs --json | jq -r .url
nix \
store \
ls \
--store https://cache.nixos.org/ \
--long \
--recursive \
"$(nix eval --raw github:NixOS/nixpkgs/9eb60f25aff0d2218c848dd4574a0ab5e296cabe#glibcLocales)" Code 2:#
# nix flake metadata nixpkgs --json | jq -r .url
nix \
store \
ls \
--store https://cache.nixos.org/ \
--long \
--recursive \
"$(nix eval --raw github:NixOS/nixpkgs/9eb60f25aff0d2218c848dd4574a0ab5e296cabe#glibc)" Code 3:#
# nix flake metadata nixpkgs --json | jq -r .url
nix \
store \
ls \
--store https://cache.nixos.org/ \
--long \
--recursive \
"$(nix eval --raw github:NixOS/nixpkgs/9eb60f25aff0d2218c848dd4574a0ab5e296cabe#locale)" Code 4:#
# nix flake metadata nixpkgs --json | jq -r .url
nix \
store \
ls \
--store https://cache.nixos.org/ \
--long \
--recursive \
"$(nix eval --raw github:NixOS/nixpkgs/9eb60f25aff0d2218c848dd4574a0ab5e296cabe#glibc.bin)" # nix flake metadata github:NixOS/nixpkgs/release-22.05 --json
command -v jq >/dev/null || nix profile install github:NixOS/nixpkgs/4aceab3cadf9fef6f70b9f6a9df964218650db0a#jq \
&& nix \
build \
--impure \
--expr \
'(
with builtins.getFlake "nixpkgs";
with legacyPackages.${builtins.currentSystem};
(
glibcLocales.override {
allLocales = false;
locales = [
"en_GB.UTF-8/UTF-8"
"ru_RU.UTF-8/UTF-8"
"en_US.UTF-8/UTF-8"
"pt_BR.UTF-8/UTF-8"
"ja_JP.UTF-8/UTF-8"
"en_IE.UTF-8/UTF-8"
];
}
)
)' Refs.:
LOCALE_ARCHIVE=result/lib/locale/locale-archive \
&& LC_ALL=pt_BT.UTF-8 \
&& nix \
run \
nixpkgs#python39 \
-- \
-c \
'
import locale
locale.setlocale(locale.LC_ALL, "pt_BR.utf8")
print(locale.currency(12345.67, grouping=True, symbol=True))
locale.setlocale(locale.LC_ALL, "en_US.utf8")
print(locale.currency(12345.67, grouping=True, symbol=True))
locale.setlocale(locale.LC_ALL, "ru_RU.utf8")
print(locale.currency(12345.67, grouping=True, symbol=True))
locale.setlocale(locale.LC_ALL, "ja_JP.utf8")
print(locale.currency(12345.67, grouping=True, symbol=True))
locale.setlocale(locale.LC_ALL, "en_IE.utf8")
print(locale.currency(12345.67, grouping=True, symbol=True))
' { cat <<WRAP >> foo.c
#include <stdio.h>
#include <locale.h>
int main()
{
char *locale = setlocale(LC_ALL, "");
printf("\n locale =%s\n", locale);
printf("test\n \u263a\u263b Hello from C\n");
return 0;
}
WRAP
} && gcc foo.c \
&& ./a.out rm -f a.out foo.c Refs.: TODO: nix run nixpkgs#gcc -- -xc -E -v /dev/null printf '#include <locale.h>\nLC_COLLATE\n' | gcc -E -x c - | tail -n 1 Refs.: nix run nixpkgs#python39 -- -c "assert '\N{snake}' == '🐍'" TODO: printf %b\\n \\u04{51,{3,4}{{0..9},{a..f}}}|sort|sed 's/./\u&&/'|tr -d \\n Refs.: cowsaynix \
shell \
--ignore-environment \
--impure \
--expr \
'
(
let
nixpkgs = (builtins.getFlake "github:NixOS/nixpkgs/0938d73bb143f4ae037143572f11f4338c7b2d1c");
pkgs = import nixpkgs { };
in
with pkgs; [
cowsay
]
)
' \
--command cowsay "Hello"
nix \
shell \
--ignore-environment \
--impure \
--expr \
'
(
let
nixpkgs = (builtins.getFlake "github:NixOS/nixpkgs/0938d73bb143f4ae037143572f11f4338c7b2d1c");
pkgs = import nixpkgs { };
in
with pkgs; [
(
glibcLocales.override {
allLocales = false;
locales = [
"en_US.UTF-8/UTF-8"
"pt_BR.UTF-8/UTF-8"
];
}
)
cowsay
]
)
' \
--command cowsay "Hello" Refs.:
OthersLOCALE_ARCHIVE=result/lib/locale/locale-archive
LC_ALL=pt_BR.UTF-8 date '+%c'
LC_ALL=en_US.UTF-8 date '+%c'
LC_ALL=ru_RU.UTF-8 date '+%c'
LC_ALL=ja_JP.UTF-8 date '+%c'
LC_ALL=en_IE.UTF-8 date '+%c' LOCALE_ARCHIVE=result/lib/locale/locale-archive
LC_ALL=en_GB.UTF-8
nix run nixpkgs#uutils-coreutils -- date '+%c'
LC_ALL=en_US.UTF-8
nix run nixpkgs#uutils-coreutils -- date '+%c' LOCALE_ARCHIVE=result/lib/locale/locale-archive
LC_ALL=en_GB.UTF-8
nix run nixpkgs#busybox -- date '+%c'
LC_ALL=en_US.UTF-8
nix run nixpkgs#busybox -- date '+%c' nix \
run \
nixpkgs#python39 -- \
-c \
"
v=32
while v:print('Ёё'*(v==26),end='%c%c'%(1072-v,1104-v));v-=1
" export LC_ALL=en_US.utf8
nix run nixpkgs#python39 -- -c '
import locale
defaultlocale = locale.getdefaultlocale()
locale.setlocale(locale.LC_ALL, defaultlocale[0] + "." + defaultlocale[1])
print(locale.currency(12345.67, grouping=True, symbol=True))
'
export LC_ALL=pt_BR.utf8
nix run nixpkgs#python39 -- -c '
import locale
defaultlocale = locale.getdefaultlocale()
locale.setlocale(locale.LC_ALL, defaultlocale[0] + "." + defaultlocale[1])
print(locale.currency(12345.67, grouping=True, symbol=True))
' Refs.: perl -MEncode=decode -E 'while(<>){ chomp; say length decode("UTF-8", $_) }' <<<'文字化け' Refs.: TODO:
Faker("cellphone_number", locale="pt-BR") TODO:
|
TODO:
To illustrate this further I've written a small c program that prints all the environment variables using the argv array pointer. As you can see the environment variable pointers are stored pretty much right after argv. #include <stdio.h>
int main(int argc, char **argv)
{
for (int i = argc + 2; argv[i] != NULL; i++)
{
printf("%s\n", argv[i]);
}
return 0;
} You can of course make it less stupid by using the full version of main which includes a pointer to the first element in the environment pointer array. #include <stdio.h>
int main(int argc, char **argv, char **envp)
{
for (int i = 0; envp[i] != NULL; i++)
{
printf("%s\n", envp[i]);
}
return 0;
} This is all defined as a part of the ABI (application binary interface) for both the x86 and x86_64 architecture, so 32 and 64 bit desktop computers. tl;dr: The environment is not a single long string separated by new-line characters. The environment variables and the pointers to them are both stored on the stack or just before it. Maybe related: https://serverfault.com/a/792136 |
Abstract
There are 4 packages in nixpkgs involved, at least.
Some notes about locale/locale-archive
Old, but really great: NixOS/nix#599 (comment)
TODO: take a look in this, lots of troubleshoot commands:
NixOS/nix#599
What is the locale-archive
Difference between locale-archive and Machine Object files in /usr/share/locale/<locale_dir>/LC_MESSAGES/ directory?
TODO: add real updated values and sha256sum
glibc
From: https://gurkan.in/wiki/nix.html#override-example-optional-args
TODO: convert this to a flake nix-shell cannot change locale warning
Some troubleshoot commands:
strace -e file locale
ls /usr/share/i18n/charmaps/
gzip -dk UTF-8.gz
From: Locale issue after upgrading to Ubuntu 16.10 from a clean installation of Ubuntu 16.04
Saving all this for now:
nix profile
NixOS/nix#3579 (comment)TODO: https://unix.stackexchange.com/questions/187402/nix-package-manager-perl-warning-setting-locale-failed/243189#243189
Maybe useful:
https://github.com/davidtwco/veritas/blob/6f2c676a76ef2885c9102aeaea874c361dbcaf61/home/profiles/common.nix#L197-L198
TODO: document from where it came from, the python PEPs about it
https://click.palletsprojects.com/en/5.x/python3/#python-3-surrogate-handling
The text was updated successfully, but these errors were encountered: