2020-11-28 01:47:35 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let cfg = config.services.wlsunset;
|
|
|
|
|
|
|
|
in {
|
2021-12-25 19:43:41 +01:00
|
|
|
meta.maintainers = [ hm.maintainers.matrss ];
|
2020-11-28 01:47:35 +01:00
|
|
|
|
|
|
|
options.services.wlsunset = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "wlsunset";
|
2020-11-28 01:47:35 +01:00
|
|
|
|
|
|
|
package = mkOption {
|
2024-05-05 19:59:14 +02:00
|
|
|
type = with types; package;
|
2020-11-28 01:47:35 +01:00
|
|
|
default = pkgs.wlsunset;
|
|
|
|
defaultText = "pkgs.wlsunset";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-11-28 01:47:35 +01:00
|
|
|
wlsunset derivation to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
latitude = mkOption {
|
2024-05-05 19:59:14 +02:00
|
|
|
type = with types; nullOr (either str (either float int));
|
|
|
|
default = null;
|
|
|
|
example = -74.3;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Your current latitude, between `-90.0` and
|
|
|
|
`90.0`.
|
2020-11-28 01:47:35 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
longitude = mkOption {
|
2024-05-05 19:59:14 +02:00
|
|
|
type = with types; nullOr (either str (either float int));
|
|
|
|
default = null;
|
|
|
|
example = 12.5;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Your current longitude, between `-180.0` and
|
|
|
|
`180.0`.
|
2020-11-28 01:47:35 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
temperature = {
|
|
|
|
day = mkOption {
|
2024-05-05 19:59:14 +02:00
|
|
|
type = with types; int;
|
2020-11-28 01:47:35 +01:00
|
|
|
default = 6500;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-11-28 01:47:35 +01:00
|
|
|
Colour temperature to use during the day, in Kelvin (K).
|
2023-07-01 01:30:13 +02:00
|
|
|
This value must be greater than `temperature.night`.
|
2020-11-28 01:47:35 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
night = mkOption {
|
2024-05-05 19:59:14 +02:00
|
|
|
type = with types; int;
|
2020-11-28 01:47:35 +01:00
|
|
|
default = 4000;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-11-28 01:47:35 +01:00
|
|
|
Colour temperature to use during the night, in Kelvin (K).
|
2023-07-01 01:30:13 +02:00
|
|
|
This value must be smaller than `temperature.day`.
|
2020-11-28 01:47:35 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
gamma = mkOption {
|
2024-05-05 19:59:14 +02:00
|
|
|
type = with types; (either str (either float int));
|
|
|
|
default = 1.0;
|
|
|
|
example = 0.6;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-11-28 01:47:35 +01:00
|
|
|
Gamma value to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-05 19:59:14 +02:00
|
|
|
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).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-11-28 01:47:35 +01:00
|
|
|
systemdTarget = mkOption {
|
2024-05-05 19:59:14 +02:00
|
|
|
type = with types; str;
|
2020-11-28 01:47:35 +01:00
|
|
|
default = "graphical-session.target";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-11-28 01:47:35 +01:00
|
|
|
Systemd target to bind to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.wlsunset" pkgs
|
|
|
|
lib.platforms.linux)
|
2024-05-05 19:59:14 +02:00
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
2021-07-07 23:24:27 +02:00
|
|
|
];
|
|
|
|
|
2020-11-28 01:47:35 +01:00
|
|
|
systemd.user.services.wlsunset = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Day/night gamma adjustments for Wayland compositors.";
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
ExecStart = let
|
2024-05-05 19:59:14 +02:00
|
|
|
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}";
|
2020-11-28 01:47:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Install = { WantedBy = [ cfg.systemdTarget ]; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|