summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklaus Giger <niklaus.giger@member.fsf.org>2020-03-23 20:21:11 +0100
committerNiklaus Giger <niklaus.giger@member.fsf.org>2020-03-23 20:21:11 +0100
commit9238b5f06e1bdac913554b5eb4666cb11d506d82 (patch)
treefbf78fe225ef4943ab0fa6f0b812818ebc1c9cb2
parentc6722b86bfb34159c130606ff2ce46ef741c3b17 (diff)
Automatically lock the desktop when removing the librem key
-rw-r--r--purism/librem/13v3/README.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/purism/librem/13v3/README.md b/purism/librem/13v3/README.md
index 2ecb6bd..b4bae0b 100644
--- a/purism/librem/13v3/README.md
+++ b/purism/librem/13v3/README.md
@@ -50,3 +50,38 @@ Adapt linux version and the UUID to your disk!!
};
}
```
+
+## Automatically lock the desktop when removing the librem key
+
+The [instructions](https://docs.puri.sm/Librem_Key/Getting_Started/User_Manual.html#automatically-lock-the-desktop-when-removing-the-librem-key) to lock the screen after unplugging the [Librem Key](https://puri.sm/products/librem-key/#overview) don't work under NixOS.
+
+This snippet works on my Librem 15v3 laptop running KDE without wayland and is using the xlock from the package xlockmore.
+
+```nix
+{ pkgs, services , systemd, ... }:
+let
+ libremScreenSaver = pkgs.writeScriptBin "libremScreenSaver" ''
+ #!${pkgs.bash}/bin/bash
+ user=`ps aux | egrep "start_kdeinit|gdm-(wayland|x)-session"| head -n 1 | awk '{print $1}'`
+ if [ -n "$user" ]; then
+ sudo -u $user DISPLAY=:0 xlock 2>&1 | logger lockScreen for user $user
+ else
+ logger libremScreenSaver failed to find a user. Not running KDE?
+ fi
+ '';
+
+in {
+ services.udev.path = [ pkgs.procps pkgs.logger pkgs.gawk pkgs.xlockmore ];
+ services.udev.extraRules = ''
+ ACTION=="remove", ENV{PRODUCT}=="316d/4c4b/101" RUN+="${pkgs.systemd}/bin/systemctl --no-block start lockScreen@%k.service"
+ '';
+ systemd.services."lockScreen@" = {
+ bindsTo = [ "dev-%i.device"] ;
+ path = [ pkgs.procps pkgs.logger pkgs.sudo pkgs.xlockmore pkgs.gawk ] ;
+ serviceConfig = {
+ Type = "oneshot"; # was simple
+ ExecStart = "${libremScreenSaver}/bin/libremScreenSaver %I";
+ };
+ };
+}
+```