From d3961395d62978d37fbf59cd3127230e19ab1da8 Mon Sep 17 00:00:00 2001 From: ChUrl Date: Sun, 7 Aug 2022 20:27:57 +0200 Subject: [PATCH] initial flatpak module --- home/home.nix | 55 ++++++++++------------ home/modules/flatpak.nix | 98 ++++++++++++++++++++++++++++++++++++++++ nixos/configuration.nix | 3 +- 3 files changed, 122 insertions(+), 34 deletions(-) create mode 100644 home/modules/flatpak.nix diff --git a/home/home.nix b/home/home.nix index 7ef6a468..1529aec0 100644 --- a/home/home.nix +++ b/home/home.nix @@ -12,6 +12,8 @@ rec { ./modules/emacs.nix ./modules/audio.nix + ./modules/flatpak.nix + ./modules/gaming.nix # inputs.nixvim.homeManagerModules.nixvim ]; @@ -19,19 +21,36 @@ rec { # Config my modules modules.emacs = { enable = true; + useDoom = true; - autosync = true; + autoSync = true; + autoUpgrade = false; # Very volatile as the upgrade fails sometimes with bleeding edge emacs }; modules.audio = { enable = true; - carla = true; + + carla.enable = true; + bitwig.enable = false; + yabridge.enable = true; - yabridge.autosync = true; - bitwig.enable = true; + yabridge.autoSync = true; + extraPackages = with pkgs; [ audacity vcv-rack ]; }; + modules.flatpak = { + enable = true; + + fontFix = true; + iconFix = true; + + autoInstall = true; + autoUpdate = true; + + packages = [ "discord" ]; + }; + # TODO: Email # TODO: Run noisetorch as login script # TODO: Gnome terminal config @@ -54,28 +73,6 @@ rec { # NOTE: I don't think I need this anymore as all fonts are installed through the system config but let's keep this just in case fonts.fontconfig.enable = true; # Also updates the font-cache - # TODO: Add to flatpak module - # TODO: Update flatpak on rebuild? - # We link like this to be able to address the absolute location, also the fonts won't get copied to store - # NOTE: This path contains all the fonts because fonts.fontDir.enable is true - home.activation.linkFontDir = lib.hm.dag.entryAfter [ "writeBoundary" ] '' - if [ ! -L "${home.homeDirectory}/.local/share/fonts" ]; then - ln -sf /run/current-system/sw/share/X11/fonts ${home.homeDirectory}/.local/share/fonts - fi - ''; - # Also link icons - # NOTE: This path works because we have homeManager.useUserPackages = true (everything is stored in /etc/profiles/) - home.activation.linkIconDir = lib.hm.dag.entryAfter [ "writeBoundary" ] '' - if [ ! -L "${home.homeDirectory}/.local/share/icons" ]; then - ln -sf /etc/profiles/per-user/christoph/share/icons ${home.homeDirectory}/.local/share/icons - fi - ''; - # Allow access to linked fonts/icons - home.file.".local/share/flatpak/overrides/global".text = '' - [Context] - filesystems=/run/current-system/sw/share/X11/fonts:ro;/run/current-system/sw/share/icons:ro;/nix/store:ro - ''; - # TODO: Move to gaming modules home.file.".local/share/flatpak/overrides/com.valvesoftware.Steam".text = '' [Context] @@ -95,12 +92,6 @@ rec { in formatted; - # NOTE: Is set by flatpak.enable - # xdg.systemDirs.data = [ - # "/var/lib/flatpak/exports/share" - # "${home.homeDirectory}/.local/share/flatpak/exports/share" - # ]; - # TODO: Module gtk = { enable = true; diff --git a/home/modules/flatpak.nix b/home/modules/flatpak.nix new file mode 100644 index 00000000..558cbff0 --- /dev/null +++ b/home/modules/flatpak.nix @@ -0,0 +1,98 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.modules.flatpak; +in { + imports = [ ]; + + options.modules.flatpak = { + enable = mkOption { + type = types.bool; + default = false; + description = "Enable flatpak support"; + }; + + fontFix = mkOption { + type = types.bool; + default = false; + description = "Link fonts to ~/.local/share/fonts so flatpak apps can find them"; + }; + + iconFix = mkOption { + type = types.bool; + default = false; + description = "Link icons to ~/.local/share/icons so flatpak apps can find them"; + }; + + packages = mkOption { + type = types.listOf types.string; + default = [ ]; + description = "List of enabled flatpaks"; + }; + + autoInstall = mkOption { + type = types.bool; + default = false; + description = "Install enabled flatpaks on nixos-rebuild"; + }; + + autoUpdate = mkOption { + type = types.bool; + default = false; + description = "Update flatpak apps on nixos-rebuild"; + }; + }; + + config = mkIf cfg.enable { + + services.flatpak.enable = true; + + # NOTE: Is already set by flatpak.enable in configuration.nix + # xdg.systemDirs.data = [ + # "/var/lib/flatpak/exports/share" + # "${home.homeDirectory}/.local/share/flatpak/exports/share" + # ]; + + home.activation = (mkMerge [ + (mkIf cfg.fontFix { + # We link like this to be able to address the absolute location, also the fonts won't get copied to store + # NOTE: This path contains all the fonts because fonts.fontDir.enable is true + linkFontDir = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + if [ ! -L "${home.homeDirectory}/.local/share/fonts" ]; then + ln -sf /run/current-system/sw/share/X11/fonts ${home.homeDirectory}/.local/share/fonts + fi + ''; + }) + + (mkIf cfg.iconFix { + # NOTE: This path works because we have homeManager.useUserPackages = true (everything is stored in /etc/profiles/) + linkIconDir = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + if [ ! -L "${home.homeDirectory}/.local/share/icons" ]; then + ln -sf /etc/profiles/per-user/christoph/share/icons ${home.homeDirectory}/.local/share/icons + fi + ''; + }) + + (mkIf cfg.autoInstall { + installFlatpak = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + flatpak install -y ${builtins.concatStringsSep " " cfg.packages} + ''; + }) + + (mkIf cfg.autoUpdate { + updateFlatpak = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + flatpak update -y + ''; + }) + ]); + + # TODO: Add option for extra overrides and concatenate this string together + # Allow access to linked fonts/icons + home.file.".local/share/flatpak/overrides/global".text = '' + [Context] + filesystems=/run/current-system/sw/share/X11/fonts:ro;/run/current-system/sw/share/icons:ro;/nix/store:ro + ''; + }; +} diff --git a/nixos/configuration.nix b/nixos/configuration.nix index e7b14416..a466a504 100644 --- a/nixos/configuration.nix +++ b/nixos/configuration.nix @@ -276,8 +276,7 @@ acpid.enable = true; dbus.enable = true; - flatpak.enable = - true; # Not quite the nix style but useful for bottles/proprietary stuff + # flatpak.enable = true; # Not quite the nix style but useful for bottles/proprietary stuff fstrim.enable = true; fwupd.enable = true; locate.enable = true; # Periodically update index