1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

i18n: Use glibcLocales from NixOS if possible (#2333) (#4177)

This will reduce the system closure size by about 200MB under NixOS by
sharing the glibcLocales package.

When home-manager is installed on Linux without the NixOS module, all
glibc locales are installed, as before.

Resolves: #2333
This commit is contained in:
Rodney Lorrimar 2023-07-04 19:28:25 +10:00 committed by GitHub
parent c24deeca64
commit 3be2abb2e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 7 deletions

View file

@ -15,15 +15,16 @@
# below for changes: # below for changes:
# https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/development/libraries/glibc/nix-locale-archive.patch # https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/development/libraries/glibc/nix-locale-archive.patch
{ lib, pkgs, ... }: { lib, pkgs, config, ... }:
with lib; with lib;
let 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 # lookup the version of glibcLocales and set the appropriate environment vars
localeVars = if versionAtLeast version "2.27" then { localeVars = if versionAtLeast version "2.27" then {
@ -36,6 +37,31 @@ let
in { in {
meta.maintainers = with maintainers; [ midchildan ]; 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 { config = mkIf pkgs.stdenv.hostPlatform.isLinux {
# For shell sessions. # For shell sessions.
home.sessionVariables = localeVars; home.sessionVariables = localeVars;

View file

@ -23,6 +23,9 @@ in {
# fontconfig by default. # fontconfig by default.
fonts.fontconfig.enable = lib.mkDefault fonts.fontconfig.enable = lib.mkDefault
(cfg.useUserPackages && config.fonts.fontconfig.enable); (cfg.useUserPackages && config.fonts.fontconfig.enable);
# Inherit glibcLocales setting from NixOS.
i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales;
}]; }];
}; };
} }

View file

@ -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}'
'';
};
};
} }

View file

@ -9,7 +9,7 @@ let
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
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 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

@ -10,7 +10,7 @@
assertFileExists $envFile assertFileExists $envFile
assertFileContent $envFile ${ assertFileContent $envFile ${
pkgs.writeText "expected" '' 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_CACHE_HOME=/home/hm-user/.cache
XDG_CONFIG_DIRS=/etc/xdg:/foo/bar''${XDG_CONFIG_DIRS:+:$XDG_CONFIG_DIRS} XDG_CONFIG_DIRS=/etc/xdg:/foo/bar''${XDG_CONFIG_DIRS:+:$XDG_CONFIG_DIRS}
XDG_CONFIG_HOME=/home/hm-user/.config XDG_CONFIG_HOME=/home/hm-user/.config

View file

@ -1,4 +1,4 @@
{ pkgs, ... }: { config, pkgs, ... }:
{ {
systemd.user.sessionVariables = { systemd.user.sessionVariables = {
@ -11,7 +11,7 @@
assertFileExists $envFile assertFileExists $envFile
assertFileContent $envFile ${ assertFileContent $envFile ${
pkgs.writeText "expected" '' 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_int=1
V_str=2 V_str=2
XDG_CACHE_HOME=/home/hm-user/.cache XDG_CACHE_HOME=/home/hm-user/.cache