nix-flatpak icon indicating copy to clipboard operation
nix-flatpak copied to clipboard

overrides: read base config from files.

Open gmodena opened this issue 6 months ago • 0 comments

WARNING: this PR contains experimental code. It overwrites system/user flatpak override files and could cause data loss.

Addresses #82 , #128.

What

This PR introduces the capability to read overrides from user provided config files, and perform a three way merge with config.flatpak.overrides and the active state config.

Why

From #82:

[...] I have a number of Flatpak override config files already present on my device. It would be very useful if I could simply drop them in a folder as part of my OS config. This would also allow users to use tools they are already familiar with, when configuring Flatpak overrides, e.g. flatseal, and the built in configuration tool present on KDE. [...]

How

The overrides config has been refactored with two new options:

  • settings: an attribute set of override settings
  • files: a list of paths to ini Flatpak overrides files. The files will be merged with the settings attribute set.

At activation nix-flatpak will merge override configurations from multiple sources:

  • base: base configuration from override files (config.flatpak.overrides.files).
  • active: currently active overrides (existing state. e.g. $HOME/.local/share/flatpak/overrides).
  • old_state: previous declarative state (e.g. $HOME/.local/state/home-manager/gcroots/flatpak-state.json).
  • new_state: new declarative state (e.g. config.flatpak.overrides.settings).

For each entry, the merge formula is:

base + (active - old) + new

Example

  services.flatpak.overrides.settings =  {
   global = {
     # Force Wayland by default
     Context.sockets = ["wayland" "!x11" "!fallback-x11"];

     Environment = {
       # Fix un-themed cursor in some Wayland apps
       XCURSOR_PATH = "/run/host/user-share/icons:/run/host/share/icons";

       # Force correct theme for some GTK apps
       GTK_THEME = "Adwaita:dark";
     };
   };

   "com.visualstudio.code".Context = {
     filesystems = [
       "xdg-config/git:ro" # Expose user Git config
       "/run/current-system/sw/bin:ro" # Expose NixOS managed software
     ];
     sockets = [
       "gpg-agent" # Expose GPG agent
       "pcsc" # Expose smart cards (i.e. YubiKey)
     ];
   };
 };

 services.flatpak.overrides.files = [
   "/home/gmodena/config/overrides/org.onlyoffice.desktopeditors"
   "/home/gmodena/config/overrides/org.gnome.gedit"
   "/home/gmodena/config/overrides/global"
 ];

Known issues

  • [] overrides ini files generate by nix-flatpak contains an extra newline
  • [] ...

gmodena avatar Jun 29 '25 13:06 gmodena