From 7fef2e38eab89caad8e9be93079a3fd51cf479f8 Mon Sep 17 00:00:00 2001 From: Marek Fajkus Date: Sat, 11 May 2019 18:56:48 +0200 Subject: [PATCH 1/3] xss-locker: improve options passing - allow locker options without hacks - add extraOptions --- nixos/modules/programs/xss-lock.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/nixos/modules/programs/xss-lock.nix b/nixos/modules/programs/xss-lock.nix index c290df01b96..24aed58cd2a 100644 --- a/nixos/modules/programs/xss-lock.nix +++ b/nixos/modules/programs/xss-lock.nix @@ -8,12 +8,23 @@ in { options.programs.xss-lock = { enable = mkEnableOption "xss-lock"; + lockerCommand = mkOption { default = "${pkgs.i3lock}/bin/i3lock"; example = literalExample ''''${pkgs.i3lock-fancy}/bin/i3lock-fancy''; type = types.string; description = "Locker to be used with xsslock"; }; + + extraOptions = mkOption { + default = [ ]; + example = literalExample [ "--ignore-sleep" ]; + type = types.listOf types.str; + description = '' + Additional command-line arguments to pass to + xss-lock. + ''; + }; }; config = mkIf cfg.enable { @@ -21,7 +32,13 @@ in description = "XSS Lock Daemon"; wantedBy = [ "graphical-session.target" ]; partOf = [ "graphical-session.target" ]; - serviceConfig.ExecStart = "${pkgs.xss-lock}/bin/xss-lock ${cfg.lockerCommand}"; + serviceConfig.ExecStart = with lib; + strings.concatStringsSep " " ([ + "${pkgs.xss-lock}/bin/xss-lock" + ] ++ cfg.extraOptions ++ [ + "--" + cfg.lockerCommand + ]); }; }; } From 775146165d0161210414566e28e18e3ac021f036 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 12 May 2019 03:20:44 +0200 Subject: [PATCH 2/3] nixos/xss-lock: improve module * Don't use `literalExample`, raw Nix values can directly be specified as an option example which provides support for highlighting in the manual as well. * Escape shell args for `extraOptions`: I.e. the `-n` option might be problematic as a longer notification command might be misinterpreted. --- nixos/modules/programs/xss-lock.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/modules/programs/xss-lock.nix b/nixos/modules/programs/xss-lock.nix index 24aed58cd2a..070463311db 100644 --- a/nixos/modules/programs/xss-lock.nix +++ b/nixos/modules/programs/xss-lock.nix @@ -18,7 +18,7 @@ in extraOptions = mkOption { default = [ ]; - example = literalExample [ "--ignore-sleep" ]; + example = [ "--ignore-sleep" ]; type = types.listOf types.str; description = '' Additional command-line arguments to pass to @@ -35,7 +35,7 @@ in serviceConfig.ExecStart = with lib; strings.concatStringsSep " " ([ "${pkgs.xss-lock}/bin/xss-lock" - ] ++ cfg.extraOptions ++ [ + ] ++ (map escapeShellArg cfg.extraOptions) ++ [ "--" cfg.lockerCommand ]); From d27431b362d8ad3d745989299d52640e4ce9863e Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 12 May 2019 03:22:29 +0200 Subject: [PATCH 3/3] nixos/xss-lock: add testcase for `lockerCommand` with several CLI options. --- nixos/tests/xss-lock.nix | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/nixos/tests/xss-lock.nix b/nixos/tests/xss-lock.nix index b46bb1a8f6e..0d757e8cef3 100644 --- a/nixos/tests/xss-lock.nix +++ b/nixos/tests/xss-lock.nix @@ -6,19 +6,35 @@ with lib; name = "xss-lock"; meta.maintainers = with pkgs.stdenv.lib.maintainers; [ ma27 ]; - machine = { - imports = [ ./common/x11.nix ./common/user-account.nix ]; - programs.xss-lock.enable = true; - services.xserver.displayManager.auto.user = "alice"; + nodes = { + simple = { + imports = [ ./common/x11.nix ./common/user-account.nix ]; + programs.xss-lock.enable = true; + services.xserver.displayManager.auto.user = "alice"; + }; + + custom_lockcmd = { pkgs, ... }: { + imports = [ ./common/x11.nix ./common/user-account.nix ]; + services.xserver.displayManager.auto.user = "alice"; + + programs.xss-lock = { + enable = true; + extraOptions = [ "-n" "${pkgs.libnotify}/bin/notify-send 'About to sleep!'"]; + lockerCommand = "${pkgs.xlockmore}/bin/xlock -mode ant"; + }; + }; }; testScript = '' - $machine->start; - $machine->waitForX; - $machine->waitForUnit("xss-lock.service", "alice"); + startAll; - $machine->fail("pgrep xlock"); - $machine->succeed("su -l alice -c 'xset dpms force standby'"); - $machine->waitUntilSucceeds("pgrep i3lock"); + ${concatStringsSep "\n" (mapAttrsToList (name: lockCmd: '' + ${"$"+name}->start; + ${"$"+name}->waitForX; + ${"$"+name}->waitForUnit("xss-lock.service", "alice"); + ${"$"+name}->fail("pgrep ${lockCmd}"); + ${"$"+name}->succeed("su -l alice -c 'xset dpms force standby'"); + ${"$"+name}->waitUntilSucceeds("pgrep ${lockCmd}"); + '') { simple = "i3lock"; custom_lockcmd = "xlock"; })} ''; })