diff --git a/flake.nix b/flake.nix index 94270a6..e31ef88 100644 --- a/flake.nix +++ b/flake.nix @@ -57,6 +57,48 @@ HOME = cfg.home; DATABASE = "database.db"; }; + + # oneshot scripts to run + serviceGenerator = mapAttrs' (script: time: nameValuePair (service_name script) { + description = "Service for ${desc} ${script}"; + wantedBy = [ ]; + after = [ "network-online.target" ]; + environment = environment_config; + + serviceConfig = { + Type = "oneshot"; + User = "${cfg.user}"; + Group = "${cfg.user}"; + ExecStart = "${self.defaultPackage."${system}"}/bin/${script}"; + EnvironmentFile = [ + "${cfg.env.ldap}" + "${cfg.env.discord}" + "${cfg.env.mail}" + ]; + }; + }); + + # each timer will run the above service + timerGenerator = mapAttrs' (script: time: nameValuePair (service_name script) { + description = "Timer for ${desc} ${script}"; + + wantedBy = [ "timers.target" ]; + partOf = [ "${service_name script}.service" ]; + timerConfig = { + OnCalendar = time; + Unit = "${service_name script}.service"; + Persistent = true; + }; + }); + + # modify these + scripts = { + # every 20 min + "update_data" = "*:0,20,40"; + # groups are updated every 8 hours, offset from teh ldap + "update_users" = "01,09,17:00:00"; + }; + in { options.services."${package_name}" = { enable = mkEnableOption "enable ${package_name}";