First commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
# Adjust this path if your module lives elsewhere in the repo
|
||||
flatpakConfPath = ../../../files/conf/apps/flatpak.conf;
|
||||
|
||||
# Parse flatpak.conf: ignore empty lines and comments
|
||||
flatpakApps =
|
||||
let
|
||||
lines = lib.splitString "\n" (builtins.readFile flatpakConfPath);
|
||||
cleaned = map (l: lib.strings.trim l) lines;
|
||||
in
|
||||
builtins.filter (l: l != "" && !(lib.hasPrefix "#" l)) cleaned;
|
||||
|
||||
# Shell script that:
|
||||
# - adds Flathub if missing
|
||||
# - installs missing apps
|
||||
# - (optional) removes apps not in the list
|
||||
syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" ''
|
||||
set -euo pipefail
|
||||
|
||||
# Ensure Flathub remote exists (system-wide)
|
||||
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
|
||||
|
||||
desired_apps=(
|
||||
${lib.concatStringsSep "\n" (map (a: ''"${a}"'') flatpakApps)}
|
||||
)
|
||||
|
||||
# Install desired apps if missing
|
||||
for app in "''${desired_apps[@]}"; do
|
||||
if ! flatpak info --system "$app" >/dev/null 2>&1; then
|
||||
flatpak install --system -y --noninteractive flathub "$app"
|
||||
fi
|
||||
done
|
||||
|
||||
# OPTIONAL: remove system apps not listed (uncomment to enforce strictly)
|
||||
# installed="$(flatpak list --system --app --columns=application | sed '/^$/d')"
|
||||
# for app in $installed; do
|
||||
# keep=0
|
||||
# for want in "''${desired_apps[@]}"; do
|
||||
# if [ "$app" = "$want" ]; then keep=1; break; fi
|
||||
# done
|
||||
# if [ "$keep" -eq 0 ]; then
|
||||
# flatpak uninstall --system -y --noninteractive "$app" || true
|
||||
# fi
|
||||
# done
|
||||
'';
|
||||
in
|
||||
{
|
||||
# Native NixOS Flatpak support
|
||||
services.flatpak.enable = true; # enables Flatpak on NixOS :contentReference[oaicite:1]{index=1}
|
||||
|
||||
# Strongly recommended for Flatpak desktop integration
|
||||
# (Adjust portals to your DE/WM if you want, this is a safe default.)
|
||||
xdg.portal = {
|
||||
enable = true;
|
||||
extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
|
||||
};
|
||||
|
||||
# Ensure the config file is present on the system (optional but convenient)
|
||||
environment.etc."flatpak/flatpak.conf".source = flatpakConfPath;
|
||||
|
||||
# Run sync after boot and after rebuilds, once networking is up
|
||||
systemd.services.flatpak-sync = {
|
||||
description = "Install Flatpak apps listed in flatpak.conf";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = syncFlatpaks;
|
||||
};
|
||||
|
||||
# Re-run when the config changes (best-effort)
|
||||
restartTriggers = [ flatpakConfPath ];
|
||||
path = [ pkgs.flatpak pkgs.coreutils pkgs.gnugrep pkgs.gnused ];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user