blob: c76e176f2d28839fb83413c7d952eacb8d36ffbd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
{ pkgs, config, lib, ... }:
let
cfg = config.vuizvui.user.aszlig.services.vlock;
messageFile = pkgs.runCommandLocal "message.cat" {} ''
echo -en '\e[H\e[2J\e[?25l' > "$out"
"${pkgs.vuizvui.aszlig.aacolorize}/bin/aacolorize" \
"${./message.cat}" "${./message.colmap}" \
>> "$out"
'';
esc = "\\\\033";
unlockCSI = "${esc}[16;39H${esc}[?25h${esc}[K";
vlock = lib.overrideDerivation pkgs.vlock (o: {
postPatch = (o.postPatch or "") + ''
echo -n '"' > src/message.h
sed -e ':nl;N;$!bnl;s/[\\"]/\\&/g;s/\n/\\n/g' "${messageFile}" \
>> src/message.h
sed -i -e '$s/$/"/' src/message.h
sed -i -e 's!getenv("VLOCK_MESSAGE")!\n#include "message.h"\n!' \
src/vlock-main.c
sed -i -re 's/(fprintf[^"]*")(.*user)/\1${unlockCSI}\2/' \
src/auth-pam.c
'';
});
in {
options.vuizvui.user.aszlig.services.vlock = {
enable = lib.mkEnableOption "console lock";
user = lib.mkOption {
type = lib.types.str;
example = "horst";
internal = true;
description = ''
The user under which the locked session will run. This is a workaround
and thus this option is solely internal.
'';
};
};
config = lib.mkIf cfg.enable {
systemd.sockets.vlock = {
description = "Console Lock Socket";
wantedBy = [ "sockets.target" ];
socketConfig.ListenStream = "/run/console-lock.sock";
socketConfig.Accept = true;
};
systemd.services."vlock@" = {
description = "Lock All Consoles";
serviceConfig.Type = "oneshot";
#environment.USER = "%i"; XXX
environment.USER = cfg.user;
script = ''
retval=0
oldvt="$("${pkgs.kbd}/bin/fgconsole")"
"${vlock}/bin/vlock" -asn || retval=$?
if [ $retval -ne 0 ]; then "${pkgs.kbd}/bin/chvt" "$oldvt"; fi
exit $retval
'';
};
};
}
|