redshift: create module

This commit is contained in:
Zynh Ludwig 2024-07-24 00:18:22 -07:00
parent f2699971d4
commit 9ce514aa6d

42
home/modules/redshift.nix Normal file
View file

@ -0,0 +1,42 @@
{ lib, config, pkgs, ... }:
let
cfg = config.snowhawk.redshift;
cfgDir = config.xdg.configHome + "/redshift";
in
{
options.snowhawk.redshift = {
enable = lib.mkEnableOption "redshift home-manager module";
};
config = lib.mkIf cfg.enable {
systemd.user.services.redshift = {
Unit = {
Description = "redshift service";
PartOf = [ "graphical-session.target" ];
};
Service = {
Type = "exec";
ExecStart =
let
catFile = file: "$(${pkgs.coreutils}/bin/cat ${file})";
toPaths = deg: "${cfgDir}/${deg}";
fetchLatLon = lib.right
(lib.strings.concatStringsSep ":")
(map catFile)
(map toPaths)
[ "lat" "lon" ];
in
"${pkgs.redshift}/bin/redshift -l ${fetchLatLon}";
};
Install = {
WantedBy = [ "graphical-session.target" ];
};
};
sops.secrets = {
"locations/snowhawk/lat".path = "${cfgDir}/lat";
"locations/snowhawk/lon".path = "${cfgDir}/lon";
};
};
}