2021-07-18 21:34:50 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2019-09-15 21:12:08 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.sxhkd;
|
|
|
|
|
2021-07-18 21:34:50 +00:00
|
|
|
keybindingsStr = concatStringsSep "\n" (mapAttrsToList (hotkey: command:
|
|
|
|
optionalString (command != null) ''
|
|
|
|
${hotkey}
|
|
|
|
${command}
|
|
|
|
'') cfg.keybindings);
|
2019-09-15 21:12:08 +00:00
|
|
|
|
2021-07-18 21:34:50 +00:00
|
|
|
in {
|
2021-05-07 19:28:52 +00:00
|
|
|
imports = [
|
2021-07-18 21:34:50 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "sxhkd" "extraPath" ]
|
|
|
|
"This option is no longer needed and can be removed.")
|
2021-05-07 19:28:52 +00:00
|
|
|
];
|
|
|
|
|
2019-09-15 21:12:08 +00:00
|
|
|
options.services.sxhkd = {
|
2023-06-30 23:30:13 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "simple X hotkey daemon");
|
2019-09-15 21:12:08 +00:00
|
|
|
|
2021-01-14 00:56:32 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.sxhkd;
|
|
|
|
defaultText = "pkgs.sxhkd";
|
2021-07-18 21:34:50 +00:00
|
|
|
description =
|
2023-06-30 23:30:13 +00:00
|
|
|
lib.mdDoc "Package containing the {command}`sxhkd` executable.";
|
2021-01-14 00:56:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2021-07-18 21:34:50 +00:00
|
|
|
description =
|
2023-06-30 23:30:13 +00:00
|
|
|
lib.mdDoc "Command line arguments to invoke {command}`sxhkd` with.";
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''[ "-m 1" ]'';
|
2021-01-14 00:56:32 +00:00
|
|
|
};
|
|
|
|
|
2019-09-15 21:12:08 +00:00
|
|
|
keybindings = mkOption {
|
2023-06-30 23:49:05 +00:00
|
|
|
type =
|
|
|
|
types.attrsOf (types.nullOr (types.oneOf [ types.str types.path ]));
|
2021-07-18 21:34:50 +00:00
|
|
|
default = { };
|
2023-06-30 23:30:13 +00:00
|
|
|
description =
|
|
|
|
lib.mdDoc "An attribute set that assigns hotkeys to commands.";
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2019-09-15 21:12:08 +00:00
|
|
|
{
|
|
|
|
"super + shift + {r,c}" = "i3-msg {restart,reload}";
|
|
|
|
"super + {s,w}" = "i3-msg {stacking,tabbed}";
|
2023-06-30 23:49:05 +00:00
|
|
|
"super + F1" = pkgs.writeShellScript "script" "echo $USER";
|
2019-09-15 21:12:08 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc "Additional configuration to add.";
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2019-09-15 21:12:08 +00:00
|
|
|
super + {_,shift +} {1-9,0}
|
|
|
|
i3-msg {workspace,move container to workspace} {1-10}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 21:24:27 +00:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.sxhkd" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
2021-05-07 19:28:52 +00:00
|
|
|
home.packages = [ cfg.package ];
|
2019-09-15 21:12:08 +00:00
|
|
|
|
2021-07-18 21:34:50 +00:00
|
|
|
xdg.configFile."sxhkd/sxhkdrc".text =
|
|
|
|
concatStringsSep "\n" [ keybindingsStr cfg.extraConfig ];
|
2019-09-15 21:12:08 +00:00
|
|
|
|
2021-07-18 21:34:50 +00:00
|
|
|
xsession.initExtra = let
|
|
|
|
sxhkdCommand = "${cfg.package}/bin/sxhkd ${toString cfg.extraOptions}";
|
|
|
|
in ''
|
|
|
|
systemctl --user stop sxhkd.scope 2> /dev/null || true
|
|
|
|
systemd-cat -t sxhkd systemd-run --user --scope -u sxhkd ${sxhkdCommand} &
|
|
|
|
'';
|
2019-09-15 21:12:08 +00:00
|
|
|
};
|
|
|
|
}
|