2020-04-24 23:36:52 +00:00
|
|
|
/* This function builds just the `lib/locale/locale-archive' file from
|
|
|
|
Glibc and nothing else. If `allLocales' is true, all supported
|
|
|
|
locales are included; otherwise, just the locales listed in
|
|
|
|
`locales'. See localedata/SUPPORTED in the Glibc source tree for
|
|
|
|
the list of all supported locales:
|
|
|
|
https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED
|
|
|
|
*/
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
{ lib, stdenv, buildPackages, callPackage, writeText, glibc
|
2020-04-24 23:36:52 +00:00
|
|
|
, allLocales ? true, locales ? [ "en_US.UTF-8/UTF-8" ]
|
|
|
|
}:
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
(callPackage ./common.nix { inherit stdenv; } {
|
2021-05-28 09:39:13 +00:00
|
|
|
pname = "glibc-locales";
|
2023-08-22 20:05:09 +00:00
|
|
|
extraNativeBuildInputs = [ glibc ];
|
2023-07-15 17:15:38 +00:00
|
|
|
}).overrideAttrs(finalAttrs: previousAttrs: {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
builder = ./locales-builder.sh;
|
|
|
|
|
|
|
|
outputs = [ "out" ];
|
|
|
|
|
2022-09-30 11:47:45 +00:00
|
|
|
LOCALEDEF_FLAGS = [
|
|
|
|
(if stdenv.hostPlatform.isLittleEndian
|
|
|
|
then "--little-endian"
|
|
|
|
else "--big-endian")
|
|
|
|
];
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
preBuild = (previousAttrs.preBuild or "") + ''
|
2022-09-30 11:47:45 +00:00
|
|
|
# Awful hack: `localedef' doesn't allow the path to `locale-archive'
|
|
|
|
# to be overriden, but you *can* specify a prefix, i.e. it will use
|
|
|
|
# <prefix>/<path-to-glibc>/lib/locale/locale-archive. So we use
|
|
|
|
# $TMPDIR as a prefix, meaning that the locale-archive is placed in
|
|
|
|
# $TMPDIR/nix/store/...-glibc-.../lib/locale/locale-archive.
|
|
|
|
LOCALEDEF_FLAGS+=" --prefix=$TMPDIR"
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
mkdir -p $TMPDIR/"${buildPackages.glibc.out}/lib/locale"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
echo 'C.UTF-8/UTF-8 \' >> ../glibc-2*/localedata/SUPPORTED
|
|
|
|
|
|
|
|
# Hack to allow building of the locales (needed since glibc-2.12)
|
2022-09-30 11:47:45 +00:00
|
|
|
sed -i -e 's,^$(rtld-prefix) $(common-objpfx)locale/localedef,localedef $(LOCALEDEF_FLAGS),' ../glibc-2*/localedata/Makefile
|
2020-04-24 23:36:52 +00:00
|
|
|
''
|
2021-02-05 17:12:51 +00:00
|
|
|
+ lib.optionalString (!allLocales) ''
|
2020-04-24 23:36:52 +00:00
|
|
|
# Check that all locales to be built are supported
|
2021-02-05 17:12:51 +00:00
|
|
|
echo -n '${lib.concatMapStrings (s: s + " \\\n") locales}' \
|
2021-09-23 15:35:13 +00:00
|
|
|
| sort -u > locales-to-build.txt
|
2020-04-24 23:36:52 +00:00
|
|
|
cat ../glibc-2*/localedata/SUPPORTED | grep ' \\' \
|
2021-09-23 15:35:13 +00:00
|
|
|
| sort -u > locales-supported.txt
|
2020-04-24 23:36:52 +00:00
|
|
|
comm -13 locales-supported.txt locales-to-build.txt \
|
|
|
|
> locales-unsupported.txt
|
|
|
|
if [[ $(wc -c locales-unsupported.txt) != "0 locales-unsupported.txt" ]]; then
|
|
|
|
cat locales-supported.txt
|
|
|
|
echo "Error: unsupported locales detected:"
|
|
|
|
cat locales-unsupported.txt
|
|
|
|
echo "You should choose from the list above the error."
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo SUPPORTED-LOCALES='${toString locales}' > ../glibc-2*/localedata/SUPPORTED
|
|
|
|
'';
|
|
|
|
|
2023-08-22 20:05:09 +00:00
|
|
|
# Current `nixpkgs` way of building locales is not compatible with
|
|
|
|
# parallel install. `locale-archive` is updated in parallel with
|
|
|
|
# multiple `localedef` processes and causes non-deterministic result:
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/245360
|
|
|
|
enableParallelBuilding = false;
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
makeFlags = (previousAttrs.makeFlags or []) ++ [
|
|
|
|
"localedata/install-locales"
|
|
|
|
"localedir=${builtins.placeholder "out"}/lib/locale"
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
installPhase =
|
|
|
|
''
|
2022-11-21 17:40:18 +00:00
|
|
|
mkdir -p "$out/lib/locale" "$out/share/i18n"
|
2020-04-24 23:36:52 +00:00
|
|
|
cp -v "$TMPDIR/$NIX_STORE/"*"/lib/locale/locale-archive" "$out/lib/locale"
|
2022-11-21 17:40:18 +00:00
|
|
|
cp -v ../glibc-2*/localedata/SUPPORTED "$out/share/i18n/SUPPORTED"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
setupHook = writeText "locales-setup-hook.sh"
|
|
|
|
''
|
|
|
|
export LOCALE_ARCHIVE=@out@/lib/locale/locale-archive
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta.description = "Locale information for the GNU C Library";
|
2023-07-15 17:15:38 +00:00
|
|
|
})
|