fork/home-manager
git clone https://git.julia.blue/fork/home-manager
8e5416b4
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . swayidle ; 8 9mkTimeout = t : 10[ "timeout" ( toString t . timeout ) ( escapeShellArg t . command ) ] 11++ optionals ( t . resumeCommand != null ) [ 12"resume" 13( escapeShellArg t . resumeCommand ) 14]; 15 16mkEvent = e :[ e . event ( escapeShellArg e . command ) ]; 17 18args = cfg . extraArgs ++ ( concatMap mkTimeout cfg . timeouts ) 19++ ( concatMap mkEvent cfg . events ); 20 21in { 22meta . maintainers = [ maintainers . c0deaddict ]; 23 24options . services . swayidle = let 25 26timeoutModule = { ...} :{ 27options = { 28timeout = mkOption { 29type = types . ints . positive ; 30example = 60 ; 31description = "Timeout in seconds." ; 32}; 33 34command = mkOption { 35type = types . str ; 36description = "Command to run after timeout seconds of inactivity." ; 37}; 38 39resumeCommand = mkOption { 40type = with types ; nullOr str ; 41default = null ; 42description = "Command to run when there is activity again." ; 43}; 44}; 45}; 46 47eventModule = { ...} :{ 48options = { 49event = mkOption { 50type = types . enum [ "before-sleep" "after-resume" "lock" "unlock" ]; 51description = "Event name." ; 52}; 53 54command = mkOption { 55type = types . str ; 56description = "Command to run when event occurs." ; 57}; 58}; 59}; 60 61in { 62enable = mkEnableOption "idle manager for Wayland" ; 63 64package = mkOption { 65type = types . package ; 66default = pkgs . swayidle ; 67defaultText = literalExpression "pkgs.swayidle" ; 68description = "Swayidle package to install." ; 69}; 70 71timeouts = mkOption { 72type = with types ; listOf ( submodule timeoutModule ); 73default = [ ]; 74example = literalExpression '' 75[ 76{ timeout = 60; command = " ${ pkgs . swaylock } /bin/swaylock -fF"; } 77] 78'' ; 79description = "List of commands to run after idle timeout." ; 80}; 81 82events = mkOption { 83type = with types ; listOf ( submodule eventModule ); 84default = [ ]; 85example = literalExpression '' 86[ 87{ event = "before-sleep"; command = " ${ pkgs . swaylock } /bin/swaylock"; } 88{ event = "lock"; command = "lock"; } 89] 90'' ; 91description = "Run command on occurrence of a event." ; 92}; 93 94extraArgs = mkOption { 95type = with types ; listOf str ; 96default = [ ]; 97description = "Extra arguments to pass to swayidle." ; 98}; 99 100systemdTarget = mkOption { 101type = types . str ; 102default = "graphical-session.target" ; 103example = "sway-session.target" ; 104description = '' 105Systemd target to bind to. 106'' ; 107}; 108 109}; 110 111config = mkIf cfg . enable { 112assertions = [ 113( hm . assertions . assertPlatform "services.swayidle" pkgs platforms . linux ) 114]; 115 116systemd . user . services . swayidle = { 117Unit = { 118Description = "Idle manager for Wayland" ; 119Documentation = "man:swayidle(1)" ; 120PartOf = [ "graphical-session.target" ]; 121}; 122 123Service = { 124Type = "simple" ; 125# swayidle executes commands using "sh -c", so the PATH needs to contain a shell. 126Environment = [ "PATH= ${ makeBinPath [ pkgs . bash ]} " ]; 127ExecStart = 128" ${ cfg . package } /bin/swayidle -w ${ concatStringsSep " " args } " ; 129}; 130 131Install = { WantedBy = [ cfg . systemdTarget ]; }; 132}; 133}; 134}