2 This function builds just the `lib/locale/locale-archive' file from
3 Glibc and nothing else. If `allLocales' is true, all supported
4 locales are included; otherwise, just the locales listed in
5 `locales'. See localedata/SUPPORTED in the Glibc source tree for
6 the list of all supported locales:
7 https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED
18 locales ? [ "en_US.UTF-8/UTF-8" ],
20 withLinuxHeaders ? !stdenv.cc.isGNU,
23 (callPackage ./common.nix
24 ({ inherit stdenv; } // lib.optionalAttrs withLinuxHeaders { inherit linuxHeaders; })
26 pname = "glibc-locales";
27 extraNativeBuildInputs = [ glibc ];
28 inherit withLinuxHeaders;
32 finalAttrs: previousAttrs: {
34 builder = ./locales-builder.sh;
39 (if stdenv.hostPlatform.isLittleEndian then "--little-endian" else "--big-endian")
43 (previousAttrs.preBuild or "")
45 # Awful hack: `localedef' doesn't allow the path to `locale-archive'
46 # to be overriden, but you *can* specify a prefix, i.e. it will use
47 # <prefix>/<path-to-glibc>/lib/locale/locale-archive. So we use
48 # $TMPDIR as a prefix, meaning that the locale-archive is placed in
49 # $TMPDIR/nix/store/...-glibc-.../lib/locale/locale-archive.
50 LOCALEDEF_FLAGS+=" --prefix=$TMPDIR"
52 mkdir -p $TMPDIR/"${buildPackages.glibc.out}/lib/locale"
54 echo 'C.UTF-8/UTF-8 \' >> ../glibc-2*/localedata/SUPPORTED
56 # Hack to allow building of the locales (needed since glibc-2.12)
57 sed -i -e 's,^$(rtld-prefix) $(common-objpfx)locale/localedef,localedef $(LOCALEDEF_FLAGS),' ../glibc-2*/localedata/Makefile
59 + lib.optionalString (!allLocales) ''
60 # Check that all locales to be built are supported
61 echo -n '${lib.concatMapStrings (s: s + " \\\n") locales}' \
62 | sort -u > locales-to-build.txt
63 cat ../glibc-2*/localedata/SUPPORTED | grep ' \\' \
64 | sort -u > locales-supported.txt
65 comm -13 locales-supported.txt locales-to-build.txt \
66 > locales-unsupported.txt
67 if [[ $(wc -c locales-unsupported.txt) != "0 locales-unsupported.txt" ]]; then
68 cat locales-supported.txt
69 echo "Error: unsupported locales detected:"
70 cat locales-unsupported.txt
71 echo "You should choose from the list above the error."
75 echo SUPPORTED-LOCALES='${toString locales}' > ../glibc-2*/localedata/SUPPORTED
78 # Current `nixpkgs` way of building locales is not compatible with
79 # parallel install. `locale-archive` is updated in parallel with
80 # multiple `localedef` processes and causes non-deterministic result:
81 # https://github.com/NixOS/nixpkgs/issues/245360
82 enableParallelBuilding = false;
84 makeFlags = (previousAttrs.makeFlags or [ ]) ++ [
85 "localedata/install-locales"
86 "localedir=${builtins.placeholder "out"}/lib/locale"
90 mkdir -p "$out/lib/locale" "$out/share/i18n"
91 cp -v "$TMPDIR/$NIX_STORE/"*"/lib/locale/locale-archive" "$out/lib/locale"
92 cp -v ../glibc-2*/localedata/SUPPORTED "$out/share/i18n/SUPPORTED"
95 setupHook = writeText "locales-setup-hook.sh" ''
96 export LOCALE_ARCHIVE=@out@/lib/locale/locale-archive
99 meta.description = "Locale information for the GNU C Library";