Home-manager and the mimeapps.list file on Plasma/KDE desktops

Hi all,

I found that home-manager allows me to configure the mimeapps.list file declaritively:

  xdg.mimeApps.enable = true;
  xdg.mimeApps.associations.added = {                                                                                                           
    ...
  };  

However it looks like the link created by home-manager gets overwritten by my desktop environment (KDE Plasma). This results in warnings due to a file being present that cannot be overwritten. This happen on both NixOS and non-NixOS machines.

Did anyone else experience this?
Is this a problem only happening with Plasma/KDE?
Any ideas on how to solve this? Or should I just not use this feature?

Thanks in advance!
Johannes

Is your problem that the KDE apps complains when overwriting the link from home-manager or is it home-manager complaining when you ask it to replace the text file generated by KDE with a link to the nix store?

There is a NixOS option xdg.mime.defaultApplications. It writes to /etc/xdg/mimeapps.list instead of ~/.config/mimeapps.list. Maybe that can help your case as this should serve as a default if no setting is given in the user specific file but your KDE app can freely edit that text file in your home dir.

1 Like

Thanks for the reply. The problem is that home-manager complains, as $SOMEONE removes the link and replaces it with a package. I guess some KDE/Plasma internal thing is doing that.

And then the next time I run home-manager switch it complains.

The NixOS option is nice to know, but only solves this on NixOS, not on other systems.

I don’t know what service is overwriting them, but in order to find out, you might look at the date the files were created after performing various operations relating to mime apps separated by time intervals. This way, you could single out the operation that performed it and perhaps be able to disable it (or not do it, if it is a user interaction).

Alternatively, you could create a home-manager group and give permissions to modify those files only to that group, consisting of home-manager only. I’m not sure if this is possible, but it’s an idea.

I was hoping that someone already ran into that and either it is a known issue with KDE/Plasma, HomeManager, .etc. or there is a simple solution that I missed. Or an error that I made…

I wouldn’t say it is an issue with either Home Manager or KDE, just an incompatibility between them. They are both likely functioning as intended.

I experienced something similar on GNOME, and my solution is simply to not touch the setting that I know will overwrite the file. Not great, but that’s all I have at the moment. Hopefully someone else has experience with it.

Yes, I also had this difficulty with home-manager.

I have the problem after editing file associations with GNOME Nautilus. It’s not Plasma/KDE specific, because apps which follow the mime-apps-spec are recommended to modify ~/.config/mimeapps.list on behalf of users.

The way I “solved” it was by setting:

{ config, lib, ... }: {
  xdg.mimeApps.enable = lib.mkDefault true;
  xdg.configFile."mimeapps.list" = lib.mkIf config.xdg.mimeApps.enable { force = true; };
}

This will wipe out file association preferences set by KDE every time home-manager is activated.

If you use the NixOS option home-manager.backupFileExtension, it will copy any modified mimeapps.list before installing the home-manager version. There is nothing protecting the backup file when using force.


The situation is not ideal for me. I would like to have some “hybrid” declarative configuration of file associations under home-manager.

Here is an idea that I just had:

{
  xdg.mimeApps.enable = true;
  # Don't generate config at the usual place.
  # Allow desktop applications to write their file association
  # preferences to this file.
  xdg.configFile."mimeapps.list".enable = false;
  # Home-manager also writes xdg-mime-apps configuration to the
  # "deprecated" location. Desktop applications will look in this
  # list for associations, if no association was found in the
  # previous config file.
  xdg.dataFile."applications/mimeapps.list".force = true;
}