1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

i18n: set the appropriate LOCALE_ARCHIVE_x_xx variable (#1659)

This commit is contained in:
midchildan 2021-01-23 23:56:38 +09:00 committed by GitHub
parent 08fc1586c0
commit 9a12cd7e81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 93 additions and 16 deletions

2
.github/CODEOWNERS vendored
View file

@ -11,6 +11,8 @@
/modules/misc/gtk.nix @rycee
/modules/config/i18n.nix @midchildan
/modules/misc/news.nix @rycee
/modules/misc/numlock.nix @evanjs

44
modules/config/i18n.nix Normal file
View file

@ -0,0 +1,44 @@
# The glibc package in nixpkgs is patched to make it possbile to specify
# an alternative path for the locale archive through a special environment
# variable. This would allow different versions of glibc to coexist on the
# same system because each version of glibc could look up different paths
# for its locale archive should the archive format ever change in
# incompatible ways.
#
# See also:
# localedef(1)
# https://nixos.org/manual/nixpkgs/stable/#locales
# https://github.com/NixOS/nixpkgs/issues/38991
#
# XXX: The name of the said environment variable gets updated with each
# breaking release of the glibcLocales package. Periodically check the link
# below for changes:
# https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/development/libraries/glibc/nix-locale-archive.patch
{ lib, pkgs, ... }:
with lib;
let
inherit (pkgs.glibcLocales) version;
archivePath = "${pkgs.glibcLocales}/lib/locale/locale-archive";
# lookup the version of glibcLocales and set the appropriate environment vars
localeVars = if (versionAtLeast version "2.27") then {
LOCALE_ARCHIVE_2_27 = archivePath;
} else if (versionAtLeast version "2.11") then {
LOCALE_ARCHIVE_2_11 = archivePath;
} else
{ };
in {
config = {
# for shell sessions
home.sessionVariables = localeVars;
# for desktop apps
systemd.user.sessionVariables = localeVars;
};
meta.maintainers = with maintainers; [ midchildan ];
}

View file

@ -22,6 +22,7 @@ let
allModules = [
(loadModule ./accounts/email.nix { })
(loadModule ./config/i18n.nix { condition = hostPlatform.isLinux; })
(loadModule ./files.nix { })
(loadModule ./home-environment.nix { })
(loadModule ./manual.nix { })

View file

@ -32,10 +32,7 @@ in {
dataDirs = concatStringsSep ":"
(map (profile: "${profile}/share") profiles
++ config.targets.genericLinux.extraXdgDataDirs);
in {
XDG_DATA_DIRS = "${dataDirs}\${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS";
LOCALE_ARCHIVE_2_27 = "${pkgs.glibcLocales}/lib/locale/locale-archive";
};
in { XDG_DATA_DIRS = "${dataDirs}\${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"; };
home.sessionVariablesExtra = ''
. "${pkgs.nix}/etc/profile.d/nix.sh"

View file

@ -79,6 +79,7 @@ import nmt {
] ++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
./modules/targets-darwin
] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [
./modules/config/i18n
./modules/misc/debug
./modules/misc/numlock
./modules/misc/pam

View file

@ -0,0 +1,17 @@
{
i18n = { ... }: {
config = {
nmt.script = ''
hmEnvFile=home-path/etc/profile.d/hm-session-vars.sh
assertFileExists $hmEnvFile
assertFileRegex $hmEnvFile \
'^export LOCALE_ARCHIVE_._..=".*/lib/locale/locale-archive"$'
envFile=home-files/.config/environment.d/10-home-manager.conf
assertFileExists $envFile
assertFileRegex $envFile \
'^LOCALE_ARCHIVE_._..=.*/lib/locale/locale-archive$'
'';
};
};
}

View file

@ -1,6 +1,7 @@
{ config, lib, pkgs, ... }:
{
let inherit (pkgs.stdenv.hostPlatform) isLinux;
in {
imports = [
({ ... }: { config.home.sessionPath = [ "foo" ]; })
({ ... }: { config.home.sessionPath = [ "bar" "baz" ]; })
@ -15,7 +16,9 @@
# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
${lib.optionalString isLinux ''
export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive"''}
export XDG_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share"

View file

@ -1,7 +1,7 @@
# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
@exportLocaleVar@
export V1="v1"
export V2="v2-v1"
export XDG_CACHE_HOME="/home/hm-user/.cache"

View file

@ -1,8 +1,18 @@
{ config, lib, ... }:
{ config, lib, pkgs, ... }:
with lib;
{
let
inherit (pkgs.stdenv.hostPlatform) isLinux;
expectedConf = pkgs.substituteAll {
src = ./session-variables-expected.txt;
# the blank space below is intentional
exportLocaleVar = optionalString isLinux ''
export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive"'';
};
in {
config = {
home.sessionVariables = {
V1 = "v1";
@ -11,9 +21,8 @@ with lib;
nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContent \
home-path/etc/profile.d/hm-session-vars.sh \
${./session-variables-expected.txt}
assertFileContent home-path/etc/profile.d/hm-session-vars.sh \
${expectedConf}
'';
};
}

View file

@ -1,2 +1,3 @@
LOCALE_ARCHIVE_2_27=@glibcLocales@/lib/locale/locale-archive
V_int=1
V_str=2

View file

@ -2,7 +2,12 @@
with lib;
{
let
expectedConf = pkgs.substituteAll {
src = ./session-variables-expected.conf;
inherit (pkgs) glibcLocales;
};
in {
config = {
systemd.user.sessionVariables = {
V_int = 1;
@ -12,7 +17,7 @@ with lib;
nmt.script = ''
envFile=home-files/.config/environment.d/10-home-manager.conf
assertFileExists $envFile
assertFileContent $envFile ${./session-variables-expected.conf}
assertFileContent $envFile ${expectedConf}
'';
};
}

View file

@ -17,9 +17,6 @@ with lib;
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
'. "${pkgs.nix}/etc/profile.d/nix.sh"'
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
'export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive"'
'';
};
}