sxhkd: add service

This commit is contained in:
Nazarii Bardiuk 2019-09-15 22:12:08 +01:00 committed by Robert Helgesson
parent b0544c8cde
commit 51581b7e43
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
8 changed files with 164 additions and 0 deletions

View File

@ -1185,6 +1185,14 @@ in
Specifying them as strings is deprecated.
'';
}
{
time = "2019-09-17T19:33:49+00:00";
condition = hostPlatform.isLinux;
message = ''
A new module is available: 'services.sxhkd'.
'';
}
];
};
}

View File

@ -128,6 +128,7 @@ let
(loadModule ./services/screen-locker.nix { })
(loadModule ./services/stalonetray.nix { })
(loadModule ./services/status-notifier-watcher.nix { })
(loadModule ./services/sxhkd.nix { condition = hostPlatform.isLinux; })
(loadModule ./services/syncthing.nix { })
(loadModule ./services/taffybar.nix { })
(loadModule ./services/tahoe-lafs.nix { })

View File

@ -0,0 +1,86 @@
{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";
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 = "${pkgs.sxhkd}/bin/sxhkd";
};
Install = {
WantedBy = [ "graphical-session.target" ];
};
};
};
}

View File

@ -38,6 +38,7 @@ import nmt {
// import ./modules/misc/xsession
// import ./modules/programs/firefox
// import ./modules/programs/rofi
// import ./modules/services/sxhkd
// import ./modules/systemd
)
// import ./modules/home-environment

View File

@ -0,0 +1,31 @@
{ config, ... }:
{
config = {
services.sxhkd = {
enable = true;
keybindings = {
"super + a" = "run command a";
"super + b" = null;
"super + Shift + b" = "run command b";
};
extraConfig = ''
super + c
call command c
# comment
super + d
call command d
'';
};
nmt.script = ''
local sxhkdrc=home-files/.config/sxhkd/sxhkdrc
assertFileExists $sxhkdrc
assertFileContent $sxhkdrc ${./sxhkdrc}
'';
};
}

View File

@ -0,0 +1,4 @@
{
sxhkd-configuration = ./configuration.nix;
sxhkd-service = ./service.nix;
}

View File

@ -0,0 +1,20 @@
{ config, ... }:
{
config = {
services.sxhkd = {
enable = true;
extraPath = "/home/the-user/bin:/extra/path/bin";
};
nmt.script = ''
local serviceFile=home-files/.config/systemd/user/sxhkd.service
assertFileExists $serviceFile
assertFileRegex $serviceFile 'ExecStart=.*/bin/sxhkd'
assertFileRegex $serviceFile \
'Environment=PATH=.*\.nix-profile/bin:/home/the-user/bin:/extra/path/bin'
'';
};
}

View File

@ -0,0 +1,13 @@
super + Shift + b
run command b
super + a
run command a
super + c
call command c
# comment
super + d
call command d