From f04b1179d8273d8e7941e23f98809fbc4fc4afa5 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 27 Jul 2024 12:18:41 +0800 Subject: [PATCH] wrapper-manager-fds/modules: add locale option for global env and per-wrapper --- modules/env/home-manager/default.nix | 12 ++++++- modules/env/nixos/default.nix | 12 ++++++- modules/wrapper-manager/default.nix | 1 + modules/wrapper-manager/locale.nix | 51 ++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 modules/wrapper-manager/locale.nix diff --git a/modules/env/home-manager/default.nix b/modules/env/home-manager/default.nix index b79f176..5562068 100644 --- a/modules/env/home-manager/default.nix +++ b/modules/env/home-manager/default.nix @@ -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; diff --git a/modules/env/nixos/default.nix b/modules/env/nixos/default.nix index ae45715..a2bf0c5 100644 --- a/modules/env/nixos/default.nix +++ b/modules/env/nixos/default.nix @@ -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 = diff --git a/modules/wrapper-manager/default.nix b/modules/wrapper-manager/default.nix index ba624f5..3df876a 100644 --- a/modules/wrapper-manager/default.nix +++ b/modules/wrapper-manager/default.nix @@ -3,6 +3,7 @@ ./base.nix ./xdg-desktop-entries.nix ./xdg-dirs.nix + ./locale.nix ./build.nix ./extra-args.nix ]; diff --git a/modules/wrapper-manager/locale.nix b/modules/wrapper-manager/locale.nix new file mode 100644 index 0000000..617c54a --- /dev/null +++ b/modules/wrapper-manager/locale.nix @@ -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); + }; +}