mirror of
https://github.com/nix-community/home-manager
synced 2024-11-27 05:29:46 +01:00
redshift/gammastep: unify common options
Nowadays services.{redshift,gammastep} modules are really similar. They should, since Gammastep is a fork of Redshift with the main objective is to support Wayland. So instead of trying to maintain two separate modules, this commit unify the options in lib/options.nix file, making the implementation of the module itself ends up being really simple (just calling the common options with the necessary parameters to differentiate between them).
This commit is contained in:
parent
c137866bd7
commit
6b15b03898
6 changed files with 70 additions and 190 deletions
5
.github/CODEOWNERS
vendored
5
.github/CODEOWNERS
vendored
|
@ -167,8 +167,6 @@
|
|||
|
||||
/modules/services/fluidsynth.nix @Valodim
|
||||
|
||||
/modules/services/gammastep.nix @petabyteboy
|
||||
|
||||
/modules/services/gnome-keyring.nix @rycee
|
||||
|
||||
/modules/services/gpg-agent.nix @rycee
|
||||
|
@ -215,7 +213,8 @@
|
|||
|
||||
/modules/services/random-background.nix @rycee
|
||||
|
||||
/modules/services/redshift.nix @rycee
|
||||
/modules/services/redshift-gammastep @rycee @petabyteboy @thiagokokada
|
||||
/tests/modules/redshift-gammastep @thiagokokada
|
||||
|
||||
/modules/services/status-notifier-watcher.nix @pltanton
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ let
|
|||
(loadModule ./services/emacs.nix { condition = hostPlatform.isLinux; })
|
||||
(loadModule ./services/flameshot.nix { })
|
||||
(loadModule ./services/fluidsynth.nix { condition = hostPlatform.isLinux; })
|
||||
(loadModule ./services/gammastep.nix { condition = hostPlatform.isLinux; })
|
||||
(loadModule ./services/redshift-gammastep/gammastep.nix { condition = hostPlatform.isLinux; })
|
||||
(loadModule ./services/getmail.nix { condition = hostPlatform.isLinux; })
|
||||
(loadModule ./services/gnome-keyring.nix { })
|
||||
(loadModule ./services/gpg-agent.nix { })
|
||||
|
@ -178,7 +178,7 @@ let
|
|||
(loadModule ./services/polybar.nix { })
|
||||
(loadModule ./services/pulseeffects.nix { condition = hostPlatform.isLinux; })
|
||||
(loadModule ./services/random-background.nix { })
|
||||
(loadModule ./services/redshift.nix { })
|
||||
(loadModule ./services/redshift-gammastep/redshift.nix { })
|
||||
(loadModule ./services/rsibreak.nix { condition = hostPlatform.isLinux; })
|
||||
(loadModule ./services/screen-locker.nix { })
|
||||
(loadModule ./services/stalonetray.nix { })
|
||||
|
|
|
@ -1,166 +0,0 @@
|
|||
# Adapted from Nixpkgs.
|
||||
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.services.gammastep;
|
||||
|
||||
in {
|
||||
meta.maintainers = [ maintainers.petabyteboy ];
|
||||
|
||||
options.services.gammastep = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = true;
|
||||
description = ''
|
||||
Enable Gammastep to change your screen's colour temperature depending on
|
||||
the time of day.
|
||||
'';
|
||||
};
|
||||
|
||||
latitude = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Your current latitude, between <literal>-90.0</literal> and
|
||||
<literal>90.0</literal>. Must be provided along with
|
||||
longitude.
|
||||
'';
|
||||
};
|
||||
|
||||
longitude = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Your current longitude, between <literal>-180.0</literal> and
|
||||
<literal>180.0</literal>. Must be provided along with
|
||||
latitude.
|
||||
'';
|
||||
};
|
||||
|
||||
provider = mkOption {
|
||||
type = types.enum [ "manual" "geoclue2" ];
|
||||
default = "manual";
|
||||
description = ''
|
||||
The location provider to use for determining your location. If set to
|
||||
<literal>manual</literal> you must also provide latitude/longitude.
|
||||
If set to <literal>geoclue2</literal>, you must also enable the global
|
||||
geoclue2 service.
|
||||
'';
|
||||
};
|
||||
|
||||
temperature = {
|
||||
day = mkOption {
|
||||
type = types.int;
|
||||
default = 5500;
|
||||
description = ''
|
||||
Colour temperature to use during the day, between
|
||||
<literal>1000</literal> and <literal>25000</literal> K.
|
||||
'';
|
||||
};
|
||||
|
||||
night = mkOption {
|
||||
type = types.int;
|
||||
default = 3700;
|
||||
description = ''
|
||||
Colour temperature to use at night, between
|
||||
<literal>1000</literal> and <literal>25000</literal> K.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
brightness = {
|
||||
day = mkOption {
|
||||
type = types.str;
|
||||
default = "1";
|
||||
description = ''
|
||||
Screen brightness to apply during the day,
|
||||
between <literal>0.1</literal> and <literal>1.0</literal>.
|
||||
'';
|
||||
};
|
||||
|
||||
night = mkOption {
|
||||
type = types.str;
|
||||
default = "1";
|
||||
description = ''
|
||||
Screen brightness to apply during the night,
|
||||
between <literal>0.1</literal> and <literal>1.0</literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.gammastep;
|
||||
defaultText = literalExample "pkgs.gammastep";
|
||||
description = ''
|
||||
gammastep derivation to use.
|
||||
'';
|
||||
};
|
||||
|
||||
tray = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = true;
|
||||
description = ''
|
||||
Start the gammastep-indicator tray applet.
|
||||
'';
|
||||
};
|
||||
|
||||
extraOptions = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
example = [ "-v" "-m randr" ];
|
||||
description = ''
|
||||
Additional command-line arguments to pass to
|
||||
<command>gammastep</command>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = [{
|
||||
assertion = cfg.provider == "manual" -> cfg.latitude != null
|
||||
&& cfg.longitude != null;
|
||||
message = "Must provide services.gammastep.latitude and"
|
||||
+ " services.gammastep.latitude when"
|
||||
+ " services.gammastep.provider is set to \"manual\".";
|
||||
}];
|
||||
|
||||
systemd.user.services.gammastep = {
|
||||
Unit = {
|
||||
Description = "Gammastep colour temperature adjuster";
|
||||
After = [ "graphical-session-pre.target" ];
|
||||
PartOf = [ "graphical-session.target" ];
|
||||
};
|
||||
|
||||
Install = { WantedBy = [ "graphical-session.target" ]; };
|
||||
|
||||
Service = {
|
||||
ExecStart = let
|
||||
providerString = if cfg.provider == "manual" then
|
||||
"${cfg.latitude}:${cfg.longitude}"
|
||||
else
|
||||
cfg.provider;
|
||||
|
||||
args = [
|
||||
"-l ${providerString}"
|
||||
"-t ${toString cfg.temperature.day}:${
|
||||
toString cfg.temperature.night
|
||||
}"
|
||||
"-b ${toString cfg.brightness.day}:${toString cfg.brightness.night}"
|
||||
] ++ cfg.extraOptions;
|
||||
|
||||
command = if cfg.tray then "gammastep-indicator" else "gammastep";
|
||||
in "${cfg.package}/bin/${command} ${concatStringsSep " " args}";
|
||||
RestartSec = 3;
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
}
|
22
modules/services/redshift-gammastep/gammastep.nix
Normal file
22
modules/services/redshift-gammastep/gammastep.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
commonOptions = import ./lib/options.nix {
|
||||
inherit config lib;
|
||||
|
||||
moduleName = "gammastep";
|
||||
programName = "Gammastep";
|
||||
defaultPackage = pkgs.gammastep;
|
||||
examplePackage = "pkgs.gammastep";
|
||||
mainExecutable = "gammastep";
|
||||
appletExecutable = "gammastep-indicator";
|
||||
serviceDocumentation = "https://gitlab.com/chinstrap/gammastep/";
|
||||
};
|
||||
|
||||
in {
|
||||
meta = commonOptions.meta;
|
||||
options.services.gammastep = commonOptions.options;
|
||||
config = mkIf config.services.gammastep.enable commonOptions.config;
|
||||
}
|
|
@ -1,24 +1,27 @@
|
|||
# Adapted from Nixpkgs.
|
||||
|
||||
{ config, lib, pkgs, ... }:
|
||||
{ config, lib, moduleName, programName, defaultPackage, examplePackage
|
||||
, mainExecutable, appletExecutable, serviceDocumentation }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.services.redshift;
|
||||
cfg = config.services.${moduleName};
|
||||
|
||||
in {
|
||||
meta.maintainers = [ maintainers.rycee ];
|
||||
meta = {
|
||||
maintainers = with maintainers; [ rycee petabyteboy thiagokokada ];
|
||||
};
|
||||
|
||||
options.services.redshift = {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = true;
|
||||
description = ''
|
||||
Enable Redshift to change your screen's colour temperature depending on
|
||||
the time of day.
|
||||
Enable ${programName} to change your screen's colour temperature
|
||||
depending on the time of day.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -81,6 +84,7 @@ in {
|
|||
between <literal>0.1</literal> and <literal>1.0</literal>.
|
||||
'';
|
||||
};
|
||||
|
||||
night = mkOption {
|
||||
type = types.str;
|
||||
default = "1";
|
||||
|
@ -93,10 +97,10 @@ in {
|
|||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.redshift;
|
||||
defaultText = literalExample "pkgs.redshift";
|
||||
default = defaultPackage;
|
||||
defaultText = literalExample examplePackage;
|
||||
description = ''
|
||||
redshift derivation to use.
|
||||
${programName} derivation to use.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -105,7 +109,7 @@ in {
|
|||
default = false;
|
||||
example = true;
|
||||
description = ''
|
||||
Start the redshift-gtk tray applet.
|
||||
Start the ${appletExecutable} tray applet.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -120,19 +124,19 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = {
|
||||
assertions = [{
|
||||
assertion = cfg.provider == "manual" -> cfg.latitude != null
|
||||
&& cfg.longitude != null;
|
||||
message = "Must provide services.redshift.latitude and"
|
||||
+ " services.redshift.latitude when"
|
||||
+ " services.redshift.provider is set to \"manual\".";
|
||||
message = "Must provide services.${moduleName}.latitude and"
|
||||
+ " services.${moduleName}.latitude when"
|
||||
+ " services.${moduleName}.provider is set to \"manual\".";
|
||||
}];
|
||||
|
||||
systemd.user.services.redshift = {
|
||||
systemd.user.services.${moduleName} = {
|
||||
Unit = {
|
||||
Description = "Redshift colour temperature adjuster";
|
||||
Documentation = "http://jonls.dk/redshift/";
|
||||
Description = "${programName} colour temperature adjuster";
|
||||
Documentation = serviceDocumentation;
|
||||
After = [ "graphical-session-pre.target" ];
|
||||
PartOf = [ "graphical-session.target" ];
|
||||
};
|
||||
|
@ -154,12 +158,11 @@ in {
|
|||
"-b ${toString cfg.brightness.day}:${toString cfg.brightness.night}"
|
||||
] ++ cfg.extraOptions;
|
||||
|
||||
command = if cfg.tray then "redshift-gtk" else "redshift";
|
||||
command = if cfg.tray then appletExecutable else mainExecutable;
|
||||
in "${cfg.package}/bin/${command} ${concatStringsSep " " args}";
|
||||
RestartSec = 3;
|
||||
Restart = "on-failure";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
}
|
22
modules/services/redshift-gammastep/redshift.nix
Normal file
22
modules/services/redshift-gammastep/redshift.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
commonOptions = import ./lib/options.nix {
|
||||
inherit config lib;
|
||||
|
||||
moduleName = "redshift";
|
||||
programName = "Redshift";
|
||||
defaultPackage = pkgs.redshift;
|
||||
examplePackage = "pkgs.redshift";
|
||||
mainExecutable = "redshift";
|
||||
appletExecutable = "redshift-gtk";
|
||||
serviceDocumentation = "http://jonls.dk/redshift/";
|
||||
};
|
||||
|
||||
in {
|
||||
meta = commonOptions.meta;
|
||||
options.services.redshift = commonOptions.options;
|
||||
config = mkIf config.services.redshift.enable commonOptions.config;
|
||||
}
|
Loading…
Reference in a new issue