fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.2 KiB52 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.translate-shell;
8
9  mkKeyValue = key: value:
10    let
11      formatValue = v:
12        if isBool v then
13          (if v then "true" else "false")
14        else if isString v then
15          ''"${v}"''
16        else if isList v then
17          "[ ${concatStringsSep " " (map formatValue v)} ]"
18        else
19          toString v;
20    in ":${key} ${formatValue value}";
21
22  toKeyValue = generators.toKeyValue { inherit mkKeyValue; };
23
24in {
25  meta.maintainers = [ ];
26
27  options.programs.translate-shell = {
28    enable = mkEnableOption "translate-shell";
29
30    settings = mkOption {
31      type = with types; attrsOf (oneOf [ bool str (listOf str) ]);
32      default = { };
33      example = {
34        verbose = true;
35        hl = "en";
36        tl = [ "es" "fr" ];
37      };
38      description = ''
39        Options to add to {file}`$XDG_CONFIG_HOME/translate-shell/init.trans` file.
40        See <https://github.com/soimort/translate-shell/wiki/Configuration>
41        for options.
42      '';
43    };
44  };
45
46  config = mkIf cfg.enable {
47    home.packages = [ pkgs.translate-shell ];
48
49    xdg.configFile."translate-shell/init.trans" =
50      mkIf (cfg.settings != { }) { text = "{${toKeyValue cfg.settings}}"; };
51  };
52}