nixos/home/modules/redshift.nix

48 lines
1.2 KiB
Nix
Raw Normal View History

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