diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c120bd92..9bd93e1b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -11,6 +11,8 @@ /modules/misc/gtk.nix @rycee +/modules/config/i18n.nix @midchildan + /modules/misc/news.nix @rycee /modules/misc/numlock.nix @evanjs diff --git a/modules/config/i18n.nix b/modules/config/i18n.nix new file mode 100644 index 00000000..18eb40fc --- /dev/null +++ b/modules/config/i18n.nix @@ -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 ]; +} diff --git a/modules/modules.nix b/modules/modules.nix index 74dce1e1..752aee7c 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -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 { }) diff --git a/modules/targets/generic-linux.nix b/modules/targets/generic-linux.nix index f813df9c..cf6b2bd8 100644 --- a/modules/targets/generic-linux.nix +++ b/modules/targets/generic-linux.nix @@ -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" diff --git a/tests/default.nix b/tests/default.nix index ce395f54..09b03978 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 diff --git a/tests/modules/config/i18n/default.nix b/tests/modules/config/i18n/default.nix new file mode 100644 index 00000000..10b35b6f --- /dev/null +++ b/tests/modules/config/i18n/default.nix @@ -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$' + ''; + }; + }; +} diff --git a/tests/modules/home-environment/session-path.nix b/tests/modules/home-environment/session-path.nix index 3b40059e..08477c5a 100644 --- a/tests/modules/home-environment/session-path.nix +++ b/tests/modules/home-environment/session-path.nix @@ -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" diff --git a/tests/modules/home-environment/session-variables-expected.txt b/tests/modules/home-environment/session-variables-expected.txt index 4e18e2b3..a96f6195 100644 --- a/tests/modules/home-environment/session-variables-expected.txt +++ b/tests/modules/home-environment/session-variables-expected.txt @@ -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" diff --git a/tests/modules/home-environment/session-variables.nix b/tests/modules/home-environment/session-variables.nix index 9f326ebc..87c044f1 100644 --- a/tests/modules/home-environment/session-variables.nix +++ b/tests/modules/home-environment/session-variables.nix @@ -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} ''; }; } diff --git a/tests/modules/systemd/session-variables-expected.conf b/tests/modules/systemd/session-variables-expected.conf index 5b6e80bc..65ced43e 100644 --- a/tests/modules/systemd/session-variables-expected.conf +++ b/tests/modules/systemd/session-variables-expected.conf @@ -1,2 +1,3 @@ +LOCALE_ARCHIVE_2_27=@glibcLocales@/lib/locale/locale-archive V_int=1 V_str=2 diff --git a/tests/modules/systemd/session-variables.nix b/tests/modules/systemd/session-variables.nix index b725827c..d00844eb 100644 --- a/tests/modules/systemd/session-variables.nix +++ b/tests/modules/systemd/session-variables.nix @@ -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} ''; }; } diff --git a/tests/modules/targets-linux/generic-linux.nix b/tests/modules/targets-linux/generic-linux.nix index c7b60b32..10481b5e 100644 --- a/tests/modules/targets-linux/generic-linux.nix +++ b/tests/modules/targets-linux/generic-linux.nix @@ -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"' ''; }; }