2017-09-28 12:41:35 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
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.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
windowColorsToString = window:
|
|
|
|
concatStringsSep ", " (with window; [ background border separator ]);
|
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
|
|
|
|
2021-01-23 15:30:34 +00:00
|
|
|
mkColorScheme = colors:
|
|
|
|
if colors != null then
|
|
|
|
with colors; {
|
|
|
|
color-window =
|
|
|
|
if (window != null) then (windowColorsToString window) else null;
|
|
|
|
color-normal = if (rows != null && rows.normal != null) then
|
|
|
|
(rowColorsToString rows.normal)
|
|
|
|
else
|
|
|
|
null;
|
|
|
|
color-active = if (rows != null && rows.active != null) then
|
|
|
|
(rowColorsToString rows.active)
|
|
|
|
else
|
|
|
|
null;
|
|
|
|
color-urgent = if (rows != null && rows.active != null) then
|
|
|
|
(rowColorsToString rows.urgent)
|
|
|
|
else
|
|
|
|
null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ };
|
|
|
|
|
|
|
|
mkValueString = value:
|
|
|
|
if isBool value then
|
|
|
|
if value then "true" else "false"
|
|
|
|
else if isInt value then
|
|
|
|
toString value
|
2021-01-23 17:13:38 +00:00
|
|
|
else if value._type or "" == "literal" then
|
|
|
|
value.value
|
|
|
|
else if isString value then
|
|
|
|
''"${value}"''
|
2021-02-03 23:48:34 +00:00
|
|
|
else if isList value then
|
|
|
|
"[ ${strings.concatStringsSep "," (map mkValueString value)} ]"
|
2021-01-23 15:30:34 +00:00
|
|
|
else
|
2021-01-23 17:13:38 +00:00
|
|
|
abort "Unhandled value type ${builtins.typeOf value}";
|
2021-01-23 15:30:34 +00:00
|
|
|
|
2021-02-09 14:59:29 +00:00
|
|
|
mkKeyValue = { sep ? ": ", end ? ";" }:
|
|
|
|
name: value:
|
|
|
|
"${name}${sep}${mkValueString value}${end}";
|
|
|
|
|
|
|
|
mkRasiSection = name: value:
|
|
|
|
if isAttrs value then
|
|
|
|
let
|
|
|
|
toRasiKeyValue = generators.toKeyValue { mkKeyValue = mkKeyValue { }; };
|
|
|
|
# Remove null values so the resulting config does not have empty lines
|
|
|
|
configStr = toRasiKeyValue (filterAttrs (_: v: v != null) value);
|
|
|
|
in ''
|
|
|
|
${name} {
|
|
|
|
${configStr}}
|
|
|
|
''
|
|
|
|
else
|
|
|
|
mkKeyValue {
|
|
|
|
sep = " ";
|
|
|
|
end = "";
|
|
|
|
} name value;
|
|
|
|
|
|
|
|
toRasi = attrs: concatStringsSep "\n" (mapAttrsToList mkRasiSection attrs);
|
2021-01-23 17:13:38 +00:00
|
|
|
|
2018-01-27 17:10:13 +00:00
|
|
|
locationsMap = {
|
2020-02-01 23:39:17 +00:00
|
|
|
center = 0;
|
|
|
|
top-left = 1;
|
|
|
|
top = 2;
|
|
|
|
top-right = 3;
|
|
|
|
right = 4;
|
2018-01-27 17:10:13 +00:00
|
|
|
bottom-right = 5;
|
2020-02-01 23:39:17 +00:00
|
|
|
bottom = 6;
|
|
|
|
bottom-left = 7;
|
|
|
|
left = 8;
|
2018-01-27 17:10:13 +00:00
|
|
|
};
|
2018-01-29 14:30:25 +00:00
|
|
|
|
2021-02-03 23:48:34 +00:00
|
|
|
primitive = with types; (oneOf [ str int bool rasiLiteral ]);
|
|
|
|
|
2021-02-09 14:59:29 +00:00
|
|
|
# Either a `section { foo: "bar"; }` or a `@import/@theme "some-text"`
|
|
|
|
configType = with types;
|
|
|
|
(either (attrsOf (either primitive (listOf primitive))) str);
|
2021-01-23 17:13:38 +00:00
|
|
|
|
|
|
|
rasiLiteral = types.submodule {
|
|
|
|
options = {
|
|
|
|
_type = mkOption {
|
|
|
|
type = types.enum [ "literal" ];
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
value = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} // {
|
|
|
|
description = "Rasi literal string";
|
|
|
|
};
|
|
|
|
|
|
|
|
themeType = with types; attrsOf configType;
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
themeName = if (cfg.theme == null) then
|
|
|
|
null
|
2021-01-23 15:30:34 +00:00
|
|
|
else if (isString cfg.theme) then
|
2020-02-01 23:39:17 +00:00
|
|
|
cfg.theme
|
2021-01-23 17:13:38 +00:00
|
|
|
else if (isAttrs cfg.theme) then
|
|
|
|
"custom"
|
2020-02-01 23:39:17 +00:00
|
|
|
else
|
2021-01-23 15:30:34 +00:00
|
|
|
removeSuffix ".rasi" (baseNameOf cfg.theme);
|
2018-01-29 14:30:25 +00:00
|
|
|
|
2021-01-23 17:13:38 +00:00
|
|
|
themePath = if (isString cfg.theme) then
|
|
|
|
null
|
|
|
|
else if (isAttrs cfg.theme) then
|
|
|
|
"custom"
|
|
|
|
else
|
|
|
|
cfg.theme;
|
2018-01-29 14:30:25 +00:00
|
|
|
|
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
|
|
|
|
2020-05-11 15:42:59 +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;
|
2018-12-04 22:43:12 +00:00
|
|
|
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;
|
2018-12-04 22:43:12 +00:00
|
|
|
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
|
|
|
|
'';
|
2021-05-30 20:47:03 +00:00
|
|
|
example = "\${pkgs.gnome.gnome_terminal}/bin/gnome-terminal";
|
2017-09-28 12:41:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2018-01-27 17:10:13 +00:00
|
|
|
location = mkOption {
|
|
|
|
default = "center";
|
2021-01-23 15:30:34 +00:00
|
|
|
type = types.enum (attrNames locationsMap);
|
2018-01-27 17:10:13 +00:00
|
|
|
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 = ''
|
2018-01-29 14:30:25 +00:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-29 14:30:25 +00:00
|
|
|
theme = mkOption {
|
|
|
|
default = null;
|
2021-01-23 17:13:38 +00:00
|
|
|
type = with types; nullOr (oneOf [ str path themeType ]);
|
|
|
|
example = literalExample ''
|
2021-02-03 23:48:34 +00:00
|
|
|
let
|
|
|
|
inherit (config.lib.formats.rasi) mkLiteral;
|
|
|
|
in {
|
2021-01-23 17:13:38 +00:00
|
|
|
"*" = {
|
|
|
|
background-color = mkLiteral "#000000";
|
|
|
|
foreground-color = mkLiteral "rgba ( 250, 251, 252, 100 % )";
|
|
|
|
border-color = mkLiteral "#FFFFFF";
|
|
|
|
width = 512;
|
|
|
|
};
|
|
|
|
|
2021-02-03 23:48:34 +00:00
|
|
|
"#inputbar" = {
|
|
|
|
children = map mkLiteral [ "prompt" "entry" ];
|
|
|
|
};
|
|
|
|
|
2021-01-23 17:13:38 +00:00
|
|
|
"#textbox-prompt-colon" = {
|
|
|
|
expand = false;
|
|
|
|
str = ":";
|
|
|
|
margin = mkLiteral "0px 0.3em 0em 0em";
|
|
|
|
text-color = mkLiteral "@foreground-color";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2018-01-29 14:30:25 +00:00
|
|
|
description = ''
|
2021-01-23 17:13:38 +00:00
|
|
|
Name of theme or path to theme file in rasi format or attribute set with
|
|
|
|
theme configuration. Available named themes can be viewed using the
|
2018-01-29 14:30:25 +00:00
|
|
|
<command>rofi-theme-selector</command> tool.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-09-28 12:41:35 +00:00
|
|
|
configPath = mkOption {
|
2021-01-23 15:30:34 +00:00
|
|
|
default = "${config.xdg.configHome}/rofi/config.rasi";
|
|
|
|
defaultText = "$XDG_CONFIG_HOME/rofi/config.rasi";
|
2018-12-04 22:43:12 +00:00
|
|
|
type = types.str;
|
2017-09-28 12:41:35 +00:00
|
|
|
description = "Path where to put generated configuration file.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2021-01-23 15:30:34 +00:00
|
|
|
default = { };
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
modi = "drun,emoji,ssh";
|
|
|
|
kb-primary-paste = "Control+V,Shift+Insert";
|
|
|
|
kb-secondary-paste = "Control+v,Insert";
|
|
|
|
}
|
|
|
|
'';
|
2021-01-23 17:13:38 +00:00
|
|
|
type = configType;
|
2017-09-28 12:41:35 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
}];
|
2018-01-29 14:30:25 +00:00
|
|
|
|
2021-01-23 17:13:38 +00:00
|
|
|
lib.formats.rasi.mkLiteral = value: {
|
|
|
|
_type = "literal";
|
|
|
|
inherit value;
|
|
|
|
};
|
|
|
|
|
2020-05-11 15:42:59 +00:00
|
|
|
home.packages = [ cfg.package ];
|
2017-09-28 12:41:35 +00:00
|
|
|
|
2021-01-23 17:13:38 +00:00
|
|
|
home.file."${cfg.configPath}".text = toRasi {
|
|
|
|
configuration = ({
|
|
|
|
width = cfg.width;
|
|
|
|
lines = cfg.lines;
|
|
|
|
font = cfg.font;
|
|
|
|
bw = cfg.borderWidth;
|
|
|
|
eh = cfg.rowHeight;
|
|
|
|
padding = cfg.padding;
|
|
|
|
separator-style = cfg.separator;
|
|
|
|
hide-scrollbar =
|
|
|
|
if (cfg.scrollbar != null) then (!cfg.scrollbar) else null;
|
|
|
|
terminal = cfg.terminal;
|
|
|
|
cycle = cfg.cycle;
|
|
|
|
fullscreen = cfg.fullscreen;
|
|
|
|
location = (getAttr cfg.location locationsMap);
|
|
|
|
xoffset = cfg.xoffset;
|
|
|
|
yoffset = cfg.yoffset;
|
|
|
|
theme = themeName;
|
|
|
|
} // (mkColorScheme cfg.colors) // cfg.extraConfig);
|
2018-01-29 14:30:25 +00:00
|
|
|
};
|
2021-01-23 17:13:38 +00:00
|
|
|
|
|
|
|
xdg.dataFile = mkIf (themePath != null) (if themePath == "custom" then {
|
|
|
|
"rofi/themes/${themeName}.rasi".text = toRasi cfg.theme;
|
|
|
|
} else {
|
|
|
|
"rofi/themes/${themeName}.rasi".source = themePath;
|
|
|
|
});
|
2017-09-28 12:41:35 +00:00
|
|
|
};
|
2021-01-23 15:30:34 +00:00
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ thiagokokada ];
|
2017-09-28 12:41:35 +00:00
|
|
|
}
|