feat(system): add Flatpak support

This commit is contained in:
Andre 2024-06-16 14:53:33 -04:00
parent f534c95342
commit a36cd617f7
3 changed files with 102 additions and 0 deletions

View file

@ -57,6 +57,14 @@ in
# Change the default text editor. Options are "emacs", "nano", or "vim".
editor = "nano";
ui.flatpak = {
# Enable Flatpak support.
enable = false;
# Define Flatpak packages to install.
packages = [ ];
};
# Additional system packages to install.
packages = [ ];

View file

@ -20,6 +20,15 @@ in
config = lib.mkIf cfg.enable {
aux.system.ui.desktops.enable = true;
programs.dconf.enable = true;
# Fix blank messages in KMail. See https://nixos.wiki/wiki/KDE#KMail_Renders_Blank_Messages
environment.sessionVariables = {
NIX_PROFILES = "${pkgs.lib.concatStringsSep " " (
pkgs.lib.reverseList config.environment.profiles
)}";
};
services = {
displayManager.sddm.enable = true;
desktopManager.plasma6.enable = true;

View file

@ -0,0 +1,85 @@
# Enable support for Flatpak applications
{
nix-flatpak,
pkgs,
config,
lib,
...
}:
let
cfg = config.aux.system.ui.flatpak;
in
with lib;
{
options = {
aux.system.ui.flatpak = {
enable = mkEnableOption (mdDoc "Enables Flatpak support.");
packages = lib.mkOption {
description = "Flatpak packages to install.";
type = lib.types.listOf lib.types.str;
default = [ ];
example = lib.literalExpression "[ \"com.valvesoftware.Steam\" ]";
};
};
};
config = mkIf cfg.enable {
# Enable Flatpak
services.flatpak = {
enable = true;
# Manage all Flatpak packages and remotes
uninstallUnmanaged = true;
# Enable automatic updates alongside nixos-rebuild
update.onActivation = true;
# Add remote(s)
remotes = [
{
name = "flathub";
location = "https://dl.flathub.org/repo/flathub.flatpakrepo";
}
];
# Install base Flatpaks. For details, see https://github.com/gmodena/nix-flatpak
packages = cfg.packages;
};
# Workaround for getting Flatpak apps to use system fonts, icons, and cursors
# For details (and source), see https://github.com/NixOS/nixpkgs/issues/119433#issuecomment-1767513263
# NOTE: If fonts in Flatpaks appear incorrect (like squares), run this command to regenerate the font cache:
# flatpak list --columns=application | xargs -I %s -- flatpak run --command=fc-cache %s -f -v
system.fsPackages = [ pkgs.bindfs ];
fileSystems =
let
mkRoSymBind = path: {
device = path;
fsType = "fuse.bindfs";
options = [
"ro"
"resolve-symlinks"
"x-gvfs-hide"
];
};
aggregatedIcons = pkgs.buildEnv {
name = "system-icons";
paths = with pkgs; [
(lib.mkIf config.aux.system.ui.gnome.enable gnome.gnome-themes-extra)
(lib.mkIf config.aux.system.ui.kde.enable kdePackages.breeze-icons)
];
pathsToLink = [ "/share/icons" ];
};
aggregatedFonts = pkgs.buildEnv {
name = "system-fonts";
paths = config.fonts.packages;
pathsToLink = [ "/share/fonts" ];
};
in
{
"/usr/share/icons" = mkRoSymBind "${aggregatedIcons}/share/icons";
"/usr/local/share/fonts" = mkRoSymBind "${aggregatedFonts}/share/fonts";
};
};
}