home-manager/modules/programs/rofi.nix

339 lines
8.9 KiB
Nix
Raw Normal View History

2017-09-28 12:41:35 +00:00
{ config, lib, pkgs, ... }:
with lib;
with builtins;
let
cfg = config.programs.rofi;
2020-02-01 23:39:17 +00:00
colorOption = description:
mkOption {
type = types.str;
description = description;
};
2017-09-28 12:41:35 +00:00
rowColorSubmodule = types.submodule {
options = {
background = colorOption "Background color";
foreground = colorOption "Foreground color";
backgroundAlt = colorOption "Alternative background color";
highlight = mkOption {
type = types.submodule {
options = {
background = colorOption "Highlight background color";
foreground = colorOption "Highlight foreground color";
};
};
description = "Color settings for highlighted row.";
};
};
};
windowColorSubmodule = types.submodule {
options = {
background = colorOption "Window background color";
border = colorOption "Window border color";
separator = colorOption "Separator color";
};
};
colorsSubmodule = types.submodule {
options = {
window = mkOption {
default = null;
type = windowColorSubmodule;
description = "Window color settings.";
};
rows = mkOption {
default = null;
type = types.submodule {
options = {
normal = mkOption {
default = null;
type = types.nullOr rowColorSubmodule;
description = "Normal row color settings.";
};
active = mkOption {
default = null;
type = types.nullOr rowColorSubmodule;
description = "Active row color settings.";
};
urgent = mkOption {
default = null;
type = types.nullOr rowColorSubmodule;
description = "Urgent row color settings.";
};
};
};
description = "Rows color settings.";
};
};
};
valueToString = value:
2020-02-01 23:39:17 +00:00
if isBool value then (if value then "true" else "else") else toString value;
2017-09-28 12:41:35 +00:00
2020-02-01 23:39:17 +00:00
windowColorsToString = window:
concatStringsSep ", " (with window; [ background border separator ]);
2017-09-28 12:41:35 +00:00
rowsColorsToString = rows: ''
2020-02-01 23:39:17 +00:00
${optionalString (rows.normal != null)
(setOption "color-normal" (rowColorsToString rows.normal))}
${optionalString (rows.active != null)
(setOption "color-active" (rowColorsToString rows.active))}
${optionalString (rows.urgent != null)
(setOption "color-urgent" (rowColorsToString rows.urgent))}
2017-09-28 12:41:35 +00:00
'';
2020-02-01 23:39:17 +00:00
rowColorsToString = row:
concatStringsSep ", " (with row; [
background
foreground
backgroundAlt
highlight.background
highlight.foreground
]);
2017-09-28 12:41:35 +00:00
setOption = name: value:
optionalString (value != null) "rofi.${name}: ${valueToString value}";
2020-02-01 23:39:17 +00:00
setColorScheme = colors:
optionalString (colors != null) ''
${optionalString (colors.window != null) setOption "color-window"
(windowColorsToString colors.window)}
${optionalString (colors.rows != null) (rowsColorsToString colors.rows)}
'';
2017-09-28 12:41:35 +00:00
locationsMap = {
2020-02-01 23:39:17 +00:00
center = 0;
top-left = 1;
top = 2;
top-right = 3;
right = 4;
bottom-right = 5;
2020-02-01 23:39:17 +00:00
bottom = 6;
bottom-left = 7;
left = 8;
};
2020-02-01 23:39:17 +00:00
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;
2020-02-01 23:39:17 +00:00
in {
2017-09-28 12:41:35 +00:00
options.programs.rofi = {
2020-02-01 23:39:17 +00:00
enable = mkEnableOption
"Rofi: A window switcher, application launcher and dmenu replacement";
2017-09-28 12:41:35 +00:00
package = mkOption {
default = pkgs.rofi;
type = types.package;
description = ''
Package providing the <command>rofi</command> binary.
'';
example = literalExample ''
pkgs.rofi.override { plugins = [ pkgs.rofi-emoji ]; };
'';
};
2017-09-28 12:41:35 +00:00
width = mkOption {
default = null;
type = types.nullOr types.int;
description = "Window width";
example = 100;
};
lines = mkOption {
default = null;
type = types.nullOr types.int;
description = "Number of lines";
example = 10;
};
borderWidth = mkOption {
default = null;
type = types.nullOr types.int;
description = "Border width";
example = 1;
};
rowHeight = mkOption {
default = null;
type = types.nullOr types.int;
description = "Row height (in chars)";
example = 1;
};
padding = mkOption {
default = null;
type = types.nullOr types.int;
description = "Padding";
example = 400;
};
font = mkOption {
default = null;
type = types.nullOr types.str;
2017-09-28 12:41:35 +00:00
example = "Droid Sans Mono 14";
2017-09-30 12:14:07 +00:00
description = "Font to use.";
2017-09-28 12:41:35 +00:00
};
scrollbar = mkOption {
default = null;
type = types.nullOr types.bool;
description = "Whether to show a scrollbar.";
};
terminal = mkOption {
default = null;
type = types.nullOr types.str;
2017-09-28 12:41:35 +00:00
description = ''
Path to the terminal which will be used to run console applications
'';
example = "\${pkgs.gnome3.gnome_terminal}/bin/gnome-terminal";
};
separator = mkOption {
default = null;
type = types.nullOr (types.enum [ "none" "dash" "solid" ]);
description = "Separator style";
example = "solid";
};
cycle = mkOption {
default = null;
type = types.nullOr types.bool;
2017-09-30 12:14:07 +00:00
description = "Whether to cycle through the results list.";
};
fullscreen = mkOption {
default = null;
type = types.nullOr types.bool;
description = "Whether to run rofi fullscreen.";
2017-09-28 12:41:35 +00:00
};
location = mkOption {
default = "center";
type = types.enum (builtins.attrNames locationsMap);
description = "The location rofi appears on the screen.";
};
xoffset = mkOption {
default = 0;
type = types.int;
description = ''
Offset in the x-axis in pixels relative to the chosen location.
'';
};
yoffset = mkOption {
default = 0;
type = types.int;
description = ''
Offset in the y-axis in pixels relative to the chosen location.
'';
};
2017-09-28 12:41:35 +00:00
colors = mkOption {
default = null;
type = types.nullOr colorsSubmodule;
description = ''
Color scheme settings. Colors can be specified in CSS color
formats. This option may become deprecated in the future and
therefore the <varname>programs.rofi.theme</varname> option
should be used whenever possible.
2017-09-28 12:41:35 +00:00
'';
example = literalExample ''
colors = {
window = {
background = "argb:583a4c54";
border = "argb:582a373e";
separator = "#c3c6c8";
};
rows = {
normal = {
background = "argb:58455a64";
foreground = "#fafbfc";
backgroundAlt = "argb:58455a64";
highlight = {
background = "#00bcd4";
foreground = "#fafbfc";
};
};
};
};
'';
};
theme = mkOption {
default = null;
2019-09-03 00:25:24 +00:00
type = with types; nullOr (either str path);
example = "Arc";
description = ''
Name of theme or path to theme file in rasi format. Available
named themes can be viewed using the
<command>rofi-theme-selector</command> tool.
'';
};
2017-09-28 12:41:35 +00:00
configPath = mkOption {
2018-09-30 09:22:21 +00:00
default = "${config.xdg.configHome}/rofi/config";
defaultText = "$XDG_CONFIG_HOME/rofi/config";
type = types.str;
2017-09-28 12:41:35 +00:00
description = "Path where to put generated configuration file.";
};
extraConfig = mkOption {
default = "";
type = types.lines;
description = "Additional configuration to add.";
};
};
config = mkIf cfg.enable {
2020-02-01 23:39:17 +00:00
assertions = [{
assertion = cfg.theme == null || cfg.colors == null;
message = ''
Cannot use the rofi options 'theme' and 'colors' simultaneously.
'';
}];
home.packages = [ cfg.package ];
2017-09-28 12:41:35 +00:00
home.file."${cfg.configPath}".text = ''
${setOption "width" cfg.width}
${setOption "lines" cfg.lines}
${setOption "font" cfg.font}
${setOption "bw" cfg.borderWidth}
${setOption "eh" cfg.rowHeight}
${setOption "padding" cfg.padding}
${setOption "separator-style" cfg.separator}
2020-02-01 23:39:17 +00:00
${setOption "hide-scrollbar"
(if (cfg.scrollbar != null) then (!cfg.scrollbar) else cfg.scrollbar)}
2017-09-28 12:41:35 +00:00
${setOption "terminal" cfg.terminal}
${setOption "cycle" cfg.cycle}
2017-09-30 12:14:07 +00:00
${setOption "fullscreen" cfg.fullscreen}
${setOption "location" (builtins.getAttr cfg.location locationsMap)}
${setOption "xoffset" cfg.xoffset}
${setOption "yoffset" cfg.yoffset}
2017-09-28 12:41:35 +00:00
${setColorScheme cfg.colors}
${setOption "theme" themeName}
2017-09-28 12:41:35 +00:00
${cfg.extraConfig}
'';
xdg.dataFile = mkIf (themePath != null) {
2020-02-01 23:39:17 +00:00
"rofi/themes/${themeName}.rasi".source = themePath;
};
2017-09-28 12:41:35 +00:00
};
}