From 1300b7f6ecf3e8387e1ab2277f33e3f5a31bd634 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sun, 17 Sep 2023 19:43:27 +0100 Subject: [PATCH] feat: added the two scripts to systemd --- flake.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) 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}";