summaryrefslogtreecommitdiffstats
path: root/tv/3modules/slock.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2019-01-16 11:43:10 +0100
committermakefu <github@syntax-fehler.de>2019-01-16 11:43:10 +0100
commite3851e0c69490d19351e0bcef64c23c9070d1d19 (patch)
treea3d1de2957f7c7c2502a399614264852c652cf49 /tv/3modules/slock.nix
parent33655bfd89f7ea6f8ab3e3139cd79f4c2d2a0ef6 (diff)
parent6cef97deb3a96731a4737f05513e2e5855f60685 (diff)
Merge remote-tracking branch 'tv/master'
Diffstat (limited to 'tv/3modules/slock.nix')
-rw-r--r--tv/3modules/slock.nix20
1 files changed, 11 insertions, 9 deletions
diff --git a/tv/3modules/slock.nix b/tv/3modules/slock.nix
index 1c84b1e9e..53f7f1f62 100644
--- a/tv/3modules/slock.nix
+++ b/tv/3modules/slock.nix
@@ -5,10 +5,12 @@ in {
options.tv.slock = {
enable = mkEnableOption "tv.slock";
package = mkOption {
- default = pkgs.execBin "slock" rec {
- filename = "${pkgs.systemd}/bin/systemctl";
- argv = [ filename "start" "slock-${cfg.user.name}.service" ];
- };
+ default = pkgs.writeDashBin "slock" ''
+ set -efu
+ display=''${DISPLAY#:}
+ service=slock-$LOGNAME@$display.service
+ exec ${pkgs.systemd}/bin/systemctl start "$service"
+ '';
type = types.package;
};
user = mkOption {
@@ -18,16 +20,16 @@ in {
config = mkIf cfg.enable {
security.polkit.extraConfig = /* js */ ''
polkit.addRule(function(action, subject) {
- if (action.id == "org.freedesktop.systemd1.manage-units" &&
- action.lookup("unit") == "slock-${cfg.user.name}.service" &&
- subject.user == ${toJSON cfg.user.name}) {
+ if (action.id === "org.freedesktop.systemd1.manage-units" &&
+ subject.user === ${toJSON cfg.user.name} &&
+ /^slock-${cfg.user.name}@[0-9]+\.service$/.test(action.lookup("unit")) ) {
return polkit.Result.YES;
}
});
'';
- systemd.services."slock-${cfg.user.name}" = {
+ systemd.services."slock-${cfg.user.name}@" = {
environment = {
- DISPLAY = ":${toString config.services.xserver.display}";
+ DISPLAY = ":%I";
LD_PRELOAD = pkgs.runCommandCC "slock-${cfg.user.name}.so" {
passAsFile = ["text"];
text = /* c */ ''