summaryrefslogtreecommitdiffstats
path: root/nixos/modules/config/xdg/terminal-exec.nix
blob: 764a1ee6c0876bc8446ac2e7f5829ebf522fe2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{
  config,
  lib,
  pkgs,
  ...
}:

let
  cfg = config.xdg.terminal-exec;
  inherit (lib)
    mkIf
    mkEnableOption
    mkOption
    mkPackageOption
    types
    ;
in
{
  meta.maintainers = with lib.maintainers; [ Cryolitia ];

  ###### interface

  options = {
    xdg.terminal-exec = {
      enable = mkEnableOption "xdg-terminal-exec, the [proposed](https://gitlab.freedesktop.org/xdg/xdg-specs/-/merge_requests/46) Default Terminal Execution Specification";
      package = mkPackageOption pkgs "xdg-terminal-exec" { };
      settings = mkOption {
        type = with types; attrsOf (listOf str);
        default = { };
        description = ''
          Configuration options for the Default Terminal Execution Specification.

          The keys are the desktop environments that are matched (case-insensitively) against `$XDG_CURRENT_DESKTOP`,
          or `default` which is used when the current desktop environment is not found in the configuration.
          The values are a list of terminals' [desktop file IDs](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s02.html#desktop-file-id) to try in order of decreasing priority.
        '';
        example = {
          default = [ "kitty.desktop" ];
          GNOME = [
            "com.raggesilver.BlackBox.desktop"
            "org.gnome.Terminal.desktop"
          ];
        };
      };
    };
  };

  ###### implementation

  config = mkIf cfg.enable {
    environment = {
      systemPackages = [ cfg.package ];

      etc = lib.mapAttrs' (
        desktop: terminals:
        # map desktop name such as GNOME to `xdg/gnome-xdg-terminals.list`, default to `xdg/xdg-terminals.list`
        lib.nameValuePair "xdg/${
          if desktop == "default" then "" else "${lib.toLower desktop}-"
        }xdg-terminals.list" { text = lib.concatLines terminals; }
      ) cfg.settings;
    };
  };
}