Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions modules/config/i18n.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
# below for changes:
# https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/development/libraries/glibc/nix-locale-archive.patch

{ lib, pkgs, ... }:
{ lib, pkgs, config, ... }:

with lib;

let
inherit (config.i18n) glibcLocales;

inherit (pkgs.glibcLocales) version;
inherit (glibcLocales) version;

archivePath = "${pkgs.glibcLocales}/lib/locale/locale-archive";
archivePath = "${glibcLocales}/lib/locale/locale-archive";

# lookup the version of glibcLocales and set the appropriate environment vars
localeVars = if versionAtLeast version "2.27" then {
Expand All @@ -36,6 +37,31 @@ let
in {
meta.maintainers = with maintainers; [ midchildan ];

options = {
i18n.glibcLocales = mkOption {
type = types.path;
description = ''
Customized <literal>glibcLocales</literal> package providing
the <literal>LOCALE_ARCHIVE_*</literal> environment variable.
</para><para>
This option only applies to the Linux platform.
</para><para>
When Home Manager is configured with NixOS, the default value
will be set to <varname>i18n.glibcLocales</varname> from the
system configuration.
'';
example = literalExpression ''
pkgs.glibcLocales.override {
allLocales = false;
locales = [ "en_US.UTF-8/UTF-8" ];
}
'';
# NB. See nixos/default.nix for NixOS default.
default = pkgs.glibcLocales;
defaultText = literalExpression "pkgs.glibcLocales";
};
};

config = mkIf pkgs.stdenv.hostPlatform.isLinux {
# For shell sessions.
home.sessionVariables = localeVars;
Expand Down
3 changes: 3 additions & 0 deletions nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ in {
# fontconfig by default.
fonts.fontconfig.enable = lib.mkDefault
(cfg.useUserPackages && config.fonts.fontconfig.enable);

# Inherit glibcLocales setting from NixOS.
i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales;
}];
};
}
Expand Down
22 changes: 22 additions & 0 deletions tests/modules/config/i18n/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,26 @@
'';
};
};

i18n-custom-locales = { pkgs, ... }: {
config = let stub = pkgs.glibcLocalesCustom;
in {
test.stubs.glibcLocalesCustom = {
inherit (pkgs.glibcLocales) version;
outPath = null; # we need a real path for this stub
};

i18n.glibcLocales = stub;

nmt.script = ''
hmEnvFile=home-path/etc/profile.d/hm-session-vars.sh
assertFileExists $hmEnvFile
assertFileRegex $hmEnvFile 'LOCALE_ARCHIVE_.*${stub}'

envFile=home-files/.config/environment.d/10-home-manager.conf
assertFileExists $envFile
assertFileRegex $envFile 'LOCALE_ARCHIVE_.*${stub}'
'';
};
};
}
2 changes: 1 addition & 1 deletion tests/modules/home-environment/session-variables.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1

export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive"
export LOCALE_ARCHIVE_2_27="${config.i18n.glibcLocales}/lib/locale/locale-archive"
export V1="v1"
export V2="v2-v1"
export XDG_CACHE_HOME="/home/hm-user/.cache"
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/misc/xdg/system-dirs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
assertFileExists $envFile
assertFileContent $envFile ${
pkgs.writeText "expected" ''
LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive
LOCALE_ARCHIVE_2_27=${config.i18n.glibcLocales}/lib/locale/locale-archive
XDG_CACHE_HOME=/home/hm-user/.cache
XDG_CONFIG_DIRS=/etc/xdg:/foo/bar''${XDG_CONFIG_DIRS:+:$XDG_CONFIG_DIRS}
XDG_CONFIG_HOME=/home/hm-user/.config
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/systemd/session-variables.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ config, pkgs, ... }:

{
systemd.user.sessionVariables = {
Expand All @@ -11,7 +11,7 @@
assertFileExists $envFile
assertFileContent $envFile ${
pkgs.writeText "expected" ''
LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive
LOCALE_ARCHIVE_2_27=${config.i18n.glibcLocales}/lib/locale/locale-archive
V_int=1
V_str=2
XDG_CACHE_HOME=/home/hm-user/.cache
Expand Down