1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-30 06:59: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/misc/gtk.nix @rycee
/modules/config/i18n.nix @midchildan
/modules/misc/news.nix @rycee /modules/misc/news.nix @rycee
/modules/misc/numlock.nix @evanjs /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 = [ allModules = [
(loadModule ./accounts/email.nix { }) (loadModule ./accounts/email.nix { })
(loadModule ./config/i18n.nix { condition = hostPlatform.isLinux; })
(loadModule ./files.nix { }) (loadModule ./files.nix { })
(loadModule ./home-environment.nix { }) (loadModule ./home-environment.nix { })
(loadModule ./manual.nix { }) (loadModule ./manual.nix { })

View file

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

View file

@ -79,6 +79,7 @@ import nmt {
] ++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [ ] ++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
./modules/targets-darwin ./modules/targets-darwin
] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ ] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [
./modules/config/i18n
./modules/misc/debug ./modules/misc/debug
./modules/misc/numlock ./modules/misc/numlock
./modules/misc/pam ./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, ... }: { config, lib, pkgs, ... }:
{ let inherit (pkgs.stdenv.hostPlatform) isLinux;
in {
imports = [ imports = [
({ ... }: { config.home.sessionPath = [ "foo" ]; }) ({ ... }: { config.home.sessionPath = [ "foo" ]; })
({ ... }: { config.home.sessionPath = [ "bar" "baz" ]; }) ({ ... }: { config.home.sessionPath = [ "bar" "baz" ]; })
@ -15,7 +16,9 @@
# Only source this once. # Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1 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_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config" export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share" export XDG_DATA_HOME="/home/hm-user/.local/share"

View file

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

View file

@ -1,8 +1,18 @@
{ config, lib, ... }: { config, lib, pkgs, ... }:
with lib; 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 = { config = {
home.sessionVariables = { home.sessionVariables = {
V1 = "v1"; V1 = "v1";
@ -11,9 +21,8 @@ with lib;
nmt.script = '' nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContent \ assertFileContent home-path/etc/profile.d/hm-session-vars.sh \
home-path/etc/profile.d/hm-session-vars.sh \ ${expectedConf}
${./session-variables-expected.txt}
''; '';
}; };
} }

View file

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

View file

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

View file

@ -17,9 +17,6 @@ with lib;
assertFileContains \ assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \ home-path/etc/profile.d/hm-session-vars.sh \
'. "${pkgs.nix}/etc/profile.d/nix.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"'
''; '';
}; };
} }