How to install xdg-desktop-portal-termfilechooser?

okay. :triumph: i THINK i have finally managed it to work without home-manager and whatever, but ONLY for firefox/librewolf… theres a few problems though - it doesnt look like it works for steam, messengers, and etc., - for 25.05 using flakes, that is. problem two is that those errors i mentioned earlier didnt really go away… anyway, here is what i have done:

this is for wezterm and yazi
configuration.nix

# ...

environment.variables = {
  GTK_USE_PORTAL = "1"; # legacy
  GDK_DEBUG = "portals"; # termfilechooser
};

xdg = {
  mime.enable = true;
  mime.defaultApplications = {
    "application/x-gnome-saved-search" = "yazi.desktop";
    "application/x-directory" = "yazi.desktop";
    "inode/directory" = "yazi.desktop";
    "x-directory/normal" = "yazi.desktop";
    "x-scheme-handler/trash" = "yazi.desktop";
  };
  portal = {
    enable = true;
    # xdgOpenUsePortal = true; # NIXOS_XDG_OPEN_USE_PORTAL
    config = {
      common.default = [ "hyprland" ]; 
      common."org.freedesktop.impl.portal.FileChooser" = [ "termfilechooser" ]; # xdg-?
      hyprland.default = [ "hyprland" ]; 
      hyprland."org.freedesktop.impl.portal.FileChooser" = [ "termfilechooser" ]; # xdg-?
      lxqt.default = [ "lxqt" "hyprland" ];
      lxqt."org.freedesktop.impl.portal.FileChooser" = [ "termfilechooser" ]; # xdg-?
    };
    extraPortals = [
      pkgs.xdg-desktop-portal-hyprland
      # pkgs.lxqt.xdg-desktop-portal-lxqt # works without!
      pkgs.xdg-desktop-portal-termfilechooser 
    ];
  };
};

# ...

xdgOpenUsePortal should be false because termfilechooser is just a backend and not a portal, and should only be used for saving / picking dialogues, etc… i mean, it broke steam for me, for example! …but maybe im just silly.

~/.config/xdg-desktop-portal-termfilechooser/config

[filechooser]
cmd=$HOME/.config/xdg-desktop-portal-termfilechooser/yazi-wrapper.sh
default_dir=$HOME/Downloads

~/.config/xdg-desktop-portal-termfilechooser/yazi-wrapper.sh

#!/bin/sh

set -ex

multiple="$1"
directory="$2"
save="$3"
path="$4"
out="$5"
cmd="yazi"
termcmd="${TERMCMD:-wezterm start --always-new-process}"

if [ "$save" = "1" ]; then
    set -- --chooser-file="$out" "$path"
elif [ "$directory" = "1" ]; then
    set -- --chooser-file="$out" --cwd-file="$out" "$path"
elif [ "$multiple" = "1" ]; then
    set -- --chooser-file="$out" "$path"
else
    set -- --chooser-file="$out" "$path"
fi

command="$termcmd $cmd"
for arg in "$@"; do
    escaped=$(printf "%s" "$arg" | sed 's/"/\\"/g')
    command="$command \"$escaped\""
done

sh -c "$command"

librewolf/firefox about:config

widget.use-xdg-desktop-portal.file-picker = 1

so… all that just for browser’s “save as” dialogue… :sob: i probably broke something anyway…

is there a way to “enforce” it to apply to ALL applications? or at least specific apps? :woozy_face: