ERROR:object_proxy.cc(623) Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/portal/desktop: org.freedesktop.DBus.Error.InvalidArgs: No such interface “org.freedesktop.portal.FileChooser”

I try to build nix package by myself, the following is my file:

# This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
{
  qq-nt-x86_64-linux = {
    pname = "qq-nt-x86_64-linux";
    version = "3.1.2_12912";
    src = fetchurl {
      url = "https://dldir1.qq.com/qqfile/qq/QQNT/80d33f88/linuxqq_3.1.2-12912_amd64.deb";
      sha256 = "sha256-F+zIHqYWKiCHYNJZ5hRw0rzltizjuqhVxbpzQGagoZ0=";
    };
  };
}
{ mySources
, pkgs
, lib
, stdenv
, autoPatchelfHook
, dpkg ? stdenv.isLinux
, rsync ? stdenv.isLinux
, nss
, alsa-lib
, gtk3
, gjs
, at-spi2-core
, vips
, libdrm
, libgcrypt
, libkrb5
, mesa
, xdg-desktop-portal
}:

stdenv.mkDerivation rec {
  inherit (mySources."qq-nt-${pkgs.system}") pname version src;
  nativeBuildInputs = [
    autoPatchelfHook
    rsync
  ]
  ++
  (if lib.hasSuffix "deb" src then [ dpkg ] else [ ])
  ;
  buildInputs = [
    nss
    alsa-lib
    gtk3
    gjs
    at-spi2-core
    vips
    libdrm
    libgcrypt
    libkrb5
    mesa
  ];
  propagatedBuildInputs = [
    xdg-desktop-portal
  ];
  unpackPhase =
    if lib.hasSuffix "deb" src then ''
      dpkg -x "$src" .
    '' else "";
  buildPhase = "true";
  installPhase =
    if lib.hasSuffix "dmg" src then
      ''
        install -Dm755 "$src" -t "$out/Applications"
      ''
    else
      ''
        mkdir -p "$out"
        rsync -rv opt/ usr/ "$out/"
      '';

  meta = with lib; {
    homepage = "https://im.qq.com";
    description = "New QQ based on Electron";
    license = licenses.unfree;
    platforms = [ "x86_64-linux" "aarch64-linux" "loong64-linux" "x86_64-darwin" "aarch64-darwin" ];
  };
}

After nix-build, I try to run result/QQ/qq, but get

[1368667:0522/120115.839359:ERROR:object_proxy.cc(623)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/portal/desktop: org.freedesktop.DBus.Error.InvalidArgs: No such interface “org.freedesktop.portal.FileChooser”
[1368667:0522/120115.839380:ERROR:select_file_dialog_linux_portal.cc(242)] Failed to read portal version property
zsh: trace trap (core dumped)  result/QQ/qq

What something wrong I did? Thanks for any suggestion.

Nix derivations are meant to be self-contained. That means building a package should not otherwise affect your system. Unfortunately, that means it is not really possible to express dependencies on systemd/D-Bus services such as xdg-desktop-portal since those require being registered/installed to a directory where systemd daemon can find them.

Typically, we install service dependencies by creating an accompanying NixOS module. For example Flatpak depends on Polkit so it enables it in the module.

But XDG portals are considered part of the Freedesktop baseline these days so your desktop environment should install them out of the box. The modules for the big ones like GNOME or Plasma already do that but if you are rolling your own then you will need to enable it yourself.

So I must enable systemd/D-Bus services to avoid this error? How to do it?

You do it in your NixOS system configuration, see for example what GNOME module does:

I change my desktop enviroment to gnome to make sure this setting is enabled by default. Now I run result/QQ/qq, it will

$ result/QQ/qq
zsh: trace trap (core dumped)  result/QQ/qq

The error message about org.freedesktop.portal.FileChooser has disappeared. Does it mean the problem about org.freedesktop.portal.FileChooser has disappeared and it still have any other problem?

I found https://github.com/NixOS/nixpkgs/blob/7084250df3d7f9735087d3234407f3c1fc2400e3/pkgs/applications/networking/instant-messengers/qq/default.nix#L95 :smile: