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