feat: updated flake with the email config

This commit is contained in:
silver 2023-07-30 04:29:37 +01:00
parent 53409add42
commit f5b4431214

View file

@ -45,17 +45,22 @@
with lib; with lib;
let let
cfg = config.services."${package_name}"; cfg = config.services."${package_name}";
enviroment_config = { # secret options are in the env file loaded separately
environment_config = {
# non secret ldap stuff # non secret ldap stuff
LDAP_HOST = cfg.ldap.host; LDAP_HOST = cfg.ldap.host;
LDAP_ADMIN = cfg.ldap.admin; LDAP_ADMIN = cfg.ldap.admin;
# basic dserver stuff # basic server stuff
HOME = cfg.home; HOME = "${cfg.home}";
DATABASE = "database.db"; DATABASE = "database.db";
CSV = "wolves.csv"; CSV = "wolves.csv";
HOST_PORT = cfg.host_port; HOST_PORT = cfg.host_port;
# Email stuff
EMAIL_SMTP = cfg.mail.host
EMAIL_USER = cfg.mail.user
# special categories of users # special categories of users
USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin; USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin;
USERS_COMMITTEE = lib.strings.concatStringsSep "," cfg.users.committee; 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 = { users = {
admin = mkOption rec { admin = mkOption rec {
type = types.listOf types.str; type = types.listOf types.str;
@ -144,7 +163,7 @@
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ]; after = [ "network-online.target" ];
wants = [ ]; wants = [ ];
environment = enviroment_config; environment = environment_config;
serviceConfig = { serviceConfig = {
# because we are storing data we need a home for it # because we are storing data we need a home for it
@ -161,12 +180,12 @@
description = "${desc} Update groups"; description = "${desc} Update groups";
wantedBy = [ ]; wantedBy = [ ];
after = [ "network-online.target" ]; after = [ "network-online.target" ];
environment = enviroment_config; environment = environment_config;
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
DynamicUser = true; DynamicUser = true;
ExecStart = "${self.defaultPackage."${system}"}/bin/${package_update}"; ExecStart = "${self.defaultPackage."${system}"}/bin/update_groups";
EnvironmentFile = "${cfg.envFile}"; 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";
};
};
}; };
}; };