nixos/home/modules/redshift.nix

48 lines
1.2 KiB
Nix
Raw Normal View History

2024-07-24 00:18:22 -07:00
{ lib, config, pkgs, ... }:
let
cfg = config.snowhawk.redshift;
cfgDir = config.xdg.configHome + "/redshift";
2024-07-24 01:16:12 -07:00
sops = config.snowhawk.sops.enable;
2024-07-24 00:18:22 -07:00
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" ];
2024-07-24 01:16:12 -07:00
After = lib.mkIf sops [ "sops-nix.service" ];
2024-07-24 00:18:22 -07:00
};
Service = {
Type = "exec";
ExecStart =
let
2024-07-24 01:52:41 -07:00
catFile = file: "\$(${pkgs.coreutils}/bin/cat ${file})";
2024-07-24 00:18:22 -07:00
toPaths = deg: "${cfgDir}/${deg}";
fetchLatLon = lib.right
(lib.strings.concatStringsSep ":")
(map catFile)
(map toPaths)
[ "lat" "lon" ];
in
2024-07-24 01:57:08 -07:00
''${pkgs.bash}/bin/bash -c "${pkgs.redshift}/bin/redshift -l ${fetchLatLon}"'';
2024-07-24 00:18:22 -07:00
};
2024-08-03 02:46:35 -07:00
Install.WantedBy = [ "graphical-session.target" ];
2024-07-24 00:18:22 -07:00
};
sops.secrets = lib.mkIf sops {
2024-07-24 00:18:22 -07:00
"locations/snowhawk/lat".path = "${cfgDir}/lat";
"locations/snowhawk/lon".path = "${cfgDir}/lon";
};
2024-09-24 08:01:30 -07:00
home.packages = with pkgs; [
redshift
];
2024-07-24 00:18:22 -07:00
};
}