{ lib, pkgs, config, ... }: let moduleName = "flatpaks"; username = config.defaultUser or "henrov"; flatpakConfPath = ./assets/system/apps/flatpaks.conf; enableProgram = config.enableFlatpaks or false; in { # Top-level toggle for this program options.enableFlatpaks = lib.mkEnableOption "Enable automatic Flatpak installation"; # Define myApps top-level option if it doesn't exist yet options.myApps = lib.mkOption { type = lib.types.attrsOf lib.types.any; default = {}; description = "Top-level container for custom apps"; }; config = lib.mkIf enableProgram { # myApps container myApps = { flatpaks = { enable = true; user = username; assetsDir = flatpakConfPath; files = []; # we handle parsing at runtime }; }; # Deploy conf file environment.etc."flatpak/flatpaks.conf".source = flatpakConfPath; # Enable flatpak service services.flatpak.enable = true; xdg.portal.enable = true; # Systemd service for installing listed flatpaks systemd.services.flatpak-sync = { description = "Install Flatpak apps listed in flatpaks.conf"; wantedBy = [ "multi-user.target" ]; wants = [ "network-online.target" ]; after = [ "network-online.target" ]; serviceConfig = { Type = "oneshot"; ExecStart = '' set -euo pipefail CONF="${flatpakConfPath}" # Add flathub if missing if ! flatpak remotes --system --columns=name | grep -qx flathub; then flatpak remote-add --system --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo fi # Install apps listed in conf while read -r app; do app=$(echo "$app" | sed 's/#.*//;s/^[[:space:]]*//;s/[[:space:]]*$//') if [[ -n "$app" ]]; then if ! flatpak info --system "$app" >/dev/null 2>&1; then flatpak install --system -y --noninteractive flathub "$app" fi fi done < "$CONF" ''; }; restartTriggers = [ flatpakConfPath ]; path = [ pkgs.flatpak pkgs.coreutils pkgs.gnugrep pkgs.gnused ]; }; }; }