aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/services/sxhkd.nix
blob: d9f0a968515d24814b64ac3b634999823a756c9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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" ];
      };
    };
  };
}