[FR]: Add xdg-terminal-exec Configuration #57

Closed
opened 2025-12-29 04:21:10 +01:00 by adam · 0 comments
Owner

Originally created by @DataEraserC on GitHub (May 11, 2025).

Background / 背景

I noticed that nix-config lacks any configuration for xdg.terminal-exec. As a result, when I right-click a file in some file managers (or elsewhere) and choose “Open With → nvim”, it may launch in a terminal other than my preferred one.
我发现 nix-config 缺少对 xdg.terminal-exec 的配置。这样当我在某些文件管理器或者其他地方右键选择“使用 nvim 打开”时,可能会在一个并非我期望的终端中启动。


Proposed Configuration / 建议的配置

I experimented with the NixOS xdg.terminal-exec option and found that it fixes this problem perfectly. Here’s the module I added under modules/nixos/desktop/xdg-terminal-exec.nix:
我试验了 NixOS 的 xdg.terminal-exec 选项,发现它能完美解决这个问题。以下是在 modules/nixos/desktop/xdg-terminal-exec.nix 中添加的 module:

{ lib, pkgs, ... }:

let
  my_terminal_desktop = [
    "foot.desktop"
    "Alacritty.desktop"
    "kitty.desktop"
    "com.mitchellh.ghostty.desktop"
  ];
in {
  environment.systemPackages = with pkgs; [
    # NOTE: These are installed in my home config
    # foot
    # Alacritty
    # kitty
    # ghostty
  ];

  xdg.terminal-exec = {
    enable  = true;
    package = pkgs.xdg-terminal-exec-mkhl;
    settings = {
      GNOME    = [ "com.raggesilver.BlackBox.desktop" "org.gnome.Terminal.desktop" ] ++ my_terminal_desktop;
      niri     = my_terminal-desktop;
      default  = my_terminal-desktop;
    };
  };
}

Questions / 报告中的疑问

  1. File Organization
    1.1. Is placing this file under modules/nixos/desktop/xdg-terminal-exec.nix right and maintainable, or might it become hard to manage as the number of desktop modules grows?
    1.1 将该文件放在 modules/nixos/desktop/xdg-terminal-exec.nix 目录下是否合适并且可维护?随着 desktop 模块增多,这种方式是否会变得难以管理?

  2. Conditional Terminal List
    2.1. The current list is hard-coded (foot, Alacritty, kitty, ghostty). Is there a way to automatically include only those terminals that are actually installed (e.g., via a check in the module)?
    2.1 现在的列表是写死的(footAlacrittykittyghostty)。是否有办法让它只在确认这些终端已安装后才加入?

  3. Separation Between NixOS Module and Home Packages
    3.1. This config lives in a NixOS module (and the option comes from NixOS), but the terminals themselves are installed via home-manager. Is this separation problematic?
    3.1 该配置写在 NixOS module 中(且选项来源于 NixOS),而终端却安装在 home-manager。这样分离是否有问题?


Possible Enhancement / 可行的改进思路

  • Wrap Terminal Collections
    Define a top-level option such as desktop.terminals in the NixOS config; if desktop.terminals.kitty.enable = true then automatically install and config kitty , and add kitty.desktop to xdg.terminal-exec.settings.

  • 封装终端集合
    在顶层 NixOS 配置中定义选项,例如 desktop.terminals;若 desktop.terminals.kitty.enable = true,则自动安装、配置kitty,以及在 xdg.terminal-exec.settings 中加入 kitty.desktop。(但是可能需要在nixoshome两侧均定义,并且在output里面统一enable)

Originally created by @DataEraserC on GitHub (May 11, 2025). ### Background / 背景 I noticed that `nix-config` lacks any configuration for `xdg.terminal-exec`. As a result, when I right-click a file in some file managers (or elsewhere) and choose “Open With → nvim”, it may launch in a terminal other than my preferred one. 我发现 `nix-config` 缺少对 `xdg.terminal-exec` 的配置。这样当我在某些文件管理器或者其他地方右键选择“使用 nvim 打开”时,可能会在一个并非我期望的终端中启动。 --- ### Proposed Configuration / 建议的配置 I experimented with the NixOS `xdg.terminal-exec` option and found that it fixes this problem perfectly. Here’s the module I added under [`modules/nixos/desktop/xdg-terminal-exec.nix`](https://github.com/Program-Learning/nix-config/blob/main/modules/nixos/desktop/xdg-terminal-exec.nix#L20-L33): 我试验了 NixOS 的 `xdg.terminal-exec` 选项,发现它能完美解决这个问题。以下是在 `modules/nixos/desktop/xdg-terminal-exec.nix` 中添加的 module: ```nix { lib, pkgs, ... }: let my_terminal_desktop = [ "foot.desktop" "Alacritty.desktop" "kitty.desktop" "com.mitchellh.ghostty.desktop" ]; in { environment.systemPackages = with pkgs; [ # NOTE: These are installed in my home config # foot # Alacritty # kitty # ghostty ]; xdg.terminal-exec = { enable = true; package = pkgs.xdg-terminal-exec-mkhl; settings = { GNOME = [ "com.raggesilver.BlackBox.desktop" "org.gnome.Terminal.desktop" ] ++ my_terminal_desktop; niri = my_terminal-desktop; default = my_terminal-desktop; }; }; } ``` --- ### Questions / 报告中的疑问 1. **File Organization** 1.1. Is placing this file under `modules/nixos/desktop/xdg-terminal-exec.nix` right and maintainable, or might it become hard to manage as the number of desktop modules grows? 1.1 将该文件放在 `modules/nixos/desktop/xdg-terminal-exec.nix` 目录下是否合适并且可维护?随着 desktop 模块增多,这种方式是否会变得难以管理? 2. **Conditional Terminal List** 2.1. The current list is hard-coded (`foot`, `Alacritty`, `kitty`, `ghostty`). Is there a way to automatically include only those terminals that are actually installed (e.g., via a check in the module)? 2.1 现在的列表是写死的(`foot`、`Alacritty`、`kitty`、`ghostty`)。是否有办法让它只在确认这些终端已安装后才加入? 3. **Separation Between NixOS Module and Home Packages** 3.1. This config lives in a NixOS module (and the option comes from NixOS), but the terminals themselves are installed via home-manager. Is this separation problematic? 3.1 该配置写在 NixOS module 中(且选项来源于 NixOS),而终端却安装在 home-manager。这样分离是否有问题? --- ### Possible Enhancement / 可行的改进思路 * **Wrap Terminal Collections** Define a top-level option such as `desktop.terminals` in the NixOS config; if `desktop.terminals.kitty.enable = true` then automatically install and config kitty , and add `kitty.desktop` to `xdg.terminal-exec.settings`. * **封装终端集合** 在顶层 NixOS 配置中定义选项,例如 `desktop.terminals`;若 `desktop.terminals.kitty.enable = true`,则自动安装、配置kitty,以及在 `xdg.terminal-exec.settings` 中加入 `kitty.desktop`。(但是可能需要在[nixos](https://github.com/ryan4yin/nix-config/blob/main/outputs/x86_64-linux/src/idols-ai.nix#L39)和[home](https://github.com/ryan4yin/nix-config/blob/main/outputs/x86_64-linux/src/idols-ai.nix#L47)两侧均定义,并且在output里面统一enable)
adam closed this issue 2025-12-29 04:21:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/nix-config-ryan4yin#57