fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . screen-locker ; 8 9in { 10meta . maintainers = [ hm . maintainers . jrobsonchase hm . maintainers . rszamszur ]; 11 12imports = let 13origOpt = name :[ "services" "screen-locker" name ]; 14xautolockOpt = name :[ "services" "screen-locker" "xautolock" name ]; 15xssLockOpt = name :[ "services" "screen-locker" "xss-lock" name ]; 16in [ 17( mkRenamedOptionModule ( origOpt "xssLockExtraOptions" ) 18( xssLockOpt "extraOptions" )) 19( mkRenamedOptionModule ( origOpt "xautolockExtraOptions" ) 20( xautolockOpt "extraOptions" )) 21( mkRenamedOptionModule ( origOpt "enableDetectSleep" ) 22( xautolockOpt "detectSleep" )) 23]; 24 25options . services . screen-locker = { 26enable = mkEnableOption "screen locker for X session" ; 27 28lockCmd = mkOption { 29type = types . str ; 30description = "Locker command to run." ; 31example = "\${pkgs.i3lock}/bin/i3lock -n -c 000000" ; 32}; 33 34inactiveInterval = mkOption { 35type = types . int ; 36default = 10 ; 37description = '' 38Inactive time interval in minutes after which session will be locked. 39The minimum is 1 minute, and the maximum is 1 hour. 40If {option}`xautolock.enable` is true, it will use this setting. 41See <https://linux.die.net/man/1/xautolock>. 42Otherwise, this will be used with {command}`xset` to configure 43the X server's screensaver timeout. 44'' ; 45}; 46 47xautolock = { 48enable = mkOption { 49type = types . bool ; 50default = true ; 51description = "Use xautolock for time-based locking." ; 52}; 53 54package = mkOption { 55type = types . package ; 56default = pkgs . xautolock ; 57description = '' 58Package providing the {command}`xautolock` binary. 59'' ; 60}; 61 62detectSleep = mkOption { 63type = types . bool ; 64default = true ; 65description = '' 66Whether to reset xautolock timers when awaking from sleep. 67No effect if {option}`xautolock.enable` is false. 68'' ; 69}; 70 71extraOptions = mkOption { 72type = types . listOf types . str ; 73default = [ ]; 74description = '' 75Extra command-line arguments to pass to {command}`xautolock`. 76No effect if {option}`xautolock.enable` is false. 77'' ; 78}; 79}; 80 81xss-lock = { 82package = mkOption { 83type = types . package ; 84default = pkgs . xss-lock ; 85description = '' 86Package providing the {command}`xss-lock` binary. 87'' ; 88}; 89 90extraOptions = mkOption { 91type = types . listOf types . str ; 92default = [ ]; 93description = '' 94Extra command-line arguments to pass to {command}`xss-lock`. 95'' ; 96}; 97 98screensaverCycle = mkOption { 99type = types . int ; 100default = 600 ; 101description = '' 102The X server's screensaver cycle value expressed as seconds. 103This will be used with {command}`xset` to configure 104the cycle along with timeout. 105'' ; 106}; 107}; 108}; 109 110config = mkIf cfg . enable ( mkMerge [ 111{ 112assertions = [ 113( lib . hm . assertions . assertPlatform "services.screen-locker" pkgs 114lib . platforms . linux ) 115]; 116 117systemd . user . services . xss-lock = { 118Unit = { 119Description = "xss-lock, session locker service" ; 120After = [ "graphical-session-pre.target" ]; 121PartOf = [ "graphical-session.target" ]; 122}; 123 124Install = { WantedBy = [ "graphical-session.target" ]; }; 125 126Service = { 127ExecStart = concatStringsSep " " 128([ " ${ cfg . xss-lock . package } /bin/xss-lock" "-s \${XDG_SESSION_ID}" ] 129++ cfg . xss-lock . extraOptions ++ [ "-- ${ cfg . lockCmd } " ]); 130}; 131}; 132} 133( mkIf ( ! cfg . xautolock . enable ) { 134systemd . user . services . xss-lock . Service . ExecStartPre = 135" ${ pkgs . xorg . xset } /bin/xset s ${ toString ( cfg . inactiveInterval * 60 )} ${ 136toString cfg . xss-lock . screensaverCycle 137} " ; 138}) 139( mkIf cfg . xautolock . enable { 140systemd . user . services . xautolock-session = { 141Unit = { 142Description = "xautolock, session locker service" ; 143After = [ "graphical-session-pre.target" ]; 144PartOf = [ "graphical-session.target" ]; 145}; 146 147Install = { WantedBy = [ "graphical-session.target" ]; }; 148 149Service = { 150ExecStart = concatStringsSep " " ([ 151" ${ cfg . xautolock . package } /bin/xautolock" 152"-time ${ toString cfg . inactiveInterval } " 153"-locker ' ${ pkgs . systemd } /bin/loginctl lock-session \${XDG_SESSION_ID}'" 154] ++ optional cfg . xautolock . detectSleep "-detectsleep" 155++ cfg . xautolock . extraOptions ); 156}; 157}; 158}) 159]); 160}