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 ];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
# Adjust this path if you place apps.nix elsewhere in the repo.
|
||||
# Best practice: keep it relative to the flake repo so flakes can read it.
|
||||
packagesConfPath = ../../../files/conf/apps/packages.conf;
|
||||
|
||||
raw = builtins.readFile packagesConfPath;
|
||||
|
||||
# Split into lines, trim whitespace, drop empty lines and comment lines.
|
||||
lines =
|
||||
let
|
||||
all = lib.splitString "\n" raw;
|
||||
trimmed = map lib.strings.trim all;
|
||||
in
|
||||
builtins.filter (l: l != "" && !(lib.hasPrefix "#" l)) trimmed;
|
||||
|
||||
# Resolve a name like:
|
||||
# "wget" -> pkgs.wget
|
||||
# "kdePackages.okular" -> pkgs.kdePackages.okular
|
||||
# "_1password-gui" -> pkgs."_1password-gui"
|
||||
resolvePkg = name:
|
||||
let
|
||||
parts = lib.splitString "." name;
|
||||
found = lib.attrByPath parts null pkgs;
|
||||
in
|
||||
if found == null then
|
||||
throw ''
|
||||
apps.nix: Package "${name}" from ${toString packagesConfPath} not found in pkgs.
|
||||
Only packages available on https://search.nixos.org/packages can be installed.
|
||||
Fix the name (or attribute path) and rebuild.
|
||||
''
|
||||
else
|
||||
found;
|
||||
|
||||
packages = map resolvePkg lines;
|
||||
|
||||
in
|
||||
{
|
||||
environment.systemPackages = packages;
|
||||
}
|
||||
Reference in New Issue
Block a user