1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.xdg.terminal-exec;
10 inherit (lib)
11 mkIf
12 mkEnableOption
13 mkOption
14 mkPackageOption
15 types
16 ;
17in
18{
19 meta.maintainers = with lib.maintainers; [ Cryolitia ];
20
21 ###### interface
22
23 options = {
24 xdg.terminal-exec = {
25 enable = mkEnableOption "xdg-terminal-exec, the [proposed](https://gitlab.freedesktop.org/xdg/xdg-specs/-/merge_requests/46) Default Terminal Execution Specification";
26 package = mkPackageOption pkgs "xdg-terminal-exec" { };
27 settings = mkOption {
28 type = with types; attrsOf (listOf str);
29 default = { };
30 description = ''
31 Configuration options for the Default Terminal Execution Specification.
32
33 The keys are the desktop environments that are matched (case-insensitively) against `$XDG_CURRENT_DESKTOP`,
34 or `default` which is used when the current desktop environment is not found in the configuration.
35 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.
36 '';
37 example = {
38 default = [ "kitty.desktop" ];
39 GNOME = [
40 "com.raggesilver.BlackBox.desktop"
41 "org.gnome.Terminal.desktop"
42 ];
43 };
44 };
45 };
46 };
47
48 ###### implementation
49
50 config = mkIf cfg.enable {
51 environment = {
52 systemPackages = [ cfg.package ];
53
54 etc = lib.mapAttrs' (
55 desktop: terminals:
56 # map desktop name such as GNOME to `xdg/gnome-xdg-terminals.list`, default to `xdg/xdg-terminals.list`
57 lib.nameValuePair (
58 "xdg/${if desktop == "default" then "" else "${lib.toLower desktop}-"}xdg-terminals.list"
59 ) { text = lib.concatLines terminals; }
60 ) cfg.settings;
61 };
62 };
63}