mirror of
https://github.com/nix-community/home-manager
synced 2024-11-10 07:04:17 +00:00
redshift-gammastep: support reading latitude and longitude from files
Support reading latitude and longitude from files, which is useful for reading the values from decrypted runtime files. The new strNotFloat type catches deprecated str types used for the latitude and longitude options. The systemd ExecStart command points to a wrapper script for subshell invocations.
This commit is contained in:
parent
10541f19c5
commit
dfa7ef2b73
6 changed files with 52 additions and 21 deletions
|
@ -28,7 +28,17 @@ in {
|
|||
(mkRenamed [ "brightness" "night" ] "brightness-night")
|
||||
];
|
||||
|
||||
options = {
|
||||
options = let
|
||||
strNotFloat = (pattern:
|
||||
lib.mkOptionType {
|
||||
inherit (lib.types.str) merge;
|
||||
|
||||
check = x: lib.types.str.check x && builtins.match pattern x == null;
|
||||
description = "string not matching the pattern ${pattern}";
|
||||
descriptionClass = "noun";
|
||||
name = "strNotMatching ${lib.strings.escapeNixString pattern}";
|
||||
}) "^-?[0-9]+\\.[0-9]+$";
|
||||
in {
|
||||
enable = mkEnableOption programName;
|
||||
|
||||
dawnTime = mkOption {
|
||||
|
@ -52,22 +62,30 @@ in {
|
|||
};
|
||||
|
||||
latitude = mkOption {
|
||||
type = with types; nullOr (either str float);
|
||||
type = with types; nullOr (either float strNotFloat);
|
||||
default = null;
|
||||
description = ''
|
||||
Your current latitude, between `-90.0` and
|
||||
`90.0`. Must be provided along with
|
||||
longitude.
|
||||
|
||||
Specifying a string retrieves the latitude using the `"$(<
|
||||
"''${config.services.${moduleName}.latitude}")"` command at runtime,
|
||||
which is useful for reading the value from a decrypted runtime file.
|
||||
'';
|
||||
};
|
||||
|
||||
longitude = mkOption {
|
||||
type = with types; nullOr (either str float);
|
||||
type = with types; nullOr (either float strNotFloat);
|
||||
default = null;
|
||||
description = ''
|
||||
Your current longitude, between `-180.0` and
|
||||
`180.0`. Must be provided along with
|
||||
latitude.
|
||||
|
||||
Specifying a string retrieves the longitude using the `"$(<
|
||||
"''${config.services.${moduleName}.longitude}")"` command at runtime,
|
||||
which is useful for reading the value from a decrypted runtime file.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -152,7 +170,7 @@ in {
|
|||
? ${mainSection}.dusk-time)
|
||||
|| (cfg.settings.${mainSection}.location-provider) == "geoclue2"
|
||||
|| ((cfg.settings.${mainSection}.location-provider) == "manual"
|
||||
&& (cfg.settings ? manual.lat || cfg.settings ? manual.lon));
|
||||
&& (cfg.latitude != null || cfg.longitude != null));
|
||||
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
|
||||
|
@ -171,10 +189,6 @@ in {
|
|||
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 =
|
||||
|
@ -200,10 +214,30 @@ in {
|
|||
ExecStart = let
|
||||
command = if cfg.tray then appletExecutable else mainExecutable;
|
||||
configFullPath = config.xdg.configHome + "/${xdgConfigFilePath}";
|
||||
in "${cfg.package}/bin/${command} " + cli.toGNUCommandLineShell { } {
|
||||
v = cfg.enableVerboseLogging;
|
||||
c = configFullPath;
|
||||
};
|
||||
in pkgs.writeShellScript moduleName ''
|
||||
${cfg.package}/bin/${command} ${
|
||||
cli.toGNUCommandLineShell { } {
|
||||
v = cfg.enableVerboseLogging;
|
||||
c = configFullPath;
|
||||
}
|
||||
} ${
|
||||
optionalString (cfg.provider == "manual"
|
||||
&& (cfg.latitude != null || cfg.longitude != null)) ''
|
||||
-l "${
|
||||
optionalString (cfg.latitude != null)
|
||||
(if builtins.isFloat cfg.latitude then
|
||||
toString cfg.latitude
|
||||
else
|
||||
''$(< "${cfg.latitude}")'')
|
||||
}:${
|
||||
optionalString (cfg.latitude != null)
|
||||
(if builtins.isFloat cfg.longitude then
|
||||
toString cfg.longitude
|
||||
else
|
||||
''$(< "${cfg.longitude}")'')
|
||||
}"''
|
||||
}
|
||||
'';
|
||||
RestartSec = 3;
|
||||
Restart = "on-failure";
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
WantedBy=graphical-session.target
|
||||
|
||||
[Service]
|
||||
ExecStart=@gammastep@/bin/gammastep -c /home/hm-user/.config/gammastep/config.ini
|
||||
ExecStart=@gammastep@
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
|
||||
|
|
|
@ -7,7 +7,5 @@ location-provider=manual
|
|||
temp-day=5500
|
||||
temp-night=3700
|
||||
|
||||
[manual]
|
||||
|
||||
[randr]
|
||||
screen=0
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
WantedBy=graphical-session.target
|
||||
|
||||
[Service]
|
||||
ExecStart=@redshift@/bin/redshift -c /home/hm-user/.config/redshift/redshift.conf
|
||||
ExecStart=@redshift@
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
[manual]
|
||||
lat=0.000000
|
||||
lon=0.0
|
||||
|
||||
[randr]
|
||||
screen=0
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
enable = true;
|
||||
provider = "manual";
|
||||
latitude = 0.0;
|
||||
longitude = "0.0";
|
||||
longitude = "$XDG_RUNTIME_DIR/longitude";
|
||||
settings = {
|
||||
redshift = {
|
||||
adjustment-method = "randr";
|
||||
|
@ -19,6 +19,9 @@
|
|||
test.stubs.redshift = { };
|
||||
|
||||
nmt.script = ''
|
||||
export XDG_RUNTIME_DIR="$(mktemp --directory)"
|
||||
echo 0.0 > "$XDG_RUNTIME_DIR/longitude"
|
||||
|
||||
assertFileContent \
|
||||
home-files/.config/redshift/redshift.conf \
|
||||
${./redshift-basic-configuration-file-expected.conf}
|
||||
|
|
Loading…
Reference in a new issue