fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Naïm Faviersxhkd: set scope OOMPolicy to continue14b54157

master
2.2 KiB81 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.sxhkd;
8
9  keybindingsStr = concatStringsSep "\n" (mapAttrsToList (hotkey: command:
10    optionalString (command != null) ''
11      ${hotkey}
12        ${command}
13    '') cfg.keybindings);
14
15in {
16  imports = [
17    (mkRemovedOptionModule [ "services" "sxhkd" "extraPath" ]
18      "This option is no longer needed and can be removed.")
19  ];
20
21  options.services.sxhkd = {
22    enable = mkEnableOption "simple X hotkey daemon";
23
24    package = mkOption {
25      type = types.package;
26      default = pkgs.sxhkd;
27      defaultText = "pkgs.sxhkd";
28      description = "Package containing the {command}`sxhkd` executable.";
29    };
30
31    extraOptions = mkOption {
32      type = types.listOf types.str;
33      default = [ ];
34      description = "Command line arguments to invoke {command}`sxhkd` with.";
35      example = literalExpression ''[ "-m 1" ]'';
36    };
37
38    keybindings = mkOption {
39      type =
40        types.attrsOf (types.nullOr (types.oneOf [ types.str types.path ]));
41      default = { };
42      description = "An attribute set that assigns hotkeys to commands.";
43      example = literalExpression ''
44        {
45          "super + shift + {r,c}" = "i3-msg {restart,reload}";
46          "super + {s,w}"         = "i3-msg {stacking,tabbed}";
47          "super + F1"            = pkgs.writeShellScript "script" "echo $USER";
48        }
49      '';
50    };
51
52    extraConfig = mkOption {
53      default = "";
54      type = types.lines;
55      description = "Additional configuration to add.";
56      example = literalExpression ''
57        super + {_,shift +} {1-9,0}
58          i3-msg {workspace,move container to workspace} {1-10}
59      '';
60    };
61  };
62
63  config = mkIf cfg.enable {
64    assertions = [
65      (lib.hm.assertions.assertPlatform "services.sxhkd" pkgs
66        lib.platforms.linux)
67    ];
68
69    home.packages = [ cfg.package ];
70
71    xdg.configFile."sxhkd/sxhkdrc".text =
72      concatStringsSep "\n" [ keybindingsStr cfg.extraConfig ];
73
74    xsession.initExtra = let
75      sxhkdCommand = "${cfg.package}/bin/sxhkd ${toString cfg.extraOptions}";
76    in ''
77      systemctl --user stop sxhkd.scope 2> /dev/null || true
78      systemd-cat -t sxhkd systemd-run --user --scope --property=OOMPolicy=continue -u sxhkd ${sxhkdCommand} &
79    '';
80  };
81}