From 9ce514aa6d29dabe26c7c5784bfb7e60a930cbbd Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Wed, 24 Jul 2024 00:18:22 -0700 Subject: [PATCH] redshift: create module --- home/modules/redshift.nix | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 home/modules/redshift.nix diff --git a/home/modules/redshift.nix b/home/modules/redshift.nix new file mode 100644 index 0000000..61a180b --- /dev/null +++ b/home/modules/redshift.nix @@ -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"; + }; + }; +}