Skip to content

Commit

Permalink
nixos/xss-lock: add module (NixOS#40619)
Browse files Browse the repository at this point in the history
`xsslock` (which was originally packaged in 6cb1d1a)
is a simple screensaver which connects a given screen locker (e.g.
`i3lock`) with `logind`. Whenever `loginctl lock-sessions` is invoked
the locker will be used to lock the screen. This works with its power
management features (e.g. `lid switch`) as well, so the PC can be locked
automatically when the lid is closed.

The module can be used like this:

```
{
  services.xserver.enable = true;

  programs.xss-lock.enable = true;
  programs.xss-lock.lockerCommand = "i3lock";
}
```
  • Loading branch information
Ma27 authored and xeji committed May 18, 2018
1 parent cfc016c commit 641a623
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
./programs/wireshark.nix
./programs/xfs_quota.nix
./programs/xonsh.nix
./programs/xss-lock.nix
./programs/yabar.nix
./programs/zsh/oh-my-zsh.nix
./programs/zsh/zsh.nix
Expand Down
26 changes: 26 additions & 0 deletions nixos/modules/programs/xss-lock.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ config, pkgs, lib, ... }:

with lib;

let
cfg = config.programs.xss-lock;
in
{
options.programs.xss-lock = {
enable = mkEnableOption "xss-lock";
lockerCommand = mkOption {
example = "xlock";
type = types.string;
description = "Locker to be used with xsslock";
};
};

config = mkIf cfg.enable {
systemd.user.services.xss-lock = {
description = "XSS Lock Daemon";
wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
serviceConfig.ExecStart = "${pkgs.xss-lock}/bin/xss-lock ${cfg.lockerCommand}";
};
};
}
1 change: 1 addition & 0 deletions nixos/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ in rec {
tests.xfce = callTest tests/xfce.nix {};
tests.xmonad = callTest tests/xmonad.nix {};
tests.xrdp = callTest tests/xrdp.nix {};
tests.xss-lock = callTest tests/xss-lock.nix {};
tests.yabar = callTest tests/yabar.nix {};
tests.zookeeper = callTest tests/zookeeper.nix {};

Expand Down
25 changes: 25 additions & 0 deletions nixos/tests/xss-lock.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import ./make-test.nix ({ pkgs, lib, ... }:

with lib;

{
name = "xss-lock";
meta.maintainers = with pkgs.stdenv.lib.maintainers; [ ma27 ];

machine = {
imports = [ ./common/x11.nix ./common/user-account.nix ];
programs.xss-lock.enable = true;
programs.xss-lock.lockerCommand = "${pkgs.xlockmore}/bin/xlock";
services.xserver.displayManager.auto.user = "alice";
};

testScript = ''
$machine->start;
$machine->waitForX;
$machine->waitForUnit("xss-lock.service", "alice");
$machine->fail("pgrep xlock");
$machine->succeed("su -l alice -c 'xset dpms force standby'");
$machine->succeed("pgrep xlock");
'';
})

0 comments on commit 641a623

Please sign in to comment.