diff --git a/modules/default.nix b/modules/default.nix index 115a144cf..cb3b9f14f 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -44,6 +44,7 @@ let ./services/owncloud-client.nix ./services/random-background.nix ./services/redshift.nix + ./services/screen-locker.nix ./services/syncthing.nix ./services/taffybar.nix ./services/tahoe-lafs.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 791dc0610..17747fb79 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -185,6 +185,13 @@ in A new service is available: 'services.compton'. ''; } + + { + time = "2017-09-20T14:47:14+00:00"; + message = '' + A new service is available: 'services.screen-locker'. + ''; + } ]; }; } diff --git a/modules/services/screen-locker.nix b/modules/services/screen-locker.nix new file mode 100644 index 000000000..291416564 --- /dev/null +++ b/modules/services/screen-locker.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.screen-locker; + +in { + + options.services.screen-locker = { + enable = mkEnableOption "screen locker for X session"; + + lockCmd = mkOption { + type = types.str; + description = "Locker command to run."; + example = "\${pkgs.i3lock}/bin/i3lock -n -c 000000"; + }; + + inactiveInterval = mkOption { + type = types.int; + default = 10; + description = '' + Inactive time interval in minutes after which session will be locked. + The minimum is 1 minute, and the maximum is 1 hour. + See . + ''; + }; + }; + + config = mkIf cfg.enable { + systemd.user.services.xautolock-session = { + Unit = { + Description = "xautolock, session locker service"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + + Service = { + ExecStart = '' + ${pkgs.xautolock}/bin/xautolock \ + -detectsleep \ + -time ${toString cfg.inactiveInterval} \ + -locker '${pkgs.systemd}/bin/loginctl lock-session $XDG_SESSION_ID' + ''; + }; + }; + + # xss-lock will run specified screen locker when the session is locked via loginctl + # can't be started as a systemd service, + # see https://bitbucket.org/raymonad/xss-lock/issues/13/allow-operation-as-systemd-user-unit + xsession.initExtra = "${pkgs.xss-lock}/bin/xss-lock -- ${cfg.lockCmd} &"; + }; + +} diff --git a/modules/xsession.nix b/modules/xsession.nix index 0ec95ffe6..89979796c 100644 --- a/modules/xsession.nix +++ b/modules/xsession.nix @@ -87,6 +87,7 @@ in systemctl --user import-environment XAUTHORITY systemctl --user import-environment XDG_DATA_DIRS systemctl --user import-environment XDG_RUNTIME_DIR + systemctl --user import-environment XDG_SESSION_ID systemctl --user start hm-graphical-session.target