From a0e508260c67a57adb3f7b511da4162643db22d7 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 3 Nov 2023 18:25:24 +0100 Subject: [PATCH] refactor(home-manager): ensure xdg.enable using assertion (#59) Signed-off-by: Sefa Eyeoglu --- modules/home-manager/btop.nix | 10 +++++----- modules/home-manager/fish.nix | 9 ++++----- modules/home-manager/micro.nix | 10 +++++----- modules/lib/default.nix | 5 +++++ test.nix | 2 ++ 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/modules/home-manager/btop.nix b/modules/home-manager/btop.nix index a6605f5..43aabe2 100644 --- a/modules/home-manager/btop.nix +++ b/modules/home-manager/btop.nix @@ -17,11 +17,11 @@ in config = lib.mkIf enable { - xdg = { - # xdg is required for this to work - enable = lib.mkForce true; - configFile."btop${themePath}".source = theme; - }; + assertions = [ + (lib.ctp.assertXdgEnabled "btop") + ]; + + xdg.configFile."btop${themePath}".source = theme; programs.btop.settings.color_theme = themeFile; }; diff --git a/modules/home-manager/fish.nix b/modules/home-manager/fish.nix index 95400f8..1124f0a 100644 --- a/modules/home-manager/fish.nix +++ b/modules/home-manager/fish.nix @@ -14,13 +14,12 @@ in { options.programs.fish.catppuccin = lib.ctp.mkCatppuccinOpt "fish"; - # xdg is required for this to work config = mkIf enable { - xdg = { - enable = lib.mkForce true; + assertions = [ + (lib.ctp.assertXdgEnabled "fish") + ]; - configFile."fish${themePath}".source = "${sources.fish}${themePath}"; - }; + xdg.configFile."fish${themePath}".source = "${sources.fish}${themePath}"; programs.fish.shellInit = '' fish_config theme choose "${themeName}" diff --git a/modules/home-manager/micro.nix b/modules/home-manager/micro.nix index 29085c3..90da806 100644 --- a/modules/home-manager/micro.nix +++ b/modules/home-manager/micro.nix @@ -14,12 +14,12 @@ in lib.ctp.mkCatppuccinOpt "micro"; config = lib.mkIf enable { + assertions = [ + (lib.ctp.assertXdgEnabled "micro") + ]; + programs.micro.settings.colorscheme = lib.removeSuffix ".micro" themePath; - xdg = { - # xdg is required for this to work - enable = lib.mkForce true; - configFile."micro/colorschemes/${themePath}".source = "${sources.micro}/src/${themePath}"; - }; + xdg.configFile."micro/colorschemes/${themePath}".source = "${sources.micro}/src/${themePath}"; }; } diff --git a/modules/lib/default.nix b/modules/lib/default.nix index db7d7f2..9db3688 100644 --- a/modules/lib/default.nix +++ b/modules/lib/default.nix @@ -105,4 +105,9 @@ in # the first string should be the name of the module, # followed by the local config attrset mkAccentOpt = mkBasicOpt "accent" types.accentOption; + + assertXdgEnabled = name: { + assertion = config.xdg.enable; + message = "Option xdg.enable must be enabled to apply Catppuccin theming for ${name}"; + }; } diff --git a/test.nix b/test.nix index 463601b..8c57668 100644 --- a/test.nix +++ b/test.nix @@ -42,6 +42,8 @@ in inherit (common) catppuccin; + xdg.enable = true; + home = { username = "test"; stateVersion = lib.mkDefault "23.11";