1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-06 00:51:04 +01:00
home-manager/modules/programs/translate-shell.nix
Austin Horstman 107352dde4 treewide: add missing package option
Provide more customization to the binary to be installed.
2025-04-02 21:49:14 -05:00

50 lines
1.4 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.programs.translate-shell;
mkKeyValue = key: value:
let
formatValue = v:
if lib.isBool v then
(if v then "true" else "false")
else if lib.isString v then
''"${v}"''
else if lib.isList v then
"[ ${lib.concatStringsSep " " (map formatValue v)} ]"
else
toString v;
in ":${key} ${formatValue value}";
toKeyValue = lib.generators.toKeyValue { inherit mkKeyValue; };
in {
meta.maintainers = [ ];
options.programs.translate-shell = {
enable = lib.mkEnableOption "translate-shell";
package = lib.mkPackageOption pkgs "translate-shell" { nullable = true; };
settings = lib.mkOption {
type = with lib.types; attrsOf (oneOf [ bool str (listOf str) ]);
default = { };
example = {
verbose = true;
hl = "en";
tl = [ "es" "fr" ];
};
description = ''
Options to add to {file}`$XDG_CONFIG_HOME/translate-shell/init.trans` file.
See <https://github.com/soimort/translate-shell/wiki/Configuration>
for options.
'';
};
};
config = lib.mkIf cfg.enable {
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
xdg.configFile."translate-shell/init.trans" =
lib.mkIf (cfg.settings != { }) { text = "{${toKeyValue cfg.settings}}"; };
};
}