From e8d8f545cc9c6ca1f4d8763698e653f0cc816ee7 Mon Sep 17 00:00:00 2001 From: ChUrl Date: Thu, 11 Aug 2022 14:10:15 +0200 Subject: [PATCH] move overrides to flatpak/gaming modules --- home/christoph/default.nix | 10 -------- modules/flatpak.nix | 49 +++++++++++++++++++++++++++++++------- modules/gaming.nix | 9 +++++++ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/home/christoph/default.nix b/home/christoph/default.nix index a2d3943d..2e75082c 100644 --- a/home/christoph/default.nix +++ b/home/christoph/default.nix @@ -102,16 +102,6 @@ in 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: Move to gaming modules - home.file.".local/share/flatpak/overrides/com.valvesoftware.Steam".text = '' - [Context] - filesystems=${home.homeDirectory}/GameSSD;${home.homeDirectory}/GameHDD - ''; - home.file.".local/share/flatpak/overrides/com.usebottles.bottles".text = '' - [Context] - filesystems=${home.homeDirectory}/.var/app/com.valvesoftware.Steam/data/Steam;${home.homeDirectory}/Downloads;${home.homeDirectory}/GameSSD;${home.homeDirectory}/GameHDD - ''; - # Generate a list of installed user packages in ~/.local/share/current-user-packages home.file.".local/share/current-user-packages".text = let packages = builtins.map (p: "${p.name}") home.packages; diff --git a/modules/flatpak.nix b/modules/flatpak.nix index 292a5f2f..4a8b0489 100644 --- a/modules/flatpak.nix +++ b/modules/flatpak.nix @@ -12,8 +12,6 @@ with mylib.modules; let cfg = config.modules.flatpak; in { - imports = [ ]; - options.modules.flatpak = { enable = mkEnableOpt "Flatpak module"; fontFix = mkBoolOpt true "Link fonts to ~/.local/share/fonts so flatpak apps can find them"; @@ -42,6 +40,22 @@ in { default = [ ]; description = "Flatpaks that will be removed additionally (use with extraInstall)"; }; + + extraOverride = mkOption { + type = types.listOf types.attrs; + default = [ ]; + # TODO: Change the format to { "com.usebottles.bottles" = [ "~/Documents" "~/Downloads" ]; } + # TODO: This requires that the lists of the same key are being merged recursively, mkMerge would override the key + example = [ { "com.usebottles.bottles" = "\${config.home.homeDirectory}/Documents"; } ]; + description = "Additional overrides"; + }; + + extraGlobalOverride = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "\${config.home.homeDirectory}/Documents:ro" ]; + description = "Additional global overrides"; + }; }; config = mkIf cfg.enable { @@ -58,6 +72,30 @@ in { # "${home.homeDirectory}/.local/share/flatpak/exports/share" # ]; + # TODO: Currently it is not possible to define overrides for the same flatpak from different places + # TODO: Also only filesystems overrides are applied + home.file = mkMerge ([ + { + ".local/share/flatpak/overrides/global".text = let + default_overrides = [ + # These are not necessary + # Make sure flatpaks are allowed to use the icons/fonts that are symlinked by icon/font fix + # "/run/current-system/sw/share/X11/fonts:ro" + # "/run/current-system/sw/share/icons:ro" + "/nix/store:ro" + ]; + + all_overrides = builtins.concatLists [ default_overrides cfg.extraGlobalOverride ]; + + str_overrides = builtins.concatStringsSep ";" all_overrides; + in "[Context]\nfilesystems=${str_overrides}"; + } + ] ++ (map (set: let + name = attrName set; + value = attrValue set; + in (optionalAttrs (name != null) { ".local/share/flatpak/overrides/${name}".text = "[Context]\nfilesystems=${value}"; })) + cfg.extraOverride)); + home.activation = mkMerge [ # 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 @@ -136,12 +174,5 @@ in { ''; }) ]; - - # 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/modules/gaming.nix b/modules/gaming.nix index f966d5a3..9c0da101 100644 --- a/modules/gaming.nix +++ b/modules/gaming.nix @@ -62,6 +62,15 @@ in { # NOTE: Important to not disable this option if another module enables it modules.flatpak.bottles.enable = mkIf cfg.bottles.enable true; + modules.flatpak.extraOverride = [ + (optionalAttrs cfg.bottles.enable { + "com.usebottles.bottles" = "${config.home.homeDirectory}/.var/app/com.valvesoftware.Steam/data/Steam;${config.home.homeDirectory}/GameSSD;${config.home.homeDirectory}/GameHDD"; + }) + (optionalAttrs cfg.steam.enable { + "com.valvesoftware.Steam" = "${config.home.homeDirectory}/GameSSD;${config.home.homeDirectory}/GameHDD"; + }) + ]; + modules.flatpak.extraInstall = builtins.concatLists [ (optionals cfg.steam.enable [ "com.valvesoftware.Steam" ]) (optionals (cfg.steam.enable && cfg.steam.protonGE) [ "com.valvesoftware.Steam.CompatibilityTool.Proton-GE" ])