gmodena / nix-flatpak

Install flatpaks declaratively
Apache License 2.0
348 stars 11 forks source link

Add the ability to specify an overrides file directory. #82

Open Spaghetto392 opened 1 month ago

Spaghetto392 commented 1 month ago

A number of NixOS options allow a user to specify a file instead of writing one as a nix expression for configuration, e.g. services.usbguard.ruleFile, security.pki.certificateFiles, etc. This can be useful if a user, for example already has a large number of pre-written configurations for whatever program they are using.

In my case, 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.

gmodena commented 1 month ago

Hey @Spaghetto392,

Good proposal. I think this is useful and should not be hard to implement.

Currently, services.flatpak.overrides is just a Nix attrSet. I need to experiment a bit, but you should be able to split the configs across multiple files and assemble them at build time.

However, this doesn’t directly solve your problem. To load unmanaged (= not declared in nix-flatpak) overrides, you'll need to convert flatpak ini files to nix. There’s some ini-wrangling in #78 that might be useful for this feature.

Just to understand your use case better: how do you currently manage override files? Do you keep them version controlled outside of $XDG_DATA_HOME/flatpak/overrides?

Spaghetto392 commented 1 month ago

Hi @gmodena,

As it currently stands I don't really manage override files. I mostly just set them and forget them, which I know, isn't particularly great, but I haven't really had the time to setup anything more sophisticated. I've considered using something like the nextcloud sync client to add them to each of my devices, but have to consider if any of the configuration would need to be changed on a by device basis.

What I would like to do, is put my premade overrides into a directory as part of my nix repo, and have them be auto deployed system wide or perhaps per user.

gmodena commented 2 weeks ago

What I would like to do, is put my premade overrides into a directory as part of my nix repo, and have them be auto deployed system wide or perhaps per user.

The tricky part is managing attrset merges between configurations loaded from Flatpak ini files and those declared in nix. Under the hood, nix-flatpak uses jq to handle overrides state. I’m still undecided on whether to add additional logic to this process or refactor the overrides management directly within nix expressions instead of relying on jq. jq is great, but it makes things harder to test compared pure nix.

tl;dr: this issue is still in scope, but might require a bit more effort than initially estimated.