2017-09-28 14:41:35 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.rofi;
|
|
|
|
|
2021-01-23 16:30:34 +01:00
|
|
|
mkValueString = value:
|
|
|
|
if isBool value then
|
|
|
|
if value then "true" else "false"
|
|
|
|
else if isInt value then
|
|
|
|
toString value
|
2021-10-08 18:45:22 +02:00
|
|
|
else if (value._type or "") == "literal" then
|
2021-01-23 18:13:38 +01:00
|
|
|
value.value
|
|
|
|
else if isString value then
|
|
|
|
''"${value}"''
|
2021-02-04 00:48:34 +01:00
|
|
|
else if isList value then
|
|
|
|
"[ ${strings.concatStringsSep "," (map mkValueString value)} ]"
|
2021-01-23 16:30:34 +01:00
|
|
|
else
|
2021-01-23 18:13:38 +01:00
|
|
|
abort "Unhandled value type ${builtins.typeOf value}";
|
2021-01-23 16:30:34 +01:00
|
|
|
|
2021-02-09 15:59:29 +01: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
|
2021-11-28 21:07:46 +01:00
|
|
|
(mkKeyValue {
|
2021-02-09 15:59:29 +01:00
|
|
|
sep = " ";
|
|
|
|
end = "";
|
2021-11-28 21:07:46 +01:00
|
|
|
} name value) + "\n";
|
2021-02-09 15:59:29 +01:00
|
|
|
|
2022-01-09 23:15:24 +01:00
|
|
|
toRasi = attrs:
|
|
|
|
concatStringsSep "\n" (concatMap (mapAttrsToList mkRasiSection) [
|
|
|
|
(filterAttrs (n: _: n == "@theme") attrs)
|
|
|
|
(filterAttrs (n: _: n == "@import") attrs)
|
|
|
|
(removeAttrs attrs [ "@theme" "@import" ])
|
|
|
|
]);
|
2021-01-23 18:13:38 +01:00
|
|
|
|
2018-01-27 18:10:13 +01:00
|
|
|
locationsMap = {
|
2020-02-02 00:39:17 +01:00
|
|
|
center = 0;
|
|
|
|
top-left = 1;
|
|
|
|
top = 2;
|
|
|
|
top-right = 3;
|
|
|
|
right = 4;
|
2018-01-27 18:10:13 +01:00
|
|
|
bottom-right = 5;
|
2020-02-02 00:39:17 +01:00
|
|
|
bottom = 6;
|
|
|
|
bottom-left = 7;
|
|
|
|
left = 8;
|
2018-01-27 18:10:13 +01:00
|
|
|
};
|
2018-01-29 15:30:25 +01:00
|
|
|
|
2021-02-04 00:48:34 +01:00
|
|
|
primitive = with types; (oneOf [ str int bool rasiLiteral ]);
|
|
|
|
|
2021-02-09 15:59:29 +01: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 18:13:38 +01: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-02 00:39:17 +01:00
|
|
|
themeName = if (cfg.theme == null) then
|
|
|
|
null
|
2021-01-23 16:30:34 +01:00
|
|
|
else if (isString cfg.theme) then
|
2020-02-02 00:39:17 +01:00
|
|
|
cfg.theme
|
2021-01-23 18:13:38 +01:00
|
|
|
else if (isAttrs cfg.theme) then
|
|
|
|
"custom"
|
2020-02-02 00:39:17 +01:00
|
|
|
else
|
2021-01-23 16:30:34 +01:00
|
|
|
removeSuffix ".rasi" (baseNameOf cfg.theme);
|
2018-01-29 15:30:25 +01:00
|
|
|
|
2021-01-23 18:13:38 +01:00
|
|
|
themePath = if (isString cfg.theme) then
|
|
|
|
null
|
|
|
|
else if (isAttrs cfg.theme) then
|
|
|
|
"custom"
|
|
|
|
else
|
|
|
|
cfg.theme;
|
2018-01-29 15:30:25 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2017-09-28 14:41:35 +02:00
|
|
|
options.programs.rofi = {
|
2020-02-02 00:39:17 +01:00
|
|
|
enable = mkEnableOption
|
|
|
|
"Rofi: A window switcher, application launcher and dmenu replacement";
|
2017-09-28 14:41:35 +02:00
|
|
|
|
2020-05-11 17:42:59 +02:00
|
|
|
package = mkOption {
|
|
|
|
default = pkgs.rofi;
|
|
|
|
type = types.package;
|
|
|
|
description = ''
|
|
|
|
Package providing the <command>rofi</command> binary.
|
|
|
|
'';
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-05-11 17:42:59 +02:00
|
|
|
pkgs.rofi.override { plugins = [ pkgs.rofi-emoji ]; };
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-01-18 00:21:40 +01:00
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
readOnly = true;
|
|
|
|
description = ''
|
|
|
|
Resulting customized rofi package.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-06-29 19:13:01 +02:00
|
|
|
plugins = mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = types.listOf types.package;
|
|
|
|
description = ''
|
|
|
|
List of rofi plugins to be installed.
|
|
|
|
'';
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression "[ pkgs.rofi-calc ]";
|
2021-06-29 19:13:01 +02:00
|
|
|
};
|
|
|
|
|
2017-09-28 14:41:35 +02:00
|
|
|
font = mkOption {
|
|
|
|
default = null;
|
2018-12-04 23:43:12 +01:00
|
|
|
type = types.nullOr types.str;
|
2017-09-28 14:41:35 +02:00
|
|
|
example = "Droid Sans Mono 14";
|
2017-09-30 14:14:07 +02:00
|
|
|
description = "Font to use.";
|
2017-09-28 14:41:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
terminal = mkOption {
|
|
|
|
default = null;
|
2018-12-04 23:43:12 +01:00
|
|
|
type = types.nullOr types.str;
|
2017-09-28 14:41:35 +02:00
|
|
|
description = ''
|
|
|
|
Path to the terminal which will be used to run console applications
|
|
|
|
'';
|
2021-05-30 22:47:03 +02:00
|
|
|
example = "\${pkgs.gnome.gnome_terminal}/bin/gnome-terminal";
|
2017-09-28 14:41:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
cycle = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.bool;
|
2017-09-30 14:14:07 +02:00
|
|
|
description = "Whether to cycle through the results list.";
|
|
|
|
};
|
|
|
|
|
2018-01-27 18:10:13 +01:00
|
|
|
location = mkOption {
|
|
|
|
default = "center";
|
2021-01-23 16:30:34 +01:00
|
|
|
type = types.enum (attrNames locationsMap);
|
2018-01-27 18:10:13 +01: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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-29 15:30:25 +01:00
|
|
|
theme = mkOption {
|
|
|
|
default = null;
|
2021-01-23 18:13:38 +01:00
|
|
|
type = with types; nullOr (oneOf [ str path themeType ]);
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-02-04 00:48:34 +01:00
|
|
|
let
|
2021-10-08 18:45:22 +02:00
|
|
|
# Use `mkLiteral` for string-like values that should show without
|
|
|
|
# quotes, e.g.:
|
|
|
|
# {
|
|
|
|
# foo = "abc"; => foo: "abc";
|
|
|
|
# bar = mkLiteral "abc"; => bar: abc;
|
|
|
|
# };
|
2021-02-04 00:48:34 +01:00
|
|
|
inherit (config.lib.formats.rasi) mkLiteral;
|
|
|
|
in {
|
2021-01-23 18:13:38 +01:00
|
|
|
"*" = {
|
|
|
|
background-color = mkLiteral "#000000";
|
|
|
|
foreground-color = mkLiteral "rgba ( 250, 251, 252, 100 % )";
|
|
|
|
border-color = mkLiteral "#FFFFFF";
|
|
|
|
width = 512;
|
|
|
|
};
|
|
|
|
|
2021-02-04 00:48:34 +01:00
|
|
|
"#inputbar" = {
|
|
|
|
children = map mkLiteral [ "prompt" "entry" ];
|
|
|
|
};
|
|
|
|
|
2021-01-23 18:13:38 +01:00
|
|
|
"#textbox-prompt-colon" = {
|
|
|
|
expand = false;
|
|
|
|
str = ":";
|
|
|
|
margin = mkLiteral "0px 0.3em 0em 0em";
|
|
|
|
text-color = mkLiteral "@foreground-color";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2018-01-29 15:30:25 +01:00
|
|
|
description = ''
|
2021-01-23 18:13:38 +01: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 15:30:25 +01:00
|
|
|
<command>rofi-theme-selector</command> tool.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-09-28 14:41:35 +02:00
|
|
|
configPath = mkOption {
|
2021-01-23 16:30:34 +01:00
|
|
|
default = "${config.xdg.configHome}/rofi/config.rasi";
|
|
|
|
defaultText = "$XDG_CONFIG_HOME/rofi/config.rasi";
|
2018-12-04 23:43:12 +01:00
|
|
|
type = types.str;
|
2017-09-28 14:41:35 +02:00
|
|
|
description = "Path where to put generated configuration file.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2021-01-23 16:30:34 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-01-23 16:30:34 +01:00
|
|
|
{
|
|
|
|
modi = "drun,emoji,ssh";
|
|
|
|
kb-primary-paste = "Control+V,Shift+Insert";
|
|
|
|
kb-secondary-paste = "Control+v,Insert";
|
|
|
|
}
|
|
|
|
'';
|
2021-01-23 18:13:38 +01:00
|
|
|
type = configType;
|
2017-09-28 14:41:35 +02:00
|
|
|
description = "Additional configuration to add.";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-10-08 18:45:22 +02:00
|
|
|
imports = let
|
|
|
|
mkRemovedOptionRofi = option:
|
|
|
|
(mkRemovedOptionModule [ "programs" "rofi" option ]
|
|
|
|
"Please use a Rofi theme instead.");
|
|
|
|
in map mkRemovedOptionRofi [
|
|
|
|
"width"
|
|
|
|
"lines"
|
|
|
|
"borderWidth"
|
|
|
|
"rowHeight"
|
|
|
|
"padding"
|
|
|
|
"separator"
|
|
|
|
"scrollbar"
|
|
|
|
"fullscreen"
|
|
|
|
"colors"
|
|
|
|
];
|
|
|
|
|
2017-09-28 14:41:35 +02:00
|
|
|
config = mkIf cfg.enable {
|
2021-10-08 18:45:22 +02:00
|
|
|
assertions =
|
|
|
|
[ (hm.assertions.assertPlatform "programs.rofi" pkgs platforms.linux) ];
|
2018-01-29 15:30:25 +01:00
|
|
|
|
2021-01-23 18:13:38 +01:00
|
|
|
lib.formats.rasi.mkLiteral = value: {
|
|
|
|
_type = "literal";
|
|
|
|
inherit value;
|
|
|
|
};
|
|
|
|
|
2022-01-18 00:21:40 +01:00
|
|
|
programs.rofi.finalPackage = let
|
2021-06-29 19:13:01 +02:00
|
|
|
rofiWithPlugins = cfg.package.override
|
2023-04-18 12:33:44 +02:00
|
|
|
(old: { plugins = (old.plugins or [ ]) ++ cfg.plugins; });
|
|
|
|
in if builtins.hasAttr "override" cfg.package && cfg.plugins != [ ] then
|
2022-01-18 00:21:40 +01:00
|
|
|
rofiWithPlugins
|
|
|
|
else
|
|
|
|
cfg.package;
|
|
|
|
|
|
|
|
home.packages = [ cfg.finalPackage ];
|
2017-09-28 14:41:35 +02:00
|
|
|
|
2021-01-23 18:13:38 +01:00
|
|
|
home.file."${cfg.configPath}".text = toRasi {
|
|
|
|
configuration = ({
|
|
|
|
font = cfg.font;
|
|
|
|
terminal = cfg.terminal;
|
|
|
|
cycle = cfg.cycle;
|
|
|
|
location = (getAttr cfg.location locationsMap);
|
|
|
|
xoffset = cfg.xoffset;
|
|
|
|
yoffset = cfg.yoffset;
|
2021-10-08 18:45:22 +02:00
|
|
|
} // cfg.extraConfig);
|
2021-11-28 21:07:46 +01:00
|
|
|
# @theme must go after configuration but attrs are output in alphabetical order ('@' first)
|
|
|
|
} + (optionalString (themeName != null) (toRasi { "@theme" = themeName; }));
|
2021-01-23 18:13:38 +01: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 14:41:35 +02:00
|
|
|
};
|
2021-01-23 16:30:34 +01:00
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ thiagokokada ];
|
2017-09-28 14:41:35 +02:00
|
|
|
}
|