feat(gaming): register Flathub remote via one-shot systemd unit

services.flatpak.enable = true (set inside core/system/gaming.nix's
mkIf cfg.enable block) ships flatpak but doesn't add any remotes, so
`flatpak install` and the Discover GUI returned empty results until
the user ran the manual `flatpak remote-add` one-liner. nixpkgs has
no declarative remote-add API yet.

Added systemd.services.nomarchy-flathub-init: a Type=oneshot,
RemainAfterExit=true unit that runs
`flatpak remote-add --if-not-exists flathub
  https://dl.flathub.org/repo/flathub.flatpakrepo`
after network-online.target. The --if-not-exists flag keeps it
idempotent across reboots and re-runs.

Lives under the gaming preset (where flatpak is wired today); lift
to a dedicated module when another preset needs flatpak.

Closes the "Gaming — declarative flathub remote" Next-column item.
`nix flake check --no-build` clean.
This commit is contained in:
Bernardo Magri
2026-05-22 18:33:51 +01:00
parent 90f9a29cb6
commit 2948dc4dbf

View File

@@ -1,4 +1,4 @@
{ config, lib, ... }:
{ config, lib, pkgs, ... }:
let
cfg = config.nomarchy.system.gaming;
@@ -16,5 +16,29 @@ in
programs.gamemode.enable = true;
services.flatpak.enable = true;
# `services.flatpak.enable = true` ships flatpak but does NOT add any
# remotes — without a remote, `flatpak install` and the Discover GUI
# can't find anything. nixpkgs has no declarative remote-add API yet,
# so we run a one-shot system unit after flatpak.service is ready that
# adds the flathub remote idempotently (`--if-not-exists`). Lives under
# the gaming preset because Pillar 5 ships flatpak as part of the
# gaming wiring; if another preset later needs flatpak, lift this to a
# dedicated module.
systemd.services.nomarchy-flathub-init = {
description = "Register the Flathub remote on first start";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
path = [ pkgs.flatpak ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
flatpak remote-add --if-not-exists flathub \
https://dl.flathub.org/repo/flathub.flatpakrepo
'';
};
};
}