Reshuffling stuff

This commit is contained in:
2026-03-18 18:37:07 +00:00
parent a82e8ed459
commit 17076e1b25
3 changed files with 212 additions and 168 deletions
+58 -60
View File
@@ -1,111 +1,109 @@
{
config,
pkgs,
lib,
flakeRoot,
...
}:
{ lib, config, pkgs, flakeRoot, ... }:
let
moduleName = "install-flatpaks";
flatpakConfPath = "${flakeRoot}/assets/system/apps/flatpaks.conf";
# Lees en split het bestand
raw = builtins.readFile flatpakConfPath;
# Explicit "\n" so we never accidentally split into characters
rawLines = lib.splitString "\n" raw;
# Guard: if we accidentally split into characters, rawLines length ~= stringLength raw
# Guard: check dat we niet per karakter hebben gesplit
_guard =
assert !(builtins.stringLength raw > 1 && builtins.length rawLines == builtins.stringLength raw);
true;
cleanLine =
l:
# Cleanup per regel: CR verwijderen, commentaar weghalen, trim
cleanLine = line:
let
noCR = lib.replaceStrings [ "\r" ] [ "" ] l;
noCR = lib.replaceStrings [ "\r" ] [ "" ] line;
noInlineComment = lib.head (lib.splitString "#" noCR);
in
lib.strings.trim noInlineComment;
lib.strings.trim noInlineComment;
# Filter lege regels
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
# Flatpak app IDs are reverse-DNS style like org.example.App (at least 2 dots).
# We'll validate and fail early with a clear message.
# Validatie: check reverse-DNS stijl (min 2 dots)
dotCount = s: builtins.length (lib.splitString "." s) - 1;
isValidId = s: (dotCount s) >= 2; # matches the error you're seeing: "at least 2 periods"
isValidId = s: (dotCount s) >= 2;
_validate = builtins.seq _guard (
builtins.map (
id:
if isValidId id then
true
else
throw ''
${moduleName}: invalid Flatpak ID in flatpaks.conf (needs reverse-DNS with at least 2 dots)
builtins.map (id:
if isValidId id then true
else throw ''
${moduleName}: invalid Flatpak ID in flatpaks.conf (needs reverse-DNS with at least 2 dots)
Token : ${builtins.toJSON id}
flatpaks.conf : ${toString flatpakConfPath}
Token : ${builtins.toJSON id}
flatpaks.conf : ${toString flatpakConfPath}
Fix: remove stray tokens/headers, or comment them out with '#'.
''
Fix: remove stray tokens or comment them out with '#'.
''
) entries
);
# Use validated entries
# Gebruik de gevalideerde lijst
flatpakApps = builtins.seq _validate entries;
# Maak systemd script
syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" ''
set -euo pipefail
# Use the deployed config path (matches environment.etc below)
CONF="/etc/flatpak/flatpaks.conf"
if [[ -f "$CONF" ]]; then
echo "flatpak-sync: using $CONF"
echo "flatpak-sync: using $CONF"
else
echo "flatpak-sync: WARNING: $CONF not found, using embedded list"
echo "flatpak-sync: WARNING: $CONF not found, using embedded list"
fi
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
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)}
${lib.concatStringsSep "\n" (map (a: ''"${a}"'') flatpakApps)}
)
for app in "''${desired_apps[@]}"; do
if ! flatpak info --system "$app" >/dev/null 2>&1; then
flatpak install --system -y --noninteractive flathub "$app"
fi
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
'';
in
{
services.flatpak.enable = true;
options.mySystem.system.flatpak.enable = lib.mkEnableOption "Enable automatic Flatpak installation";
xdg.portal = {
enable = true;
};
config = lib.mkIf (config.mySystem.system.flatpak.enable or false) {
# Deploy the config file for runtime visibility/debugging
environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath;
# Flatpak service zelf
services.flatpak.enable = true;
systemd.services.flatpak-sync = {
description = "Install Flatpak apps listed in flatpaks.conf";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
xdg.portal.enable = true;
serviceConfig = {
Type = "oneshot";
ExecStart = syncFlatpaks;
# Deploy config voor runtime/debug
environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath;
# systemd service
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 = syncFlatpaks;
};
restartTriggers = [ flatpakConfPath ];
path = [
pkgs.flatpak
pkgs.coreutils
pkgs.gnugrep
pkgs.gnused
];
};
restartTriggers = [ flatpakConfPath ];
path = [
pkgs.flatpak
pkgs.coreutils
pkgs.gnugrep
pkgs.gnused
];
};
}