Move Flatpak management to system configuration

Flatpak management has been refactored from Home Manager and nix-flatpak to a new system/flatpak.nix module, now imported in system/common.nix. This centralizes Flatpak enablement and declarative app management at the system level, simplifying configuration and maintenance.
This commit is contained in:
2025-10-26 23:25:10 +00:00
parent a7b9f265af
commit 524663aa9b
4 changed files with 53 additions and 24 deletions

View File

@@ -10,9 +10,6 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
# Declarative Flatpak management
nix-flatpak.url = "github:gmodena/nix-flatpak";
# Optional: Hyprland (if you want a tiling Wayland compositor) # Optional: Hyprland (if you want a tiling Wayland compositor)
# hyprland.url = "github:hyprwm/Hyprland"; # hyprland.url = "github:hyprwm/Hyprland";
@@ -20,7 +17,7 @@
# nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; # nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
}; };
outputs = { self, nixpkgs, home-manager, nix-flatpak, ... }@inputs: { outputs = { self, nixpkgs, home-manager, ... }@inputs: {
# NixOS configuration for your hostname(s) # NixOS configuration for your hostname(s)
nixosConfigurations = { nixosConfigurations = {
# Desktop PC configuration # Desktop PC configuration
@@ -47,9 +44,6 @@
# User configuration # User configuration
home-manager.users.zeph = import ./home/home.nix; home-manager.users.zeph = import ./home/home.nix;
# Declarative Flatpak
home-manager.sharedModules = [ nix-flatpak.homeManagerModules.nix-flatpak ];
} }
]; ];
}; };
@@ -78,9 +72,6 @@
# User configuration # User configuration
home-manager.users.zeph = import ./home/home.nix; home-manager.users.zeph = import ./home/home.nix;
# Declarative Flatpak
home-manager.sharedModules = [ nix-flatpak.homeManagerModules.nix-flatpak ];
} }
]; ];
}; };

View File

@@ -155,17 +155,7 @@
# platformTheme.name = "gtk"; # platformTheme.name = "gtk";
# }; # };
# Declarative Flatpak packages # Flatpaks are managed in system/flatpak.nix
services.flatpak = {
packages = [
"io.github.zen_browser.zen"
# Add more Flatpak apps here
];
update.auto = {
enable = true;
onCalendar = "weekly";
};
};
# Let Home Manager manage itself # Let Home Manager manage itself
programs.home-manager.enable = true; programs.home-manager.enable = true;

View File

@@ -1,6 +1,10 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
imports = [
./flatpak.nix
];
# Common system configuration shared across all machines # Common system configuration shared across all machines
# Bootloader # Bootloader
@@ -10,9 +14,6 @@
# Networking # Networking
networking.networkmanager.enable = true; networking.networkmanager.enable = true;
# Enable Flatpak
services.flatpak.enable = true;
# Timezone and locale # Timezone and locale
time.timeZone = "Europe/London"; time.timeZone = "Europe/London";
i18n.defaultLocale = "en_US.UTF-8"; i18n.defaultLocale = "en_US.UTF-8";

47
system/flatpak.nix Normal file
View File

@@ -0,0 +1,47 @@
{ config, pkgs, ... }:
let
grep = pkgs.gnugrep;
# Declare the Flatpaks you want on your system
desiredFlatpaks = [
"io.github.zen_browser.zen"
# Add more Flatpak apps here
# "com.spotify.Client"
# "com.discordapp.Discord"
];
in {
# Enable Flatpak
services.flatpak.enable = true;
system.userActivationScripts.flatpakManagement = {
text = ''
# Ensure the Flathub repo is added
${pkgs.flatpak}/bin/flatpak remote-add --if-not-exists flathub \
https://flathub.org/repo/flathub.flatpakrepo
# Get currently installed Flatpaks
installedFlatpaks=$(${pkgs.flatpak}/bin/flatpak list --app --columns=application)
# Remove any Flatpaks that are NOT in the desired list
for installed in $installedFlatpaks; do
if ! echo ${toString desiredFlatpaks} | ${grep}/bin/grep -q $installed; then
echo "Removing $installed because it's not in the desiredFlatpaks list."
${pkgs.flatpak}/bin/flatpak uninstall -y --noninteractive $installed
fi
done
# Install or re-install the Flatpaks you DO want
for app in ${toString desiredFlatpaks}; do
echo "Ensuring $app is installed."
${pkgs.flatpak}/bin/flatpak install -y flathub $app
done
# Remove unused Flatpaks
${pkgs.flatpak}/bin/flatpak uninstall --unused -y
# Update all installed Flatpaks
${pkgs.flatpak}/bin/flatpak update -y
'';
};
}