mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-08-24 20:23:55 +02:00
At login the xdg-autostart-generator starts apps at graphical-session.target, racing the portal user services. Sandboxed apps (nixpak firefox/telegram) end up with broken FileChooser/OpenURI until manually restarted. Add a template drop-in on app-@autostart.service that makes every autostart app wait for the portal stack.
78 lines
2.6 KiB
Nix
78 lines
2.6 KiB
Nix
{ lib, pkgs, ... }:
|
|
{
|
|
xdg.terminal-exec = {
|
|
enable = true;
|
|
package = pkgs.xdg-terminal-exec;
|
|
settings =
|
|
let
|
|
my_terminal_desktop = [
|
|
# NOTE: We have add these packages at user level
|
|
"Alacritty.desktop"
|
|
"kitty.desktop"
|
|
"foot.desktop"
|
|
"com.mitchellh.ghostty.desktop"
|
|
];
|
|
in
|
|
{
|
|
GNOME = my_terminal_desktop ++ [
|
|
"com.raggesilver.BlackBox.desktop"
|
|
"org.gnome.Terminal.desktop"
|
|
];
|
|
niri = my_terminal_desktop;
|
|
default = my_terminal_desktop;
|
|
};
|
|
};
|
|
|
|
xdg = {
|
|
autostart.enable = lib.mkDefault true;
|
|
menus.enable = lib.mkDefault true;
|
|
mime.enable = lib.mkDefault true;
|
|
icons.enable = lib.mkDefault true;
|
|
};
|
|
|
|
xdg.portal = {
|
|
enable = true;
|
|
|
|
config = {
|
|
common = {
|
|
# Use xdg-desktop-portal-gtk for every portal interface...
|
|
default = [
|
|
"gtk"
|
|
"gnome"
|
|
];
|
|
};
|
|
};
|
|
|
|
# Sets environment variable NIXOS_XDG_OPEN_USE_PORTAL to 1
|
|
# This will make xdg-open use the portal to open programs,
|
|
# which resolves bugs involving programs opening inside FHS envs or with unexpected env vars set from wrappers.
|
|
# xdg-open is used by almost all programs to open a unknown file/uri
|
|
# alacritty as an example, it use xdg-open as default, but you can also custom this behavior
|
|
xdgOpenUsePortal = true;
|
|
|
|
# ls /run/current-system/sw/share/xdg-desktop-portal/portals/
|
|
extraPortals = with pkgs; [
|
|
xdg-desktop-portal-gtk # for provides file picker / OpenURI
|
|
xdg-desktop-portal-gnome # for screensharing
|
|
];
|
|
};
|
|
|
|
# The xdg-autostart-generator starts every autostart app (including nixpak
|
|
# sandboxes like firefox/telegram) right at graphical-session.target, while
|
|
# the portal user services come up around the same time (xdg-desktop-portal-gtk
|
|
# is even ordered after graphical-session.target). This template drop-in makes
|
|
# every `app-*@autostart.service` wait for the portal stack, so portal-dependent
|
|
# features (FileChooser upload/save dialogs, OpenURI) work on first launch
|
|
# instead of needing a manual app restart after login.
|
|
systemd.user.units."app-@autostart.service" = {
|
|
# Template drop-in: applies to every `app-*.desktop` instance generated by
|
|
# systemd-xdg-autostart-generator, current and future.
|
|
overrideStrategy = "asDropin";
|
|
text = ''
|
|
[Unit]
|
|
After=xdg-desktop-portal.service xdg-desktop-portal-gtk.service xdg-desktop-portal-gnome.service
|
|
Wants=xdg-desktop-portal.service xdg-desktop-portal-gtk.service xdg-desktop-portal-gnome.service
|
|
'';
|
|
};
|
|
}
|