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