From f2265b10e4eb48c66d334fa1d90bebb4affbec69 Mon Sep 17 00:00:00 2001 From: Andrew Scott <3648487+ayyjayess@users.noreply.github.com> Date: Mon, 29 Jan 2018 14:30:25 +0000 Subject: [PATCH] rofi: add theme option The preferred method of theming rofi is now to use "rasi" theme files. This commit therefore downplays the colors option and introduces the theme option. --- modules/misc/news.nix | 17 +++++++++++++++++ modules/programs/rofi.nix | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/modules/misc/news.nix b/modules/misc/news.nix index fada8e74..07b7ea30 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -560,6 +560,23 @@ in feature is slowly forthcoming. ''; } + + { + time = "2018-02-09T21:14:42+00:00"; + condition = with config.programs.rofi; enable && colors != null; + message = '' + The new and preferred way to configure the rofi theme is + using rasi themes through the 'programs.rofi.theme' option. + This option can take as value either the name of a + pre-installed theme or the path to a theme file. + + A rasi theme can be generated from an Xresources config + using 'rofi -dump-theme'. + + The option 'programs.rofi.colors' is still supported but may + become deprecated and removed in the future. + ''; + } ]; }; } diff --git a/modules/programs/rofi.nix b/modules/programs/rofi.nix index de98a466..19a18fae 100644 --- a/modules/programs/rofi.nix +++ b/modules/programs/rofi.nix @@ -124,6 +124,14 @@ let bottom-left = 7; left = 8; }; + + themeName = + if (cfg.theme == null) then null + else if (lib.isString cfg.theme) then cfg.theme + else lib.removeSuffix ".rasi" (baseNameOf cfg.theme); + + themePath = if (lib.isString cfg.theme) then null else cfg.theme; + in { @@ -232,8 +240,10 @@ in default = null; type = types.nullOr colorsSubmodule; description = '' - Color scheme settings. - Colors can be specified in CSS color formats. + Color scheme settings. Colors can be specified in CSS color + formats. This option may become deprecated in the future and + therefore the programs.rofi.theme option + should be used whenever possible. ''; example = literalExample '' colors = { @@ -258,6 +268,17 @@ in ''; }; + theme = mkOption { + default = null; + type = with types; nullOr (either string path); + example = "Arc"; + description = '' + Name of theme or path to theme file in rasi format. Available + named themes can be viewed using the + rofi-theme-selector tool. + ''; + }; + configPath = mkOption { default = ".config/rofi/config"; type = types.string; @@ -273,6 +294,15 @@ in }; config = mkIf cfg.enable { + assertions = [ + { + assertion = cfg.theme == null || cfg.colors == null; + message = '' + Cannot use the rofi options 'theme' and 'colors' simultaneously. + ''; + } + ]; + home.packages = [ pkgs.rofi ]; home.file."${cfg.configPath}".text = '' @@ -296,8 +326,13 @@ in ${setOption "yoffset" cfg.yoffset} ${setColorScheme cfg.colors} + ${setOption "theme" themeName} ${cfg.extraConfig} ''; + + xdg.dataFile = mkIf (themePath != null) { + "rofi/themes/${themeName}.rasi".source = themePath; + }; }; }