1
0
Fork 0
nix-configuration/modules/nixos/ui/flatpak/default.nix

96 lines
3 KiB
Nix
Raw Normal View History

{
pkgs,
config,
lib,
2024-12-06 16:46:10 +00:00
namespace,
...
}:
2024-02-29 14:53:34 +00:00
# Flatpak support and options
let
2024-12-06 16:46:10 +00:00
cfg = config.${namespace}.ui.flatpak;
2024-02-29 14:53:34 +00:00
in
{
options = {
2024-12-06 16:46:10 +00:00
${namespace}.ui.flatpak = {
enable = lib.mkEnableOption { description = "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\" ]";
};
2024-06-25 18:13:15 +00:00
remotes = lib.mkOption {
description = "The list of remote Flatpak repos to pull from. Includes Flathub by default.";
type = lib.types.listOf lib.types.attrs;
default = [
{
name = "flathub";
location = "https://dl.flathub.org/repo/flathub.flatpakrepo";
}
];
};
2024-09-08 15:58:56 +00:00
useBindFS = lib.mkEnableOption "Whether to use a BindFS mount to support custom themes and cursors. May cause performance issues.";
};
};
2024-02-29 14:53:34 +00:00
config = lib.mkMerge [
(lib.mkIf cfg.enable {
# Enable Flatpak
services.flatpak = {
enable = true;
2024-02-29 14:53:34 +00:00
# Manage all Flatpak packages and remotes
uninstallUnmanaged = true;
2024-02-29 20:07:39 +00:00
# Enable automatic updates alongside nixos-rebuild
update.onActivation = true;
2024-02-29 14:53:34 +00:00
# Add remote(s)
remotes = cfg.remotes;
2024-02-29 14:53:34 +00:00
# Install base Flatpaks. For details, see https://github.com/gmodena/nix-flatpak
packages = cfg.packages;
};
})
(lib.mkIf cfg.useBindFS {
# 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; [
2024-12-06 16:46:10 +00:00
(lib.mkIf config.${namespace}.ui.desktops.gnome.enable gnome-themes-extra)
(lib.mkIf config.${namespace}.ui.desktops.kde.enable kdePackages.breeze-icons)
papirus-icon-theme
qogir-icon-theme
];
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";
};
})
];
2024-02-29 14:53:34 +00:00
}