feat: up[dated the config for the timers and services
This commit is contained in:
parent
057284712c
commit
90a24c97be
1 changed files with 65 additions and 67 deletions
104
flake.nix
104
flake.nix
|
@ -67,6 +67,44 @@
|
||||||
USERS_LIFETIME = lib.strings.concatStringsSep "," cfg.users.lifetime;
|
USERS_LIFETIME = lib.strings.concatStringsSep "," cfg.users.lifetime;
|
||||||
USERS_BANNED = lib.strings.concatStringsSep "," cfg.users.banned;
|
USERS_BANNED = lib.strings.concatStringsSep "," cfg.users.banned;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
service_name = script: lib.strings.sanitizeDerivationName("${cfg.prefix}${cfg.user}@${script}");
|
||||||
|
|
||||||
|
# oneshot scripts to run
|
||||||
|
serviceGenerator = builtins.mapAttrs (script: time: nameValuePair (service_name script) {
|
||||||
|
description = "Service for ${desc} ${script}";
|
||||||
|
wantedBy = [ ];
|
||||||
|
after = [ "network-online.target" ];
|
||||||
|
environment = environment_config;
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
DynamicUser = true;
|
||||||
|
ExecStart = "${self.defaultPackage."${system}"}/bin/${script}";
|
||||||
|
EnvironmentFile = "${cfg.envFile}";
|
||||||
|
};
|
||||||
|
}) scripts;
|
||||||
|
|
||||||
|
# each timer will run the above service
|
||||||
|
timerGenerator = builtins.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;
|
||||||
|
};
|
||||||
|
}) scripts;
|
||||||
|
|
||||||
|
# modify these
|
||||||
|
scripts = {
|
||||||
|
"update_groups" = "*-*-* *:00:00";
|
||||||
|
"new_users" = "*:0/15";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
in {
|
in {
|
||||||
options.services."${package_name}" = {
|
options.services."${package_name}" = {
|
||||||
enable = mkEnableOption "enable ${package_name}";
|
enable = mkEnableOption "enable ${package_name}";
|
||||||
|
@ -145,6 +183,13 @@
|
||||||
description = "The home for the user";
|
description = "The home for the user";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
prefix = mkOption rec {
|
||||||
|
type = types.str;
|
||||||
|
default = "skynet_";
|
||||||
|
example = default;
|
||||||
|
description = "The prefix used to name service/folders";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
@ -158,7 +203,9 @@
|
||||||
group = "${cfg.user}";
|
group = "${cfg.user}";
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services."${cfg.user}" = {
|
systemd.services = {
|
||||||
|
# main service
|
||||||
|
"${cfg.user}" = {
|
||||||
description = desc;
|
description = desc;
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
|
@ -174,59 +221,10 @@
|
||||||
EnvironmentFile = "${cfg.envFile}";
|
EnvironmentFile = "${cfg.envFile}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
} // serviceGenerator;
|
||||||
|
|
||||||
# for updating the data
|
# timers to run the above services
|
||||||
systemd.services."${cfg.user}_update" = {
|
systemd.timers = timerGenerator;
|
||||||
description = "${desc} Update groups";
|
|
||||||
wantedBy = [ ];
|
|
||||||
after = [ "network-online.target" ];
|
|
||||||
environment = environment_config;
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "oneshot";
|
|
||||||
DynamicUser = true;
|
|
||||||
ExecStart = "${self.defaultPackage."${system}"}/bin/update_groups";
|
|
||||||
EnvironmentFile = "${cfg.envFile}";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.timers."${cfg.user}_update" = {
|
|
||||||
description = "Run the update script for ${desc}";
|
|
||||||
|
|
||||||
wantedBy = [ "timers.target" ];
|
|
||||||
partOf = [ "${cfg.user}_update.service" ];
|
|
||||||
timerConfig = {
|
|
||||||
# every hour
|
|
||||||
OnCalendar = "*-*-* *:00:00";
|
|
||||||
Unit = "${cfg.user}_update.service";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# 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 15 min
|
|
||||||
OnCalendar = "*:0/15";
|
|
||||||
Unit = "${cfg.user}_new_users.service";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue