tv slock service: support multiple displays

This commit is contained in:
tv 2019-01-07 11:23:25 +01:00
parent 6e5a61b676
commit 7c84b32f2d

View File

@ -5,10 +5,12 @@ in {
options.tv.slock = { options.tv.slock = {
enable = mkEnableOption "tv.slock"; enable = mkEnableOption "tv.slock";
package = mkOption { package = mkOption {
default = pkgs.execBin "slock" rec { default = pkgs.writeDashBin "slock" ''
filename = "${pkgs.systemd}/bin/systemctl"; set -efu
argv = [ filename "start" "slock-${cfg.user.name}.service" ]; display=''${DISPLAY#:}
}; service=slock-$LOGNAME@$display.service
exec ${pkgs.systemd}/bin/systemctl start "$service"
'';
type = types.package; type = types.package;
}; };
user = mkOption { user = mkOption {
@ -18,16 +20,16 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
security.polkit.extraConfig = /* js */ '' security.polkit.extraConfig = /* js */ ''
polkit.addRule(function(action, subject) { polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.systemd1.manage-units" && if (action.id === "org.freedesktop.systemd1.manage-units" &&
action.lookup("unit") == "slock-${cfg.user.name}.service" && subject.user === ${toJSON cfg.user.name} &&
subject.user == ${toJSON cfg.user.name}) { /^slock-${cfg.user.name}@[0-9]+\.service$/.test(action.lookup("unit")) ) {
return polkit.Result.YES; return polkit.Result.YES;
} }
}); });
''; '';
systemd.services."slock-${cfg.user.name}" = { systemd.services."slock-${cfg.user.name}@" = {
environment = { environment = {
DISPLAY = ":${toString config.services.xserver.display}"; DISPLAY = ":%I";
LD_PRELOAD = pkgs.runCommandCC "slock-${cfg.user.name}.so" { LD_PRELOAD = pkgs.runCommandCC "slock-${cfg.user.name}.so" {
passAsFile = ["text"]; passAsFile = ["text"];
text = /* c */ '' text = /* c */ ''