How to remove 'xdg-desktop-portal-gtk', where does it come from and why?

hello everyone.

daft noob here. my system has gotten an xdg-desktop-portal-gtk flu and cant seem to get better (perhaps it always had it)! dont want it, dont need it, i just want it gone…!! it just causes so much problems! ive tried literally everything. i have located its /nix/store/ whereabouts, but not its parent package its dependant on (i dont know how to do it + i checked every single option, variable and package i have… not to say i know what theyre doing, again) and it seems to be a D-BUS Service with the name of org.freedesktop.impl.portal.desktop.gtk - ok, how do i disable or remove it?! there is, as per usual, zero information on the internet…

thx in advance!!

Use nix-tree (3rd-party tool) to figure out what pulls it in. If it’s system-path, then use nixos-option environment.systemPackages to figure out what module adds it in. If it’s something else, now you know what package pulls it in.

1 Like

thanks! nix-tree is really great! didnt know about it - thank you. …so it looks like xdg-desktop-portal-gtk is a part of system-path with dbus-1 and user-units as immediate parents. no idea what is that supposed to mean…

im sorry, i dont really understand what do you mean by “use nixos-option environment.systemPackages to figure out what module adds it in”…? but i dont have it IN my systemPackages list…? i am completely lost…

P.S. is this some sort of a fallback portal with pre-installed gnome software? could be useful but not for me…

P.P.S. for context, i only want to leave my hyprland and lxqt environments, and i had this problem with some file openers where some gnome apps kept opening instead, with different interfaces and all. afaik they can be managed either via XDG portals or via XDG MIME associations, which i have both set. but that really freaked me out because i never installed any gnome stuff - is it not possible to NOT have the gtk portal installed and running? why do people then bother installing it as an extra portal, if it comes preinstalled anyway? i would have never thought i would ask such obscure questions… anyway i was going to install a third portal, xdg-desktop-portal-termfilechooser (update: i miserably failed, but will try this), and i really want to keep it minimal, because i heard that its better to have less environments and portals, generally… but im getting distracted! what do i do next? :sob:

EDIT: okay. i have read a bit about portals. the xdg-desktop-portal-gtk is a generic backend implementation FOR the xdg-desktop-portal portal which can be used as a fallback. sure, but i dont need this “fallback”, especially if its overriding my preferences! and i dont want to tinker with the xdg.portal.config preferences either! i just want to simply delete it… :sob: :sob:

assuming that xdg-desktop-portal-gtk is hardcoded into nixOS, i give up trying to remove it. let it be, i guess… still doesnt answer any of my questions though…

Search for it in nixpkgs (Code search results · GitHub, or with your editor/grep, if you have nixpkgs checked out locally) and see if you use any modules that come up in the search — as you can see a lot of desktop enviroments add this, as portals are often used to provide things like screen sharing or reading/changing system settings. Yes, it’s a bit tedious there’s no simple command to tell you which modules affected a given option, but it is what it is. Turns out nixos-option exists for just that purpose, as mentioned by waffle8946 below. TIL after years of using NixOS xD

You should be able to disable it by using lib.mkForce on xdg.portals.enable (with a false) or xdg.portal.extraPortals (with a list of portals you want instead), even if you don’t figure out where they come from — keep in mind that overrides whatever other modules might set, so you will have to ensure you specify everything you need there.

1 Like

okay, sheesh. i tried the pkgs.lib.mkForce thingie (cos without pkgs. i would have declared it in { config, pkgs, inputs, lib, ... } and it seems a little silly, isnt it, to include it just for…) for

xdg.portal.extraPortals = pkgs.lib.mkForce [
  pkgs.lxqt.xdg-desktop-portal-lxqt
  inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.xdg-desktop-portal-hyprland
  pkgs.xdg-desktop-portal-termfilechooser 
  # ...
];

and it worked! the gtk portal and everything gnome related is gone, including xdg-desktop-portal-gtk! gtk themes and file choosers/pickers work flawlessly! thanks SO much! <3

P.S. yes, my hyprland is a flake, so i had to write down its inputs. to extraPortals again, otherwise it would’ve gotten deleted. same goes for lxqt and any other environment or backend.

interestingly, but xdg.portal.lxqt.enable = pkgs.lib.mkForce true; does not seem to force installation of the pkgs.lxqt.xdg-desktop-portal-lxqt, so i had to write it down in extraPortals.

P.P.S. if you are curious, yes, every gtk application works as expected! incredibly, i knew what i was doing all along! :partying_face: :tada:

