Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatpaks with DBusActivatable=true fail to start through menu #138956

Closed
mrckndt opened this issue Sep 22, 2021 · 22 comments · Fixed by #222678
Closed

Flatpaks with DBusActivatable=true fail to start through menu #138956

mrckndt opened this issue Sep 22, 2021 · 22 comments · Fixed by #222678
Labels
0.kind: bug 6.topic: GNOME GNOME desktop environment and its underlying platform

Comments

@mrckndt
Copy link

mrckndt commented Sep 22, 2021

Describe the bug

When trying to start a flatpak which contains DBusActivatable=true in its .desktop file it refuses to start (tested in GNOME shell). Commenting out DBusActivatable=true (tested in copied .desktop to home dir) or just flatpak run .... seems to work fine.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install e.g. org.gnome.Geary
  2. Run it from GNOME shell

Expected behavior

Flatpak should open.

Notify maintainers

@jtojnar

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
 - host os: `Linux 5.12.13-xanmod1-cacule, NixOS, 21.05.3294.3397f0ede9e (Okapi)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.15`
 - channels(root): `"nixos-21.05.3294.3397f0ede9e"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
@Artturin
Copy link
Member

Try this, maybe it'll give a error or something
nix run nixos.gnome.gtk -c gtk-launch foot
foot terminal used as a example desktop file in share/applications

@jtojnar
Copy link
Member

jtojnar commented Sep 22, 2021

Pre-requisite would be Flatpak linking D-Bus service files to a well-known location. Not sure if it currently does that.

https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html#d-bus-activation

@mrckndt
Copy link
Author

mrckndt commented Sep 22, 2021

Try this, maybe it'll give a error or something
nix run nixos.gnome.gtk -c gtk-launch foot
foot terminal used as a example desktop file in share/applications

@Artturin there is nothing. Tbh i don't get how this helps. FWIW gnome-maps (also with dbus actication) installed with nix works; the gnome-maps flatpak not.

@mrckndt
Copy link
Author

mrckndt commented Sep 22, 2021

@jtojnar on both my Fedora Silverblue machine and NixOS machine the services are symlinked to the same location if that's what you mean.

(chapek9) ~ $ ls -l /var/lib/flatpak/exports/share/dbus-1/services/org.gnome.Geary.service
lrwxrwxrwx. 1 root root 99 21. Sep 02:30 /var/lib/flatpak/exports/share/dbus-1/services/org.gnome.Geary.service -> ../../../../app/org.gnome.Geary/current/active/export/share/dbus-1/services/org.gnome.Geary.service

@jtojnar
Copy link
Member

jtojnar commented Sep 22, 2021

Maybe we need to add /var/lib/flatpak/exports to services.dbus.packages:

serviceDirectories = cfg.packages;

https://github.com/NixOS/nixpkgs/blob/63ec2613bd109c36d29aaf015152da92a7984f7f/pkgs/development/libraries/dbus/make-dbus-conf.nix

@Artturin Artturin self-assigned this Sep 22, 2021
@Artturin
Copy link
Member

Artturin commented Sep 22, 2021

screenshot_2021-09-22_22-10-35_735147180

screenshot_2021-09-22_22-11-27_282383802

screenshot_2021-09-22_22-15-16_210146900

@jtojnar
Copy link
Member

jtojnar commented Sep 22, 2021

Did you try adding the path to services.dbus.packages?

@Artturin
Copy link
Member

Did you try adding the path to services.dbus.packages?

yes
/var/lib/flatpak/exports

/var/lib/flatpak/exports/share/dbus-1/services
got added to /etc/dbus-1/session.conf
doesn't work

@Artturin
Copy link
Member

this is what i have for now
i switched to dbus-broker since fedora is using that and it has better logs

it does find the geany service file but it Failed at step EXEC spawning flatpak: No such file or directory

if someone wants to try:

this patch applied to nixos-unstable branch
very rough for now

diff --git a/nixos/modules/services/desktops/flatpak.nix b/nixos/modules/services/desktops/flatpak.nix
index 7da92cc9f26..868714ce603 100644
--- a/nixos/modules/services/desktops/flatpak.nix
+++ b/nixos/modules/services/desktops/flatpak.nix
@@ -28,11 +28,59 @@ in {
       }
     ];
 
-    environment.systemPackages = [ pkgs.flatpak ];
+    environment.systemPackages = [ pkgs.flatpak pkgs.xdg-dbus-proxy pkgs.dbus-broker ];
 
-    services.dbus.packages = [ pkgs.flatpak ];
+    services.dbus.packages = [ pkgs.flatpak /*"/var/lib/flatpak/exports"*/ ];
 
-    systemd.packages = [ pkgs.flatpak ];
+    systemd.services.dbus-broker = {
+      path = [ pkgs.flatpak ];
+      enable = true;
+      aliases = [ "dbus.service" ];
+      # Don't restart dbus-daemon. Bad things tend to happen if we do.
+      reloadIfChanged = true;
+      restartTriggers = [ "/etc/dbus-1" ];
+      environment = { LD_LIBRARY_PATH = config.system.nssModules.path; };
+    };
+    systemd.user.services.dbus-broker = {
+      path = [ pkgs.flatpak ];
+      enable = true;
+      wantedBy = [ "default.target" ];
+      aliases = [ "dbus.service" ];
+      # Don't restart dbus-daemon. Bad things tend to happen if we do.
+      reloadIfChanged = true;
+      restartTriggers = [ "/etc/dbus-1" ];
+      environment = { LD_LIBRARY_PATH = config.system.nssModules.path; };
+    };
+
+    #systemd.services.dbus = {
+    #  enable = true;
+    #  aliases = [ "dbus.service" ];
+    #};
+    #systemd.user.services.dbus = {
+    #  enable = true;
+    #  aliases = [ "dbus.service" ];
+    #};
+
+    systemd.sockets.dbus = {
+      description = "D-Bus System Message Bus Socket";
+      wantedBy = [ "sockets.target" ];
+      socketConfig = { 
+        ListenStream = "/run/dbus/system_bus_socket";
+      };
+    };
+
+    systemd.user.sockets.dbus = {
+      description = "D-Bus System Message Bus Socket";
+      wantedBy = [ "sockets.target" ];
+      socketConfig = { 
+        ListenStream = "%t/bus";
+        ExecStartPost = "-/run/current-system/systemd/bin/systemctl --user set-environment DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus";
+      };
+    };
+    #systemd.services.dbus.enable = false;
+    #systemd.user.services.dbus.enable = false;
+
+    systemd.packages = [ pkgs.flatpak pkgs.dbus-broker ];
 
     environment.profiles = [
       "$HOME/.local/share/flatpak/exports"
diff --git a/nixos/modules/services/system/dbus.nix b/nixos/modules/services/system/dbus.nix
index d4cacb85694..85eb4350f73 100644
--- a/nixos/modules/services/system/dbus.nix
+++ b/nixos/modules/services/system/dbus.nix
@@ -102,7 +102,7 @@ in
 
     users.groups.messagebus.gid = config.ids.gids.messagebus;
 
-    systemd.packages = [ pkgs.dbus.daemon ];
+    #systemd.packages = [ pkgs.dbus.daemon ];
 
     security.wrappers.dbus-daemon-launch-helper = {
       source = "${pkgs.dbus.daemon}/libexec/dbus-daemon-launch-helper";
diff --git a/pkgs/os-specific/linux/dbus-broker/default.nix b/pkgs/os-specific/linux/dbus-broker/default.nix
index b7e0a6b6158..631c173e1ed 100644
--- a/pkgs/os-specific/linux/dbus-broker/default.nix
+++ b/pkgs/os-specific/linux/dbus-broker/default.nix
@@ -23,6 +23,11 @@ stdenv.mkDerivation rec {
   PKG_CONFIG_SYSTEMD_SYSTEMDUSERUNITDIR = "${placeholder "out"}/lib/systemd/user";
   PKG_CONFIG_SYSTEMD_CATALOGDIR = "${placeholder "out"}/lib/systemd/catalog";
 
+  postPatch = ''
+    substituteInPlace src/launch/launcher.c \
+      --replace "/usr/share/dbus-1" "${dbus.daemon}/share/dbus-1"
+  '';
+
   postInstall = ''
     install -Dm644 $src/README.md $out/share/doc/dbus-broker/README
 
{
  inputs = {
    #nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixpkgs.url = "/home/artturin/nixgits/my-nixpkgs";
    #nixpkgs.url = "path:../nixgits/nixpkgs1";
    #pkgsReview.url = "github:Artturin/nixpkgs/pipewirejackldpath";
    #pkgsReview.url = "path:../nixgits/my-nixpkgs";
  };

  outputs = inputs@{ self, nixpkgs, /*pkgsReview*/ }: {

    nixosConfigurations.vm = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = { inherit inputs; };
      modules = [
        ({ pkgs, ... }: {
          #hardware.video.hidpi.enable = true;
        })
        ({ pkgs, ... }: {
          #disabledModules = [ "services/desktops/pipewire/pipewire.nix" ];
          imports = [
            #"${inputs.pkgsReview}/nixos/modules/services/desktops/pipewire/pipewire.nix"

            #"${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/iso-image.nix"
            #"${inputs.nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix"
            ## For virtualisation settings
            "${inputs.nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix"
            "${inputs.nixpkgs}/nixos/modules/profiles/clone-config.nix"
            "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix"
          ];
          environment.systemPackages = with pkgs; [
            (neovim.override { viAlias = true; vimAlias = true;})
            ranger
            ripgrep
            tree
            #firefox
          ];

          #hardware.pulseaudio.enable = true;

          services.xserver = {
            enable = true;
            #displayManager.lightdm = {
            #  enable = true;
            #};
            displayManager.autoLogin = {
              user = "user";
              enable = true;
            };
            desktopManager.gnome = {
              enable = true;
            };
          };

          environment.gnome.excludePackages = with pkgs.gnome; [
            gnome-weather
            gnome-calendar
            gnome-maps
            gnome-contacts
            gnome-software
            gnome-calculator
            gnome-calendar
            gnome-characters
            gnome-clocks
            gnome-font-viewer
            gnome-logs
            gnome-maps
            gnome-music
            pkgs.gnome-photos
            totem
            epiphany
            geary
            gnome-disk-utility
            seahorse
            sushi
            evince
            cheese
            eog
            baobab
            pkgs.evolution
            gnome-backgrounds
          ];

          services.flatpak.enable = true;
          # Documentation for these is in nixos/modules/virtualisation/qemu-vm.nix
          virtualisation = {
            memorySize = 1024 * 3;
            diskSize = 1024 * 4;
            cores = 8;
          };

          programs = {
            zsh.enable = true;
          };
          environment.etc."zshrc.local" = { source = "${pkgs.grml-zsh-config}/etc/zsh/zshrc"; };

          boot.tmpOnTmpfs = true;
          #boot.tmpOnTmpfsSize = "80%";

          documentation.enable = false;
          users.mutableUsers = false;
          users.defaultUserShell = pkgs.zsh;
          users.users.root = {
            password = "root";
          };
          users.users.user = {
            password = "user";
            isNormalUser = true;
            extraGroups = [ "wheel" ];
          };
        })
      ];
    };
    # So that we can just run 'nix run' instead of
    # 'nix build ".#nixosConfigurations.vm.config.system.build.vm" && ./result/bin/run-nixos-vm'
    defaultPackage.x86_64-linux = self.nixosConfigurations.vm.config.system.build.vm;
    defaultApp.x86_64-linux = {
      type = "app";
      program = "${self.defaultPackage.x86_64-linux}/bin/run-nixos-vm";
    };
  };
}

nix run to run this vm

@veprbl veprbl added the 6.topic: GNOME GNOME desktop environment and its underlying platform label Sep 23, 2021
@stale
Copy link

stale bot commented Apr 19, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 19, 2022
@keanuk
Copy link
Contributor

keanuk commented Aug 8, 2022

I am still having this issue in 22.05 and the 22.11 unstable channel. I get the following log output when trying to launch one of the Flatpaks in question:
Activated service 'org.gnome.Boxes' failed: Failed to execute program org.gnome.Boxes: No such file or directory

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 8, 2022
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/some-flatpaks-fail-to-launch-from-launcher-icon/20818/3

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/some-flatpaks-fail-to-launch-from-launcher-icon/20818/4

@sambuca1g
Copy link

sambuca1g commented Sep 18, 2022

The patch hasn't been applied to unstable. The issue still persists...

@alaviss
Copy link
Contributor

alaviss commented Dec 9, 2022

Here's my fix for the issue if you use dbus-broker:

{ pkgs, ... }:

{
  systemd.packages = [
    (pkgs.writeTextFile {
      name = "flatpak-dbus-overrides";
      destination = "/etc/systemd/user/dbus-.service.d/flatpak.conf";
      text = ''
        [Service]
        ExecSearchPath=${pkgs.flatpak}/bin
      '';
    })
  ];
}

This "solution" is based on the fact dbus-broker launch services via systemd using transient units with prefix dbus-.

systemd however does not have flatpak in its PATH and these transient units do not have them specified either.

The drop-in is used to point systemd to where it could find flatpak.

EDIT: Updated to not use systemd.services as it injects environment variables override that may break other applications.

@meisme-dev
Copy link

Same issue on unstable

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/boxes-flatpak-wont-start/28702/4

@Artturin Artturin removed their assignment Jun 5, 2023
@uricot
Copy link

uricot commented Jun 11, 2023

Having the same issue on nixos unstable channel

@kenos1
Copy link
Contributor

kenos1 commented Jun 17, 2023

Same issue on 23.05

@Irate-Walrus
Copy link

I'm experiencing the same behaviour in sway with gnome.nautilus and flatpaks. However, the error I receive from .nautilus-wrapp gives no owner for PackageKit errors, so may be unrelated.

@Xyphyn
Copy link

Xyphyn commented Jul 16, 2023

This seems like quite a critical issue, any updates? Same error.

~ gapplication launch org.gnome.Boxes         
error sending Activate message to application: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ExecFailed: Failed to execute program org.gnome.Boxes: No such file or directory
➜  ~ 

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/flatpak-telegram-desktop-desktop-entry-problems/31374/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug 6.topic: GNOME GNOME desktop environment and its underlying platform
Projects
None yet