From 3dfe05aa9b5646995ace887931fa60269a039777 Mon Sep 17 00:00:00 2001 From: Daru <135046711+Daru-san@users.noreply.github.com> Date: Sun, 5 May 2024 19:59:14 +0200 Subject: [PATCH] wlsunset: update options --- modules/services/wlsunset.nix | 82 +++++++++++++++---- .../wlsunset-service-expected.service | 2 +- 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/modules/services/wlsunset.nix b/modules/services/wlsunset.nix index 3bc3f2f74..f3352750c 100644 --- a/modules/services/wlsunset.nix +++ b/modules/services/wlsunset.nix @@ -11,7 +11,7 @@ in { enable = mkEnableOption "wlsunset"; package = mkOption { - type = types.package; + type = with types; package; default = pkgs.wlsunset; defaultText = "pkgs.wlsunset"; description = '' @@ -20,7 +20,9 @@ in { }; latitude = mkOption { - type = types.str; + type = with types; nullOr (either str (either float int)); + default = null; + example = -74.3; description = '' Your current latitude, between `-90.0` and `90.0`. @@ -28,7 +30,9 @@ in { }; longitude = mkOption { - type = types.str; + type = with types; nullOr (either str (either float int)); + default = null; + example = 12.5; description = '' Your current longitude, between `-180.0` and `180.0`. @@ -37,7 +41,7 @@ in { temperature = { day = mkOption { - type = types.int; + type = with types; int; default = 6500; description = '' Colour temperature to use during the day, in Kelvin (K). @@ -46,7 +50,7 @@ in { }; night = mkOption { - type = types.int; + type = with types; int; default = 4000; description = '' Colour temperature to use during the night, in Kelvin (K). @@ -56,15 +60,42 @@ in { }; gamma = mkOption { - type = types.str; - default = "1.0"; + type = with types; (either str (either float int)); + default = 1.0; + example = 0.6; description = '' Gamma value to use. ''; }; + output = mkOption { + type = with types; nullOr str; + default = null; + description = '' + Name of output to use, by default all outputs are used. + ''; + }; + + sunrise = mkOption { + type = with types; nullOr str; + default = null; + example = "06:30"; + description = '' + The time when the sun rises (in 24 hour format). + ''; + }; + + sunset = mkOption { + type = with types; nullOr str; + default = null; + example = "18:00"; + description = '' + The time when the sun sets (in 24 hour format). + ''; + }; + systemdTarget = mkOption { - type = types.str; + type = with types; str; default = "graphical-session.target"; description = '' Systemd target to bind to. @@ -76,6 +107,22 @@ in { assertions = [ (lib.hm.assertions.assertPlatform "services.wlsunset" pkgs lib.platforms.linux) + { + assertion = (cfg.sunrise != null || cfg.sunset != null) + != (cfg.latitude != null || cfg.longitude != null); + message = + "Either `sunrise` and `sunset` together or `longitude` and `latitude` together must be set for wlsunset"; + } + { + assertion = (cfg.sunrise != null) == (cfg.sunset != null); + message = + "Both `sunset` and `sunrise` together must be set for wlsunset"; + } + { + assertion = (cfg.latitude != null) == (cfg.longitude != null); + message = + "Both `latitude and `longitude` together must be set for wlsunset"; + } ]; systemd.user.services.wlsunset = { @@ -86,14 +133,17 @@ in { Service = { ExecStart = let - args = [ - "-l ${cfg.latitude}" - "-L ${cfg.longitude}" - "-t ${toString cfg.temperature.night}" - "-T ${toString cfg.temperature.day}" - "-g ${cfg.gamma}" - ]; - in "${cfg.package}/bin/wlsunset ${concatStringsSep " " args}"; + args = cli.toGNUCommandLineShell { } { + t = cfg.temperature.night; + T = cfg.temperature.day; + g = cfg.gamma; + l = cfg.latitude; + L = cfg.longitude; + S = cfg.sunrise; + s = cfg.sunset; + o = cfg.output; + }; + in "${cfg.package}/bin/wlsunset ${args}"; }; Install = { WantedBy = [ cfg.systemdTarget ]; }; diff --git a/tests/modules/services/wlsunset/wlsunset-service-expected.service b/tests/modules/services/wlsunset/wlsunset-service-expected.service index f0cf96f3a..f311d900e 100644 --- a/tests/modules/services/wlsunset/wlsunset-service-expected.service +++ b/tests/modules/services/wlsunset/wlsunset-service-expected.service @@ -2,7 +2,7 @@ WantedBy=test.target [Service] -ExecStart=@wlsunset@/bin/wlsunset -l 12.3 -L 128.8 -t 3500 -T 6000 -g 0.6 +ExecStart=@wlsunset@/bin/wlsunset '-L' '128.8' '-T' '6000' '-g' '0.6' '-l' '12.3' '-t' '3500' [Unit] Description=Day/night gamma adjustments for Wayland compositors.