nixpkgs/nixos/modules/services/security/physlock.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

140 lines
3.7 KiB
Nix
Raw Normal View History

2015-04-21 02:13:42 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.physlock;
in
{
###### interface
options = {
services.physlock = {
enable = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to enable the {command}`physlock` screen locking mechanism.
2015-04-21 02:13:42 +02:00
Enable this and then run {command}`systemctl start physlock`
2015-04-21 02:13:42 +02:00
to securely lock the screen.
This will switch to a new virtual terminal, turn off console
switching and disable SysRq mechanism (when
{option}`services.physlock.disableSysRq` is set)
2017-03-11 15:52:12 +01:00
until the root or user password is given.
2015-04-21 02:13:42 +02:00
'';
};
2018-02-02 14:00:01 +01:00
allowAnyUser = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
2018-02-02 14:00:01 +01:00
Whether to allow any user to lock the screen. This will install a
setuid wrapper to allow any user to start physlock as root, which
is a minor security risk. Call the physlock binary to use this instead
of using the systemd service.
'';
};
2015-04-21 02:13:42 +02:00
disableSysRq = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
2015-04-21 02:13:42 +02:00
Whether to disable SysRq when locked with physlock.
'';
};
2020-04-24 23:24:25 +02:00
lockMessage = mkOption {
type = types.str;
default = "";
description = lib.mdDoc ''
2020-04-24 23:24:25 +02:00
Message to show on physlock login terminal.
'';
};
2015-04-21 02:13:42 +02:00
lockOn = {
suspend = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
2015-04-21 02:13:42 +02:00
Whether to lock screen with physlock just before suspend.
'';
};
hibernate = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
2015-04-21 02:13:42 +02:00
Whether to lock screen with physlock just before hibernate.
'';
};
extraTargets = mkOption {
type = types.listOf types.str;
default = [];
example = [ "display-manager.service" ];
description = lib.mdDoc ''
2015-04-21 02:13:42 +02:00
Other targets to lock the screen just before.
Useful if you want to e.g. both autologin to X11 so that
your {file}`~/.xsession` gets executed and
2015-04-21 02:13:42 +02:00
still to have the screen locked so that the system can be
booted relatively unattended.
'';
};
};
};
};
###### implementation
2018-02-02 14:00:01 +01:00
config = mkIf cfg.enable (mkMerge [
{
# for physlock -l and physlock -L
environment.systemPackages = [ pkgs.physlock ];
2019-08-13 23:52:01 +02:00
systemd.services.physlock = {
2018-02-02 14:00:01 +01:00
enable = true;
description = "Physlock";
wantedBy = optional cfg.lockOn.suspend "suspend.target"
++ optional cfg.lockOn.hibernate "hibernate.target"
++ cfg.lockOn.extraTargets;
before = optional cfg.lockOn.suspend "systemd-suspend.service"
++ optional cfg.lockOn.hibernate "systemd-hibernate.service"
++ optional (cfg.lockOn.hibernate || cfg.lockOn.suspend) "systemd-suspend-then-hibernate.service"
2018-02-02 14:00:01 +01:00
++ cfg.lockOn.extraTargets;
serviceConfig = {
Type = "forking";
2020-04-24 23:24:25 +02:00
ExecStart = "${pkgs.physlock}/bin/physlock -d${optionalString cfg.disableSysRq "s"}${optionalString (cfg.lockMessage != "") " -p \"${cfg.lockMessage}\""}";
2018-02-02 14:00:01 +01:00
};
};
2015-04-21 02:13:42 +02:00
2018-02-02 14:00:01 +01:00
security.pam.services.physlock = {};
2018-02-02 14:00:01 +01:00
}
(mkIf cfg.allowAnyUser {
security.wrappers.physlock =
{ setuid = true;
owner = "root";
group = "root";
source = "${pkgs.physlock}/bin/physlock";
};
2018-02-02 14:00:01 +01:00
})
]);
2015-04-21 02:13:42 +02:00
}