P.P.P.S. no, i still do not, in fact, know the module that pulls the xdg-desktop-portal-gtk dependancy, but it doesnt matter anyway… i also still seem to have the gnome session (GNOME/Openbox) in my desktop manager (greetd with tuigreet), but i think this is fine… until it will bother me so much i will have to make another post…

Comment out the mkForce stuff, and run nixos-option xdg.portal.extraPortals.

2 Likes

Glad that helped ;’ )

it seems a little silly, isnt it, to include it just for…) for

I suppose it would be useful to be able to tell you want to prioritize a specific part of the config a module generates, but I don’t think anything like that exist, unfortunately.

interestingly, but xdg.portal.lxqt.enable = pkgs.lib.mkForce true; does not seem to force installation of the pkgs.lxqt.xdg-desktop-portal-lxqt , so i had to write it down in extraPortals .

For example, what you’ve done here will only force that particular xdg.portal.lxqt.enable option to be always set to true — so for example if some other module tries to disable it, it won’t be able to (you’ll get an evaluation error about conflicting overriding).

But it won’t affect anything this module does (you would need something like I mentioned under the first quote), so it will still add its xdg.portal.extraPortals value without a mkForce and it will get overriden. This is why you have to mention everything in one place when using mkForce and it’s what I’ve meant in my last sentence, sorry if that wasn’t clear.

Comment out the mkForce stuff, and run nixos-option xdg.portal.extraPortals .

Years of using NixOS and I didn’t know that existed xD Thanks for that!

1 Like

oh i forgot to mention, yeah, i did try nixos-option xdg.portal.extraPortals but it gave me an error, so…

error:
       … while evaluating a branch condition
         at /nix/store/gj6hz9mj23v01yvq1nn5f655jrcky1qq-nixos-option.nix:160:1:
          159| in
          160| if !lib.hasAttrByPath path' nixos.config then
             | ^
          161|   throw "Couldn't resolve config path '${lib.showOption path'}'"

       … in the argument of the not operator
         at /nix/store/gj6hz9mj23v01yvq1nn5f655jrcky1qq-nixos-option.nix:160:5:
          159| in
          160| if !lib.hasAttrByPath path' nixos.config then
             |     ^
          161|   throw "Couldn't resolve config path '${lib.showOption path'}'"

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)

…so i went with the other solution. im going for a wild guess - its most likely hyprland flake and less likely, hopefully, me… if its the hyprland flake, how do i exclude a portal for it? and WHY does it install it? also, why do people specifically add it to extraPortals, if it comes preinstalled anyway?

i think it used to show another kind of error, but i dont understand it either way\

P.S. i did try nixos-option -I path/to/my/configuration.nix and its still the same error

Oh you’re using flakes but still on 24.11… try

nix eval .#nixosConfigurations.$(hostname).options.xdg.portal.extraPortals.definitionsWithLocations

From 25.05 onwards nixos-option will work with flakes, btw.

1 Like

okay i just tried nixos-option -F path/to/my/configuration.nix and it started doing something…

nevermind, it shows the same error :^)

yes i am… what does that mean? isnt my system.stateVersion permament? or is there a way to “update” my version?

EDIT: no, my sytem is 25.05 Warbler

tried

nix eval .#nixosConfigurations.$(hostname).options.xdg.portal.extraPortals.definitionsWithLocations

with $(hostname) changed to my hostname LOL, didnt work (idk what i was thinking), but then i tried it as is and after a hefty download it said this:

[
{ file = "/nix/store/5ds20jm3x2s4z7wn3581r6lc9ybmh45b-source/nixos/modules/programs/wayland/hyprland.nix"; value = [ «derivation /nix/store/8r94kyzcm8l5czcjvzzfrpyw1rz1as55-xdg-desktop-portal-hyprland-1.3.9+date=2025-03-14_150b0b6.drv» ]; }
{ file = "/nix/store/5ds20jm3x2s4z7wn3581r6lc9ybmh45b-source/nixos/modules/programs/wayland/hyprland.nix"; value = [ «derivation /nix/store/g6vlci17rs352spywd5wxzs50qx8bsbh-xdg-desktop-portal-gtk-1.15.3.drv» ]; }
{ file = "/nix/store/5ds20jm3x2s4z7wn3581r6lc9ybmh45b-source/nixos/modules/config/xdg/portals/lxqt.nix"; value = [ «derivation /nix/store/9d2np61bkqfd040zpv43b7yw3wp8bw11-xdg-desktop-portal-lxqt-1.1.0.drv» ]; }
]

this is WITH lib.mkForce stuff, should i try without it or… do i now know that it was actually hyprland itself this whole time? i think thats what im looking at. mind boggling…

