1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-15 23:59:45 +01:00
home-manager/modules/services/sxhkd.nix

82 lines
2.1 KiB
Nix
Raw Normal View History

2021-07-18 23:34:50 +02:00
{ config, lib, pkgs, ... }:
2019-09-15 23:12:08 +02:00
with lib;
let
cfg = config.services.sxhkd;
2021-07-18 23:34:50 +02:00
keybindingsStr = concatStringsSep "\n" (mapAttrsToList (hotkey: command:
optionalString (command != null) ''
${hotkey}
${command}
'') cfg.keybindings);
2019-09-15 23:12:08 +02:00
2021-07-18 23:34:50 +02:00
in {
imports = [
2021-07-18 23:34:50 +02:00
(mkRemovedOptionModule [ "services" "sxhkd" "extraPath" ]
"This option is no longer needed and can be removed.")
];
2019-09-15 23:12:08 +02:00
options.services.sxhkd = {
enable = mkEnableOption "simple X hotkey daemon";
package = mkOption {
type = types.package;
default = pkgs.sxhkd;
defaultText = "pkgs.sxhkd";
2021-07-18 23:34:50 +02:00
description =
"Package containing the <command>sxhkd</command> executable.";
};
extraOptions = mkOption {
type = types.listOf types.str;
default = [ ];
2021-07-18 23:34:50 +02:00
description =
"Command line arguments to invoke <command>sxhkd</command> with.";
example = literalExpression ''[ "-m 1" ]'';
};
2019-09-15 23:12:08 +02:00
keybindings = mkOption {
type = types.attrsOf (types.nullOr types.str);
2021-07-18 23:34:50 +02:00
default = { };
2019-09-15 23:12:08 +02:00
description = "An attribute set that assigns hotkeys to commands.";
example = literalExpression ''
2019-09-15 23:12:08 +02:00
{
"super + shift + {r,c}" = "i3-msg {restart,reload}";
"super + {s,w}" = "i3-msg {stacking,tabbed}";
}
'';
};
extraConfig = mkOption {
default = "";
type = types.lines;
description = "Additional configuration to add.";
example = literalExpression ''
2019-09-15 23:12:08 +02:00
super + {_,shift +} {1-9,0}
i3-msg {workspace,move container to workspace} {1-10}
'';
};
};
config = mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.sxhkd" pkgs
lib.platforms.linux)
];
home.packages = [ cfg.package ];
2019-09-15 23:12:08 +02:00
2021-07-18 23:34:50 +02:00
xdg.configFile."sxhkd/sxhkdrc".text =
concatStringsSep "\n" [ keybindingsStr cfg.extraConfig ];
2019-09-15 23:12:08 +02:00
2021-07-18 23:34:50 +02: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 23:12:08 +02:00
};
}