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,...}:letmy_terminal_desktop=["foot.desktop""Alacritty.desktop""kitty.desktop""com.mitchellh.ghostty.desktop"];in{environment.systemPackages=withpkgs;[# 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 / 报告中的疑问
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 模块增多,这种方式是否会变得难以管理?
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)。是否有办法让它只在确认这些终端已安装后才加入?
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.
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)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @DataEraserC on GitHub (May 11, 2025).
Background / 背景
I noticed that
nix-configlacks any configuration forxdg.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-execoption and found that it fixes this problem perfectly. Here’s the module I added undermodules/nixos/desktop/xdg-terminal-exec.nix:我试验了 NixOS 的
xdg.terminal-exec选项,发现它能完美解决这个问题。以下是在modules/nixos/desktop/xdg-terminal-exec.nix中添加的 module:Questions / 报告中的疑问
File Organization
1.1. Is placing this file under
modules/nixos/desktop/xdg-terminal-exec.nixright 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 模块增多,这种方式是否会变得难以管理?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)。是否有办法让它只在确认这些终端已安装后才加入?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.terminalsin the NixOS config; ifdesktop.terminals.kitty.enable = truethen automatically install and config kitty , and addkitty.desktoptoxdg.terminal-exec.settings.封装终端集合
在顶层 NixOS 配置中定义选项,例如
desktop.terminals;若desktop.terminals.kitty.enable = true,则自动安装、配置kitty,以及在xdg.terminal-exec.settings中加入kitty.desktop。(但是可能需要在nixos和home两侧均定义,并且在output里面统一enable)