aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Riße <matthias.risze@t-online.de>2020-11-28 01:47:35 +0100
committerRobert Helgesson <robert@rycee.net>2020-12-01 21:46:46 +0100
commit33407189c1df5742b2e75a13cf1912089c685eb4 (patch)
tree542032a9cf4e4de49d258bad061f79c96aedd90e
parent44f9d68d8c21aecda1cde153b72af5e99d367afe (diff)
wlsunset: add module
This adds the wlsunset module, a program for day/night gamma adjustments on wayland. Fixes #1625
-rw-r--r--.github/CODEOWNERS3
-rw-r--r--modules/lib/maintainers.nix6
-rw-r--r--modules/misc/news.nix8
-rw-r--r--modules/modules.nix1
-rw-r--r--modules/services/wlsunset.nix97
-rw-r--r--tests/default.nix1
-rw-r--r--tests/modules/services/wlsunset/default.nix1
-rw-r--r--tests/modules/services/wlsunset/wlsunset-service-expected.service9
-rw-r--r--tests/modules/services/wlsunset/wlsunset-service.nix25
9 files changed, 151 insertions, 0 deletions
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index fed617251632..5967e4f43db3 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -216,6 +216,9 @@
/modules/services/window-managers/i3-sway/sway.nix @alexarice
+/modules/services/wlsunset.nix @matrss
+/tests/modules/services/wlsunset @matrss
+
/modules/services/xcape.nix @nickhu
/modules/services/xembed-sni-proxy.nix @rycee
diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix
index f70913bcb4b8..715b5b0bbc50 100644
--- a/modules/lib/maintainers.nix
+++ b/modules/lib/maintainers.nix
@@ -31,4 +31,10 @@
github = "olmokramer";
githubId = 3612514;
};
+ matrss = {
+ name = "Matthias Riße";
+ email = "matrss@users.noreply.github.com";
+ github = "matrss";
+ githubId = 9308656;
+ };
}
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index 689aa8f5e2f6..96bd94fe7ca5 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -1759,6 +1759,14 @@ in
];
'';
}
+
+ {
+ time = "2020-12-01T20:46:14+00:00";
+ condition = hostPlatform.isLinux;
+ message = ''
+ A new module is available: 'services.wlsunset'.
+ '';
+ }
];
};
}
diff --git a/modules/modules.nix b/modules/modules.nix
index e7aab60fb8b8..b599fe99099a 100644
--- a/modules/modules.nix
+++ b/modules/modules.nix
@@ -192,6 +192,7 @@ let
(loadModule ./services/window-managers/i3-sway/i3.nix { })
(loadModule ./services/window-managers/i3-sway/sway.nix { condition = hostPlatform.isLinux; })
(loadModule ./services/window-managers/xmonad.nix { })
+ (loadModule ./services/wlsunset.nix { condition = hostPlatform.isLinux; })
(loadModule ./services/xcape.nix { condition = hostPlatform.isLinux; })
(loadModule ./services/xembed-sni-proxy.nix { condition = hostPlatform.isLinux; })
(loadModule ./services/xscreensaver.nix { })
diff --git a/modules/services/wlsunset.nix b/modules/services/wlsunset.nix
new file mode 100644
index 000000000000..084dbdb7c3d6
--- /dev/null
+++ b/modules/services/wlsunset.nix
@@ -0,0 +1,97 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let cfg = config.services.wlsunset;
+
+in {
+ meta.maintainers = [ maintainers.matrss ];
+
+ options.services.wlsunset = {
+ enable = mkEnableOption "Whether to enable wlsunset.";
+
+ package = mkOption {
+ type = types.package;
+ default = pkgs.wlsunset;
+ defaultText = "pkgs.wlsunset";
+ description = ''
+ wlsunset derivation to use.
+ '';
+ };
+
+ latitude = mkOption {
+ type = types.str;
+ description = ''
+ Your current latitude, between <literal>-90.0</literal> and
+ <literal>90.0</literal>.
+ '';
+ };
+
+ longitude = mkOption {
+ type = types.str;
+ description = ''
+ Your current longitude, between <literal>-180.0</literal> and
+ <literal>180.0</literal>.
+ '';
+ };
+
+ temperature = {
+ day = mkOption {
+ type = types.int;
+ default = 6500;
+ description = ''
+ Colour temperature to use during the day, in Kelvin (K).
+ This value must be greater than <literal>temperature.night</literal>.
+ '';
+ };
+
+ night = mkOption {
+ type = types.int;
+ default = 4000;
+ description = ''
+ Colour temperature to use during the night, in Kelvin (K).
+ This value must be smaller than <literal>temperature.day</literal>.
+ '';
+ };
+ };
+
+ gamma = mkOption {
+ type = types.str;
+ default = "1.0";
+ description = ''
+ Gamma value to use.
+ '';
+ };
+
+ systemdTarget = mkOption {
+ type = types.str;
+ default = "graphical-session.target";
+ description = ''
+ Systemd target to bind to.
+ '';
+ };
+ };
+
+ config = mkIf cfg.enable {
+ systemd.user.services.wlsunset = {
+ Unit = {
+ Description = "Day/night gamma adjustments for Wayland compositors.";
+ PartOf = [ "graphical-session.target" ];
+ };
+
+ 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}";
+ };
+
+ Install = { WantedBy = [ cfg.systemdTarget ]; };
+ };
+ };
+}
diff --git a/tests/default.nix b/tests/default.nix
index 5386005fda38..1ce1b5a27ca3 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -99,6 +99,7 @@ import nmt {
./modules/services/sxhkd
./modules/services/window-managers/i3
./modules/services/window-managers/sway
+ ./modules/services/wlsunset
./modules/systemd
./modules/targets-linux
]);
diff --git a/tests/modules/services/wlsunset/default.nix b/tests/modules/services/wlsunset/default.nix
new file mode 100644
index 000000000000..d59af701535b
--- /dev/null
+++ b/tests/modules/services/wlsunset/default.nix
@@ -0,0 +1 @@
+{ wlsunset-service = ./wlsunset-service.nix; }
diff --git a/tests/modules/services/wlsunset/wlsunset-service-expected.service b/tests/modules/services/wlsunset/wlsunset-service-expected.service
new file mode 100644
index 000000000000..f0cf96f3ad0a
--- /dev/null
+++ b/tests/modules/services/wlsunset/wlsunset-service-expected.service
@@ -0,0 +1,9 @@
+[Install]
+WantedBy=test.target
+
+[Service]
+ExecStart=@wlsunset@/bin/wlsunset -l 12.3 -L 128.8 -t 3500 -T 6000 -g 0.6
+
+[Unit]
+Description=Day/night gamma adjustments for Wayland compositors.
+PartOf=graphical-session.target
diff --git a/tests/modules/services/wlsunset/wlsunset-service.nix b/tests/modules/services/wlsunset/wlsunset-service.nix
new file mode 100644
index 000000000000..de32a8270be0
--- /dev/null
+++ b/tests/modules/services/wlsunset/wlsunset-service.nix
@@ -0,0 +1,25 @@
+{ config, pkgs, ... }:
+
+{
+ config = {
+ services.wlsunset = {
+ enable = true;
+ package = pkgs.writeScriptBin "dummy-wlsunset" "" // {
+ outPath = "@wlsunset@";
+ };
+ latitude = "12.3";
+ longitude = "128.8";
+ temperature.day = 6000;
+ temperature.night = 3500;
+ gamma = "0.6";
+ systemdTarget = "test.target";
+ };
+
+ nmt.script = ''
+ serviceFile=home-files/.config/systemd/user/wlsunset.service
+
+ assertFileExists $serviceFile
+ assertFileContent $serviceFile ${./wlsunset-service-expected.service}
+ '';
+ };
+}