/etc/flatpak/remotes.d

I am currently trying to install flathub as a repository on NixOS from within my configuration.nix (so that I don’t have manual steps to run every install). The flatpak command reference has a comment which states that a flatpakrepo dropped into /etc/flatpak/remotes can be used to setup static system-wide repos. A nice gentlemen from the NixOS discourse helped me come up with the code for that:

  environment.etc = {
    "flatpak/remotes.d/flathub.flatpakrepo".source = pkgs.fetchurl {
      url = "https://dl.flathub.org/repo/flathub.flatpakrepo";
      # Let this run once and you will get the hash as an error.
      hash = "";
    };
  };

The file is created at /etc/flatpak/remotes.d/flathub.flatpakrepo when I switch into the new configuration, but flatpak still does not list flathub as a remote and gnome-software does not find any repositories or applications.

Does anyone here have any idea what might be going wrong?

Just to be safe: This is not a very old Flatpak version? The behaviour was changed with version 1.3.4.

The repository is only added to system-wide repositories. If you’re using --user then this won’t work.

At least for 1.15.4 I can confirm that it works:

$ cat /etc/flatpak/remotes.d/flathub.flatpakrepo 
[Flatpak Repo]
Title=Flathub
Url=https://dl.flathub.org/repo/
Homepage=https://flathub.org/
Comment=Central repository of Flatpak applications
Description=Central repository of Flatpak applications
Icon=https://dl.flathub.org/repo/logo.svg
GPGKey=…

On the next run the repository is added to the system-wide installation (remotes --system is only an example, you can directly use another command):

$ flatpak remotes --system -v
F: Calling system helper: EnsureRepo [This seems to add the repo]
F: Opening system flatpak installation at path /var/lib/flatpak
flathub	system

The repository is then imported to the installation’s ostree repo:

$ cat /var/lib/flatpak/repo/config 
[core]
…
xa.applied-remotes=flathub;

[remote "flathub"]
url=https://dl.flathub.org/repo/
xa.title=Flathub
…

I think xa.applied-remotes tells flatpak that the repository was already imported. If I just remove the remote, it’s not added again until I remove that line.

Hi cxrv! Thanks for the reply!

I don’t see anything about about “Calling system helper:”

[ladmin@nixos:/var/lib/flatpak/repo]$ flatpak --version
Flatpak 1.14.4
[ladmin@nixos:/var/lib/flatpak/repo]$ flatpak remotes --system -v
F: Opening system flatpak installation at path /var/lib/flatpak


[ladmin@nixos:/var/lib/flatpak/repo]$ ls -l /etc/flatpak/remotes.d/flathub.flatpakrepo 
lrwxrwxrwx 1 root root 49 Jul  5 22:17 /etc/flatpak/remotes.d/flathub.flatpakrepo -> /etc/static/flatpak/remotes.d/flathub.flatpakrepo
[ladmin@nixos:/var/lib/flatpak/repo]$ ls -l /etc/static/flatpak/remotes.d/flathub.flatpakrepo 
lrwxrwxrwx 1 root root 63 Dec 31  1969 /etc/static/flatpak/remotes.d/flathub.flatpakrepo -> /nix/store/y84yyx1s86haylxkdc3yvmzy0lyha6k1-flathub.flatpakrepo
ladmin@nixos:/var/lib/flatpak/repo]$ ls -l /nix/store/y84yyx1s86haylxkdc3yvmzy0lyha6k1-flathub.flatpakrepo 
-r--r--r-- 1 root root 4040 Dec 31  1969 /nix/store/y84yyx1s86haylxkdc3yvmzy0lyha6k1-flathub.flatpakrepo
[ladmin@nixos:/var/lib/flatpak/repo]$ cat config 
[core]
repo_version=1
mode=bare-user-only
min-free-space-size=500MB

All of the symbolic links are a result of the nix config system.
Do you think that could be messing it up? Does the file need to be more than read only?

It works here with a symbolic link to a read-only file, this shouldn’t be the problem. You could manually copy the file to verify this (I’m still testing on 1.15.4).

What about authorization? My local user has the necessary rights via the wheel group. The system-helper requires authorization to change system installations (CONTRIBUTING.md):

  • system-helper: The flatpak-system-helper service, which runs as root on the system bus and allows non-root users to modify system installations

Secondly, Flatpak ships with a root-privileged PolicyKit helper for system-wide installation, called flatpak-system-helper. It is D-Bus activated (on the system bus) and if you install in a non-standard location it is likely that D-Bus will not find it and PolicyKit integration will not work. However, if the system installation is synchronized, you can often use the system installed helper instead— at least if the two versions are close enough.

The strange thing is that:
flatpak --system remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
works just fine.

But without manually adding the repo, when I have /etc/remotes.d/flathub.flatpakrepo present, even sudo flatpak remotes --system doesn’t show anything.
If it was a permission problem, I would expect sudo flatpak not to suffer from it.

This option is part of the 1.14.4 documentation, but perhaps it doesn’t really work until 1.15.4?

I tried 1.14.4 on Fedora 37 & NixOS (Live system, nix-shell): It does work on Fedora but not on NixOS.

I also added an installation to /etc/flatpak/installation.d/ with the same result: It’s not found on NixOS.

Given the issue with the installation, it seems that the configuration folder is not used at all. But I’ve actually no idea how NixOS works so that’s just a guess.