2021-01-28 01:25:47 +01:00
|
|
|
{ config, lib, pkgs, moduleName, mainSection, programName, defaultPackage
|
|
|
|
, examplePackage, mainExecutable, appletExecutable, xdgConfigFilePath
|
|
|
|
, serviceDocumentation }:
|
2017-01-20 19:26:52 +01:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2021-01-23 23:03:57 +01:00
|
|
|
cfg = config.services.${moduleName};
|
2021-01-28 01:25:47 +01:00
|
|
|
settingsFormat = pkgs.formats.ini { };
|
2017-01-20 19:26:52 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2022-07-04 11:39:38 +02:00
|
|
|
meta.maintainers = with maintainers; [ rycee thiagokokada ];
|
2017-01-20 19:26:52 +01:00
|
|
|
|
2021-01-28 01:25:47 +01:00
|
|
|
imports = let
|
|
|
|
mkRenamed = old: new:
|
|
|
|
mkRenamedOptionModule ([ "services" moduleName ] ++ old) [
|
|
|
|
"services"
|
|
|
|
moduleName
|
|
|
|
"settings"
|
|
|
|
mainSection
|
|
|
|
new
|
|
|
|
];
|
|
|
|
in [
|
|
|
|
(mkRemovedOptionModule [ "services" moduleName "extraOptions" ]
|
|
|
|
"All ${programName} configuration is now available through services.${moduleName}.settings instead.")
|
|
|
|
(mkRenamed [ "brightness" "day" ] "brightness-day")
|
|
|
|
(mkRenamed [ "brightness" "night" ] "brightness-night")
|
|
|
|
];
|
|
|
|
|
2021-01-23 23:03:57 +01:00
|
|
|
options = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption programName;
|
2021-01-28 01:25:47 +01:00
|
|
|
|
|
|
|
dawnTime = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "6:00-7:45";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-28 01:25:47 +01:00
|
|
|
Set the time interval of dawn manually.
|
|
|
|
The times must be specified as HH:MM in 24-hour format.
|
2021-01-28 01:25:47 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-01-28 01:25:47 +01:00
|
|
|
duskTime = mkOption {
|
2021-02-07 10:20:03 +01:00
|
|
|
type = types.nullOr types.str;
|
2021-01-28 01:25:47 +01:00
|
|
|
default = null;
|
2021-01-28 01:25:47 +01:00
|
|
|
example = "18:35-20:15";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-28 01:25:47 +01:00
|
|
|
Set the time interval of dusk manually.
|
|
|
|
The times must be specified as HH:MM in 24-hour format.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
latitude = mkOption {
|
|
|
|
type = with types; nullOr (either str float);
|
|
|
|
default = null;
|
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`. Must be provided along with
|
2018-07-13 20:54:20 +02:00
|
|
|
longitude.
|
2017-01-20 19:26:52 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
longitude = mkOption {
|
2021-01-28 01:25:47 +01:00
|
|
|
type = with types; nullOr (either str float);
|
2018-07-13 20:54:20 +02:00
|
|
|
default = null;
|
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`. Must be provided along with
|
2018-07-13 20:54:20 +02:00
|
|
|
latitude.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
provider = mkOption {
|
|
|
|
type = types.enum [ "manual" "geoclue2" ];
|
|
|
|
default = "manual";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-07-13 20:54:20 +02:00
|
|
|
The location provider to use for determining your location. If set to
|
2023-07-01 01:30:13 +02:00
|
|
|
`manual` you must also provide latitude/longitude.
|
|
|
|
If set to `geoclue2`, you must also enable the global
|
2018-07-13 20:54:20 +02:00
|
|
|
geoclue2 service.
|
2017-01-20 19:26:52 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
temperature = {
|
|
|
|
day = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 5500;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2017-01-20 19:26:52 +01:00
|
|
|
Colour temperature to use during the day, between
|
2023-07-01 01:30:13 +02:00
|
|
|
`1000` and `25000` K.
|
2017-01-20 19:26:52 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
night = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 3700;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2017-01-20 19:26:52 +01:00
|
|
|
Colour temperature to use at night, between
|
2023-07-01 01:30:13 +02:00
|
|
|
`1000` and `25000` K.
|
2017-01-20 19:26:52 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2021-01-23 23:03:57 +01:00
|
|
|
default = defaultPackage;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression examplePackage;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-23 23:03:57 +01:00
|
|
|
${programName} derivation to use.
|
2017-01-20 19:26:52 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
enableVerboseLogging = mkEnableOption "verbose service logging";
|
2022-09-09 21:25:49 +02:00
|
|
|
|
2018-01-10 21:31:28 +01:00
|
|
|
tray = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-23 23:03:57 +01:00
|
|
|
Start the ${appletExecutable} tray applet.
|
2018-01-10 21:31:28 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-01-28 01:25:47 +01:00
|
|
|
settings = mkOption {
|
|
|
|
type = types.submodule { freeformType = settingsFormat.type; };
|
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-01-28 01:25:47 +01:00
|
|
|
{
|
|
|
|
${mainSection} = {
|
|
|
|
adjustment-method = "randr";
|
|
|
|
};
|
|
|
|
randr = {
|
|
|
|
screen = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-28 01:25:47 +01:00
|
|
|
The configuration to pass to ${programName}.
|
|
|
|
Available options for ${programName} described in
|
2023-07-01 01:30:13 +02:00
|
|
|
{manpage}`${moduleName}(1)`.
|
2017-01-20 19:26:52 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-01-23 23:03:57 +01:00
|
|
|
config = {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "services.${moduleName}" pkgs
|
|
|
|
platforms.linux)
|
|
|
|
|
|
|
|
{
|
|
|
|
assertion = (cfg.settings ? ${mainSection}.dawn-time || cfg.settings
|
|
|
|
? ${mainSection}.dusk-time)
|
|
|
|
|| (cfg.settings.${mainSection}.location-provider) == "geoclue2"
|
|
|
|
|| ((cfg.settings.${mainSection}.location-provider) == "manual"
|
|
|
|
&& (cfg.settings ? manual.lat || cfg.settings ? manual.lon));
|
|
|
|
message = ''
|
|
|
|
In order for ${programName} to know the time of action, you need to set one of
|
|
|
|
- services.${moduleName}.provider = "geoclue2" for automatically inferring your location
|
|
|
|
(you also need to enable Geoclue2 service separately)
|
|
|
|
- services.${moduleName}.longitude and .latitude for specifying your location manually
|
|
|
|
- services.${moduleName}.dawnTime and .duskTime for specifying the times manually
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
2019-10-02 22:00:58 +02:00
|
|
|
|
2021-01-28 01:25:47 +01:00
|
|
|
services.${moduleName}.settings = {
|
|
|
|
${mainSection} = {
|
|
|
|
temp-day = cfg.temperature.day;
|
|
|
|
temp-night = cfg.temperature.night;
|
|
|
|
location-provider = cfg.provider;
|
|
|
|
dawn-time = mkIf (cfg.dawnTime != null) cfg.dawnTime;
|
|
|
|
dusk-time = mkIf (cfg.duskTime != null) cfg.duskTime;
|
|
|
|
};
|
|
|
|
manual = mkIf (cfg.provider == "manual") {
|
|
|
|
lat = mkIf (cfg.latitude != null) (toString cfg.latitude);
|
|
|
|
lon = mkIf (cfg.longitude != null) (toString cfg.longitude);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
xdg.configFile.${xdgConfigFilePath}.source =
|
|
|
|
settingsFormat.generate xdgConfigFilePath cfg.settings;
|
|
|
|
|
2023-02-27 15:49:49 +01:00
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
2021-01-23 23:03:57 +01:00
|
|
|
systemd.user.services.${moduleName} = {
|
2022-08-05 22:55:25 +02:00
|
|
|
Unit = let
|
|
|
|
geoclueAgentService =
|
|
|
|
lib.optional (cfg.provider == "geoclue2") "geoclue-agent.service";
|
|
|
|
in {
|
2021-01-23 23:03:57 +01:00
|
|
|
Description = "${programName} colour temperature adjuster";
|
|
|
|
Documentation = serviceDocumentation;
|
2022-08-05 22:55:25 +02:00
|
|
|
After = [ "graphical-session-pre.target" ] ++ geoclueAgentService;
|
|
|
|
Wants = geoclueAgentService;
|
2017-06-26 18:34:09 +02:00
|
|
|
PartOf = [ "graphical-session.target" ];
|
2017-01-20 19:26:52 +01:00
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2017-01-20 19:26:52 +01:00
|
|
|
|
|
|
|
Service = {
|
2020-02-02 00:39:17 +01:00
|
|
|
ExecStart = let
|
2021-01-23 23:03:57 +01:00
|
|
|
command = if cfg.tray then appletExecutable else mainExecutable;
|
2021-01-28 01:25:47 +01:00
|
|
|
configFullPath = config.xdg.configHome + "/${xdgConfigFilePath}";
|
2022-09-09 21:25:49 +02:00
|
|
|
in "${cfg.package}/bin/${command} " + cli.toGNUCommandLineShell { } {
|
|
|
|
v = cfg.enableVerboseLogging;
|
|
|
|
c = configFullPath;
|
|
|
|
};
|
2017-01-20 19:26:52 +01:00
|
|
|
RestartSec = 3;
|
2020-03-16 16:43:11 +01:00
|
|
|
Restart = "on-failure";
|
2017-01-20 19:26:52 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|