From 187c673adf3c6a9a7afd8934ee41df7941f28cbf Mon Sep 17 00:00:00 2001 From: aszlig Date: Wed, 18 Mar 2015 03:07:20 +0100 Subject: modules: Move my modules into category dirs. Signed-off-by: aszlig --- modules/user/aszlig/services/vlock/default.nix | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 modules/user/aszlig/services/vlock/default.nix (limited to 'modules/user/aszlig/services/vlock/default.nix') diff --git a/modules/user/aszlig/services/vlock/default.nix b/modules/user/aszlig/services/vlock/default.nix new file mode 100644 index 00000000..fdf0522f --- /dev/null +++ b/modules/user/aszlig/services/vlock/default.nix @@ -0,0 +1,55 @@ +{ pkgs, config, lib, ... }: + +let + cfg = config.vuizvui.user.aszlig.services.vlock; + + messageFile = pkgs.runCommand "message.cat" {} '' + echo -en '\e[H\e[2J\e[?25l' > "$out" + "${pkgs.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"; + }; + + config.systemd.sockets.vlock = { + description = "Console Lock Socket"; + wantedBy = [ "sockets.target" ]; + socketConfig.ListenStream = "/run/console-lock.sock"; + socketConfig.Accept = true; + }; + + config.systemd.services."vlock@" = lib.mkIf cfg.enable { + description = "Lock All Consoles"; + serviceConfig.Type = "oneshot"; + + #environment.USER = "%i"; XXX + environment.USER = "aszlig"; + + 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 + ''; + }; +} -- cgit 1.4.1