From f5b44312145385f5334098e359b7110faeeb3779 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sun, 30 Jul 2023 04:29:37 +0100 Subject: [PATCH] feat: updated flake with the email config --- flake.nix | 57 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 1de2a4d..cbb49b0 100644 --- a/flake.nix +++ b/flake.nix @@ -45,17 +45,22 @@ with lib; let cfg = config.services."${package_name}"; - enviroment_config = { + # secret options are in the env file loaded separately + environment_config = { # non secret ldap stuff LDAP_HOST = cfg.ldap.host; LDAP_ADMIN = cfg.ldap.admin; - # basic dserver stuff - HOME = cfg.home; + # basic server stuff + HOME = "${cfg.home}"; DATABASE = "database.db"; CSV = "wolves.csv"; HOST_PORT = cfg.host_port; + # Email stuff + EMAIL_SMTP = cfg.mail.host + EMAIL_USER = cfg.mail.user + # special categories of users USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin; USERS_COMMITTEE = lib.strings.concatStringsSep "," cfg.users.committee; @@ -84,6 +89,20 @@ }; }; + mail = { + host = mkOption rec { + type = types.str; + default = "mail.skynet.ie"; + description = "Email Host"; + }; + + user = mkOption rec { + type = types.str; + default = "compsoc@skynet.ie"; + description = "User for sending emails"; + }; + }; + users = { admin = mkOption rec { type = types.listOf types.str; @@ -144,7 +163,7 @@ wantedBy = [ "multi-user.target" ]; after = [ "network-online.target" ]; wants = [ ]; - environment = enviroment_config; + environment = environment_config; serviceConfig = { # because we are storing data we need a home for it @@ -161,12 +180,12 @@ description = "${desc} Update groups"; wantedBy = [ ]; after = [ "network-online.target" ]; - environment = enviroment_config; + environment = environment_config; serviceConfig = { Type = "oneshot"; DynamicUser = true; - ExecStart = "${self.defaultPackage."${system}"}/bin/${package_update}"; + ExecStart = "${self.defaultPackage."${system}"}/bin/update_groups"; EnvironmentFile = "${cfg.envFile}"; }; }; @@ -183,6 +202,32 @@ }; }; + # for new users + systemd.services."${cfg.user}_new_users" = { + description = "${desc} Get new users"; + wantedBy = [ ]; + after = [ "network-online.target" ]; + environment = environment_config; + + serviceConfig = { + Type = "oneshot"; + DynamicUser = true; + ExecStart = "${self.defaultPackage."${system}"}/bin/new_users"; + EnvironmentFile = "${cfg.envFile}"; + }; + }; + + systemd.timers."${cfg.user}_new_users" = { + description = "Run the new users script for ${desc}"; + wantedBy = [ "timers.target" ]; + partOf = [ "${cfg.user}_new_users.service" ]; + timerConfig = { + # every hour + OnCalendar = "*-*-* *:15:00"; + Unit = "${cfg.user}_update.service"; + }; + }; + }; };