ok, this is crazy… maybe there is a BETTER way to exclude xdg-desktop-portal-gtk for hyprland flake?

P.S. sorry for shifting the main focus of the problem multiple times…

Yes. Don’t touch it. stateVersion has absolutely nothing to do with the NixOS version. The numbers mean completely different things, even if they look the same. No, really, see here.


@waffle8946 is talking about the version of the nixpkgs repository the software running on your machine was built from. Since the latest version of nixos-option supports this, and is only available on master, this either means you’re running nixpkgs stable, or have not updated your system in a very long time.

Make sure you update with nix flake update and not nixos-rebuild --upgrade, sudo nix-channel --update or whatever.

2 Likes

Yes. IIRC hyprland depends on the gtk portal because it needs it to provide certain functionality. There was a whole complex rigamaroll of forwarding exactly the right requests to the gtk portal.

Granted, this is years ago.

It’s possible the hyprland module exposes an option to disable this feature, but lib.mkForce is fine too.

1 Like

No, there isn’t, there’s no option exposed to do so.

1 Like

oh i know. its uhm, one of the first things i learnt ^^

right now i am on 25.05 Warbler with flakes (nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";) but my stateVersion is “24.11”. i… i do update quite regularly, perhaps even too much (on an hourly basis), via nh (nix helper), so im not really sure why do you guys think i am out of date… :thinking: :upside_down_face: maybe that was just a path error…

i have a slight suspicion that hyprland doesnt need xdg-desktop-portal-gtk anymore… because it works just fine without it, no? i literally dont have it right now! XD :crazy_face: anyway, “hyprland has its own portal”, and a fully functional portal at that, is it not? and even IF - people still could just install their own preferred portals and backends and whatever if they want to anyway, so… why? i think thats inconsiderate of them :confused: you know… forcefully installing things without an option to say NO…

sadge. :sob: there should be an option to exclude ANY package, anytime, anywhere… just a suggestion…

Because your system behaves like one that’s out of date :stuck_out_tongue:

Maybe just double check that the commit for nixpkgs listed in flake.lock is indeed whatever the latest commit of nixpkgs master is. There will likely be more than one nixpkgs reference, check it’s the one not referred to by inputs with .follows.

The things that don’t work may be subtle, since not having the gtk portal will only break specific features. You likely won’t have a file picker when you use a flatpak, for example, and some applications won’t open your browser if you click a link.

These things may not matter to you, so you might never notice. I don’t know exactly what surface each portal covers though, it’s just quite clear that the module author believes it important to have both. If it seems to work for you without, well, no harm in trying.

Well, no, that’s kind of the point, it’s not fully functional.

Modules are an abstraction level at which selecting teeny details like this should not be your job. It’s like how you don’t have to select every kernel module your system uses.

It’s a bit tricky to disable those details in the end for implementation reasons, but I wouldn’t necessarily say users must have the option to break the abstraction. You can always write your own module, and NixOS is flexible enough that you can break the abstraction with a bit of effort.

Anyway, this veers into philosophy of software engineering, just wanted to clean up your final questions.

2 Likes

To be more accurate, here’s the list of portals and what they cover (though these may not 100% match up to how they’re set up in nixpkgs, these are just at most what they could support):

https://wiki.archlinux.org/title/XDG_Desktop_Portal#List_of_backends_and_interfaces

So, having lxqt and the termfilechooser portals is pointless, as they both only provide a file picker impl and nothing else. Meanwhile the gtk portal could provide a lot more functionality not covered by the other portals that you’ve chosen.

3 Likes

oh.

err… i dont suppose its desynced. i am literally downloading the freshest, newest master commit and the numbers seem to match right now. also no, i dont have any .follows inputs either… i dunno :woozy_face: MAYBE its the specialArgs = { inherit inputs; }; that i have, but i was following the hyprland wiki guide…

thats the thing - i can use xdg-open with file paths and URLs and they open alright, no problem! could be the MIME default associations that i have set…

oh… :melting_face:

mind boggling. amazes me every time. i dont know what im doing and it works!

oohhh… alright. well, thanks for helping me out and for this great explanation, i… this is my first interaction with the community and you guys seem alright! no, really, you did heaps of help. thank you very much! :exploding_head:

oh yeah. i remember getting lost on their wiki and i remember seeing that page once.

oh, damn. so, is it safe to delete the lxqt.xdg-desktop-portal-lxqt then? im going to try it in a minute, but first i have a dentist appointment…

thank you very much, mate! :smiley: