Files
2026-10-23 15:18:56 +02:00

54 lines
1.9 KiB
Nix

{ pkgs, config, ... }:
let
termfilechooser = pkgs.xdg-desktop-portal-termfilechooser;
in
{
# Use yazi (in alacritty) as the file picker for every app that goes through
# the XDG FileChooser portal.
#
# Portal/D-Bus files are found through XDG_DATA_DIRS (user profile), so we
# deliberately don't enable HM's `xdg.portal`: it would point
# NIX_XDG_DESKTOP_PORTAL_DIR at the user profile only and hide the
# system-wide gnome/gtk portals that niri relies on.
home.packages = [ termfilechooser ];
# The D-Bus activation file references this unit by name, and HM doesn't
# link `share/systemd/user` from packages.
systemd.user.services.xdg-desktop-portal-termfilechooser = {
Unit = {
Description = "Portal service (terminal file chooser implementation)";
PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ];
};
Service = {
Type = "dbus";
BusName = "org.freedesktop.impl.portal.desktop.termfilechooser";
ExecStart = "${termfilechooser}/libexec/xdg-desktop-portal-termfilechooser";
Environment = [ "PATH=${config.home.profileDirectory}/bin:/run/current-system/sw/bin" ];
Restart = "on-failure";
Slice = "session.slice";
};
};
xdg.configFile = {
# Overrides niri's shipped niri-portals.conf, so its entries are repeated here.
"xdg-desktop-portal/niri-portals.conf".text = ''
[preferred]
default=gnome;gtk;
org.freedesktop.impl.portal.Access=gtk;
org.freedesktop.impl.portal.Notification=gtk;
org.freedesktop.impl.portal.Secret=gnome-keyring;
org.freedesktop.impl.portal.FileChooser=termfilechooser;
'';
"xdg-desktop-portal-termfilechooser/config".text = ''
[filechooser]
cmd=${termfilechooser}/share/xdg-desktop-portal-termfilechooser/yazi-wrapper.sh
default_dir=$HOME
env=TERMCMD=alacritty --title termfilechooser -e
open_mode=suggested
save_mode=suggested
'';
};
}