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

101 lines
2.4 KiB
Nix
Raw Normal View History

2019-09-15 23:12:08 +02:00
{config, lib, pkgs, ...}:
with lib;
let
cfg = config.services.sxhkd;
keybindingsStr = concatStringsSep "\n" (
mapAttrsToList (hotkey: command:
optionalString (command != null) ''
${hotkey}
${command}
''
)
cfg.keybindings
);
in
{
options.services.sxhkd = {
enable = mkEnableOption "simple X hotkey daemon";
package = mkOption {
type = types.package;
default = pkgs.sxhkd;
defaultText = "pkgs.sxhkd";
description = "Package containing the <command>sxhkd</command> executable.";
};
extraOptions = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Command line arguments to invoke <command>sxhkd</command> with.";
example = literalExample ''[ "-m 1" ]'';
};
2019-09-15 23:12:08 +02:00
keybindings = mkOption {
type = types.attrsOf (types.nullOr types.str);
default = {};
description = "An attribute set that assigns hotkeys to commands.";
example = literalExample ''
{
"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 = literalExample ''
super + {_,shift +} {1-9,0}
i3-msg {workspace,move container to workspace} {1-10}
'';
};
extraPath = mkOption {
default = "";
type = types.envVar;
description = ''
Additional <envar>PATH</envar> entries to search for commands.
'';
example = "/home/some-user/bin:/extra/path/bin";
};
};
config = mkIf cfg.enable {
home.packages = [ pkgs.sxhkd ];
xdg.configFile."sxhkd/sxhkdrc".text = concatStringsSep "\n" [
keybindingsStr
cfg.extraConfig
];
systemd.user.services.sxhkd = {
Unit = {
Description = "simple X hotkey daemon";
After = [ "graphical-session-pre.target" ];
PartOf = [ "graphical-session.target" ];
};
Service = {
Environment =
"PATH="
+ "${config.home.profileDirectory}/bin"
+ optionalString (cfg.extraPath != "") ":"
+ cfg.extraPath;
ExecStart = "${cfg.package}/bin/sxhkd ${toString cfg.extraOptions}";
2019-09-15 23:12:08 +02:00
};
Install = {
WantedBy = [ "graphical-session.target" ];
};
};
};
}