1 { config, lib, pkgs, ... }:
6 cfg = config.services.physlock;
21 Whether to enable the {command}`physlock` screen locking mechanism.
23 Enable this and then run {command}`systemctl start physlock`
24 to securely lock the screen.
26 This will switch to a new virtual terminal, turn off console
27 switching and disable SysRq mechanism (when
28 {option}`services.physlock.disableSysRq` is set)
29 until the root or user password is given.
33 allowAnyUser = mkOption {
37 Whether to allow any user to lock the screen. This will install a
38 setuid wrapper to allow any user to start physlock as root, which
39 is a minor security risk. Call the physlock binary to use this instead
40 of using the systemd service.
44 disableSysRq = mkOption {
48 Whether to disable SysRq when locked with physlock.
52 lockMessage = mkOption {
56 Message to show on physlock login terminal.
60 muteKernelMessages = mkOption {
64 Disable kernel messages on console while physlock is running.
74 Whether to lock screen with physlock just before suspend.
78 hibernate = mkOption {
82 Whether to lock screen with physlock just before hibernate.
86 extraTargets = mkOption {
87 type = types.listOf types.str;
89 example = [ "display-manager.service" ];
91 Other targets to lock the screen just before.
93 Useful if you want to e.g. both autologin to X11 so that
94 your {file}`~/.xsession` gets executed and
95 still to have the screen locked so that the system can be
96 booted relatively unattended.
107 ###### implementation
109 config = mkIf cfg.enable (mkMerge [
112 # for physlock -l and physlock -L
113 environment.systemPackages = [ pkgs.physlock ];
115 systemd.services.physlock = {
117 description = "Physlock";
118 wantedBy = optional cfg.lockOn.suspend "suspend.target"
119 ++ optional cfg.lockOn.hibernate "hibernate.target"
120 ++ cfg.lockOn.extraTargets;
121 before = optional cfg.lockOn.suspend "systemd-suspend.service"
122 ++ optional cfg.lockOn.hibernate "systemd-hibernate.service"
123 ++ optional (cfg.lockOn.hibernate || cfg.lockOn.suspend) "systemd-suspend-then-hibernate.service"
124 ++ cfg.lockOn.extraTargets;
127 ExecStart = "${pkgs.physlock}/bin/physlock -d${optionalString cfg.muteKernelMessages "m"}${optionalString cfg.disableSysRq "s"}${optionalString (cfg.lockMessage != "") " -p \"${cfg.lockMessage}\""}";
131 security.pam.services.physlock = {};
135 (mkIf cfg.allowAnyUser {
137 security.wrappers.physlock =
141 source = "${pkgs.physlock}/bin/physlock";