-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
Apps launched by xdg-open can misbehave when called from FHS envs or wrapped programs #160923
Comments
Related issues:
|
Before we reinvent any wheels, how does Flatpak solve this problem? |
xdg-utils detects I'm not sure if making |
I mean, it basically is? Is there a non-Flatpak-specific way to handle portals? I imagine Snap and AppImage must be doing it somehow too. If they also use the Flatpak method, we should use it too. If they use a more generic way, we should use that. |
I was concerned that telling xdg-utils it's in a flatpak by making sure that |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/who-uses-nixos-with-kde/18212/10 |
So is this why links from Discord open in Chrome instead of my default browser? 🤔 |
It's possible although it's probably not that, it's more likely an issue with the xdg associations. If you use home-manager, try something like xdg-mime-apps.nix |
It's not that, firefox is the only thing I have set in my |
I've implemented a workaround for this as a nixos module which is exposed at Implementation at https://github.com/LunNova/nixos-configs/blob/dev/modules/exported/xdg-open-workaround.nix and https://github.com/LunNova/nixos-configs/blob/dev/packages/xdg-open-with-portal/default.nix Is this approach worth upstreaming? |
Is #176962 related to this issue? |
@LunNova yes please |
I would be glad if this problem can be solved generically, as it effects many applications (for me for example zettlr and marktext). I haven't tried your workaround, but it looks good when looking at the files. @LunNova How can I install your nixos module? |
Add
Add it as an argument to outputs, then add Not sure how best to do it if you don't use flakes. I'll try to get a PR to include this in nixpkgs shortly. |
@LunNova I haven't completely tried your approach, but one thing I noticed is that on my system |
Been somewhat distracted, hope to make a PR for this tonight. (Yes, this comment is an accountability post for myself so I'll actually do it :)) |
Draft PR up here: #187293 |
@deifactor I swapped it to use bash's "new" (from 2009 lol) syntax for auto selecting an available FD instead, hopefully that works on your machine! |
Looks like it works (that is, |
Not commenting on the quality of the fix itself, more "how did we get here". So if I understand correctly, the problem is that your FHS application can have an arbitrary environment, which get passed to xdg-open, which get in turn passed down to Firefox. On most distributions, this isn't a problem because you don't do weird stuff with environment variables (or if you do, you do so for your entire user session so you'll break firefox immediately), but nixpkgs' isolation means that the FHS application might have LD_PRELOAD, LD_LIBRARY_PATH, or some other weird thing set that isn't set when invoking it normally.
|
Yes, but it has a limited scope as once you manage to make a dbus call you're talking to the portal which isn't inheriting your environment, and it's only one combination to test (your program's env/fhs + gdbus) instead of your program's env/fhs + any other program in your system it might launch.
This works for wrapped programs but not FHS envs. FHS envs use namespaces/cgroups, you can't undo this just by clearing an environment variable. If your solution only needs to work for wrapped programs, clearing a set of env variables works. |
Freedesktop deleted their xdg-utils repo here so I can't see whether https://github.com/freedesktop/xdg-utils/pull/12 was declined or just not merged. I filed https://gitlab.freedesktop.org/xdg/xdg-utils/-/issues/240 asking upstream to implement a similar override. Thanks for this work. Perhaps this should be turned on by default for home-manager when running in an FHS env as I expect this will be a problem for many apps installed in that way. |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/cant-open-steam-links-from-proton-games/36734/4 |
This issue (I assume) is preventing me from logging into the JetBrains Toolbox. To login (I have a subscription that must be checked to give me access to the various applications), it redirects to the browser. First I get the "KIO-client" warning, not actually opening anything in Vivaldi. If I switch to Firefox, I am able to get to the app approval in the browser. However, Firefox appears to not be able to deal with this. I then took the url that was opened in Firefox, copied it over in Vivaldi, then approved it there. This then opened up an xdg-open dialog (the link is jetbrains://) which when clicked on does absolutely nothing. I'm fairly new to nixos, so I'm not entirely sure where to look up the relevant logs etc |
As I can see, Jetbrains Toolbox from nixpks doesn't handle |
That looks like a fairly trivial fix on the Nixpkgs side. |
For anyone with the KDE/vscodeFHS issue. I think you can fix it with some of the suggestions here. Remember to restart your PC after updating the portal settings. What worked for me was
|
Assuming that this option works in most/all use cases and doesn't break anything:
|
@K900 thoughts on changing the plasma 6 defaults like @viscountexx suggested? We could set the env var only in the plasma 6 session so it doesn't impact non-plasma sessions. |
We could mkDefault it I guess, but I'd be very careful with the potential side effects. |
So, I just stumbled on this while debugging an issue with a URL handler. The xdgOpenUsePortal definitely deals with the issue, but I end up with a much bigger problem. All of a sudden xdg-open seems to have a split personality. I call |
So, I decided to go the route of making .desktop files executable, and made an overlay to handle the bulk of it. It doesn't work with every package, but it seems to work for many. executableDesktopFiles = final: _prev: let
pkgs = import inputs.nixpkgs {
system = "x86_64-linux";
config.allowUnfree = true;
};
fixDesktop = name: pkg: pkgs.runCommand "${name}-exedesk" {} ''
mkdir -p $out/share/applications
cp -ur ${pkg.out}/* $out/
cp -nL ${pkg.out}/share/applications/* $out/share/applications || true
for f in $out/share/applications/*; do
target=$(readlink -f "$f")
if [ -L "$f" ]; then
rm "$f"
cp "$target" "$f"
fi
chmod +x "$f"
done
'';
in builtins.mapAttrs fixDesktop {
inherit (pkgs)
audacity
blender
brave
...
;
}; |
Based on the discussion here and the fact Firefox (with an executable .desktop file which brave doesn't have) works perfectly, while Joplin-Desktop opening links -> Brave browser does this: I'm having this same challenge... I'll give @sbuller's overlay a try and hope for a less hacky fix to this issue to eventually emerge. 🍻 |
Tried to incorporate @sbuller's overlay into my # MARK: Joplin-Desktop -> Brave URL Open fix
nixpkgs.overlays = [
(final: _prev: let
# pkgs = import inputs.nixpkgs {
# system = "x86_64-linux";
# config.allowUnfree = true;
# };
fixDesktop = name: pkg: pkgs.runCommand "${name}-exedesk" {} ''
mkdir -p $out/share/applications
cp -ur ${pkg.out}/* $out/
cp -nL ${pkg.out}/share/applications/* $out/share/applications || true
for f in $out/share/applications/*; do
target=$(readlink -f "$f")
if [ -L "$f" ]; then
rm "$f"
cp "$target" "$f"
fi
chmod +x "$f"
done
'';
in builtins.mapAttrs fixDesktop {
inherit (pkgs)
brave;
}
)
]; |
Sorry about that whole |
If that fixes launching you're probably launching the handler for that filetype inside the FHS bubblewrap container for the app you tried to open it from, so it's not a great solution. I recommend trying to get portals working correctly rather than marking .desktop files +x. KDE only thinks they need +x when it tries to launch inside a bubblewrap FHS containers because the .desktop files look like they're owned by #107826 decided making them executable was a bad idea. |
Yep, it's bad, I don't disagree... however that issue is also from 4 years ago and this issue is over 2 years old. This problem is annoying, I'll live with the risks using the workaround for it until there's a proper fix. Here's the full working code for @sbuller's workaround for anyone else that wants: # MARK: Joplin-Desktop -> Brave URL open workaround (credit: sbuller)
nixpkgs.overlays = [
(final: prev: let
fixDesktop = name: pkg: prev.runCommand "${name}-exedesk" {} ''
mkdir -p $out/share/applications
cp -ur ${pkg.out}/* $out/
cp -nL ${pkg.out}/share/applications/* $out/share/applications || true
for f in $out/share/applications/*; do
target=$(readlink -f "$f")
if [ -L "$f" ]; then
rm "$f"
cp "$target" "$f"
fi
chmod +x "$f"
done
'';
in builtins.mapAttrs fixDesktop {
inherit (prev)
brave;
}
)
]; |
I'm really struggling with debugging DBus here. Is it possible that kde / xdg-desktop-portal-kde just doesn't implement OpenURI, and when gdbus tries to call it gdbus just falls back to gio which then uses a default gnome config? |
The KDE portal should support OpenURI. What do you have set under xdg.portal? There's a Here's an example which sets it for KDE and i3 in case that helps. xdg.portal = {
enable = true;
xdgOpenUsePortal = true;
# I think the name under config has to match up with the value of XDG_CURRENT_DESKTOP.
# kde portal by default, fallback to anything for KDE and i3
# I don't set this for KDE in my personal config and it seems to work fine.
config.KDE.default = [ "kde" "*" ];
config.${"none+i3"}.default = [ "kde" "*" ];
extraPortals = [
pkgs.xdg-desktop-portal-gtk
pkgs.xdg-desktop-portal-wlr
];
}; |
I'd had xdg.portal = {
enable = true;
xdgOpenUsePortal = true;
wlr.enable = true;
extraPortals = [ pkgs.xdg-desktop-portal-kde ];
}; but no variation that I've tried has made any difference, including an exact copy of the above. In every instance (when xdgOpenUsePortal is set) I went and looked through https://github.com/KDE/xdg-desktop-portal-kde, and found no mention of OpenURI, but I'm not sure if that's the right place to look. |
Explicitly setting xdg.mime.{addedAssociations,defaultApplications} works around the issue for the mimetypes which I've set. This is unsatisfactory however, as I don't get to benefit from the long list of associations set by my desktop environment. |
Just a heads-up, we should probably update xdgUsePortal to use the env vars from https://gitlab.freedesktop.org/xdg/xdg-utils/-/merge_requests/112 if it is merged (seems likely) and remove our own patch |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/alvr-cant-launch-steamvr-steam-desktop-is-not-executable/43845/10 |
Just to clear it, the portal doesn't ask backends for the default application, it always uses glib to retrieve the default application and the list of applications. Backends are called only when the frontend wants to present app chooser dialog and backends get the apps list from the frontend which in turn gets it from glib. In other words, when you let portal handle your application defaults, you in fact let glib handle them. Which is not a bad thing I would say as xdg-open's offload to DE binaries with custom MIME handling is beating desktop Linux for a long time. While glib always follows mime-apps-spec. Plasma 5 used a custom way to handle initial defaults ( |
Describe the bug
When calling
xdg-open
from a FHS env or wrapped app, it tries to launch the associated program directly while either having unexpected/unrelated environment variables likeLD_PRELOAD
set or worse being in an FHS env which is entirely missing some dependencies.Ideally,
xdg-open
when used in a FHS env or wrapped package would usexdg-desktop-portal
to launch apps instead, similarly to how flatpaks use this to open other applications outside of the package.There is partial upstream support for this but it only applies in flatpaks:
https://github.com/freedesktop/xdg-utils/blob/1a58bc28f6844898532daf9ee1bf6da7764955a9/scripts/xdg-open.in#L250
https://github.com/freedesktop/xdg-utils/blob/d11b33ec7f24cfb1546f6b459611d440013bdc72/scripts/xdg-utils-common.in#L361-L363
It also doesn't handle local files correctly.
An example script which also handles files is here.
Steps To Reproduce
One example of this issue, although there are many related issues in different contexts.
Steps to reproduce the behavior:
Expected behavior
The
xdg-open
package in NixOS should usexdg-desktop-portal
to launch apps/urls/etc when possible as if it is inside a flatpak to avoid running apps in unexpected FHS envs or with unexpected env from wrappers.Screenshots
Notify maintainers
@edolstra - xdg-utils maintainer entry
@Atemu @illegalprime @wentasah - work on bwrap FHS envs
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.The text was updated successfully, but these errors were encountered: