mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-24 16:03:23 +00:00
2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
140 lines
3.7 KiB
Nix
140 lines
3.7 KiB
Nix
{ 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.
|
|
|
|
Enable this and then run {command}`systemctl start physlock`
|
|
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)
|
|
until the root or user password is given.
|
|
'';
|
|
};
|
|
|
|
allowAnyUser = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc ''
|
|
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.
|
|
'';
|
|
};
|
|
|
|
disableSysRq = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = lib.mdDoc ''
|
|
Whether to disable SysRq when locked with physlock.
|
|
'';
|
|
};
|
|
|
|
lockMessage = mkOption {
|
|
type = types.str;
|
|
default = "";
|
|
description = lib.mdDoc ''
|
|
Message to show on physlock login terminal.
|
|
'';
|
|
};
|
|
|
|
lockOn = {
|
|
|
|
suspend = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = lib.mdDoc ''
|
|
Whether to lock screen with physlock just before suspend.
|
|
'';
|
|
};
|
|
|
|
hibernate = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = lib.mdDoc ''
|
|
Whether to lock screen with physlock just before hibernate.
|
|
'';
|
|
};
|
|
|
|
extraTargets = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [];
|
|
example = [ "display-manager.service" ];
|
|
description = lib.mdDoc ''
|
|
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
|
|
still to have the screen locked so that the system can be
|
|
booted relatively unattended.
|
|
'';
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
{
|
|
|
|
# for physlock -l and physlock -L
|
|
environment.systemPackages = [ pkgs.physlock ];
|
|
|
|
systemd.services.physlock = {
|
|
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"
|
|
++ cfg.lockOn.extraTargets;
|
|
serviceConfig = {
|
|
Type = "forking";
|
|
ExecStart = "${pkgs.physlock}/bin/physlock -d${optionalString cfg.disableSysRq "s"}${optionalString (cfg.lockMessage != "") " -p \"${cfg.lockMessage}\""}";
|
|
};
|
|
};
|
|
|
|
security.pam.services.physlock = {};
|
|
|
|
}
|
|
|
|
(mkIf cfg.allowAnyUser {
|
|
|
|
security.wrappers.physlock =
|
|
{ setuid = true;
|
|
owner = "root";
|
|
group = "root";
|
|
source = "${pkgs.physlock}/bin/physlock";
|
|
};
|
|
|
|
})
|
|
]);
|
|
|
|
}
|