wrapper-manager-fds/modules: add locale option for global env and per-wrapper

This commit is contained in:
Gabriel Arazas 2024-07-27 12:18:41 +08:00
parent aef2ac2825
commit f04b1179d8
4 changed files with 74 additions and 2 deletions

View File

@ -1,4 +1,4 @@
{ config, lib, ... }:
{ config, lib, ... }@moduleArgs:
let
cfg = config.wrapper-manager;
@ -11,6 +11,16 @@ in
config = lib.mkMerge [
{ wrapper-manager.extraSpecialArgs.hmConfig = config; }
(lib.mkIf moduleArgs?nixosConfig {
wrapper-manager.sharedModules = [
({ lib, ... }: {
# NixOS already has the option to set the locale so we don't need to
# have this.
config.locale.enable = lib.mkDefault false;
})
];
})
(lib.mkIf (cfg.packages != {}) {
home.packages =
lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.packages;

View File

@ -9,7 +9,17 @@ in
];
config = lib.mkMerge [
{ wrapper-manager.extraSpecialArgs.nixosConfig = config; }
{
wrapper-manager.extraSpecialArgs.nixosConfig = config;
wrapper-manager.sharedModules = [
({ lib, ... }: {
# NixOS already has the option to set the locale so we don't need to
# have this.
config.locale.enable = lib.mkDefault false;
})
];
}
(lib.mkIf (cfg.packages != {}) {
environment.systemPackages =

View File

@ -3,6 +3,7 @@
./base.nix
./xdg-desktop-entries.nix
./xdg-dirs.nix
./locale.nix
./build.nix
./extra-args.nix
];

View File

@ -0,0 +1,51 @@
{ config, lib, pkgs, ... }:
let
cfg = config.locale;
localeModuleFactory = { isGlobal ? false }: {
locale = {
enable = lib.mkOption {
type = lib.types.bool;
default = if isGlobal then true else cfg.enable;
description = if isGlobal then ''
Whether to enable explicit glibc locale support. This is recommended
for Nix-built applications.
'' else ''
Whether to enable locale support for this wrapper. Recommended for
Nix-built applications.
'';
};
package = lib.mkOption {
type = lib.types.package;
default =
if isGlobal
then (pkgs.glibcLocales.override { allLocales = true; })
else cfg.package;
description = ''
The package containing glibc locales.
'';
};
};
};
in
{
options.locale = localeModuleFactory { isGlobal = true; };
options.wrappers =
let
localeSubmodule = { config, lib, name, ... }: let
submoduleCfg = config.locale;
in {
options.locale = localeModuleFactory { isGlobal = false; };
config = lib.mkIf submoduleCfg.enable {
env.LOCALE_ARCHIVE = "${submoduleCfg.package}/lib/locale/locale-archive";
};
};
in
lib.mkOption {
type = with lib.types; attrsOf (submodule localeSubmodule);
};
}