feat: added the function to get teh data and updated teh times tehy run at #35

Merged
silver merged 6 commits from #10_wolves_database into main 2023-08-05 21:36:30 +00:00
Showing only changes of commit 90a24c97be - Show all commits

104
flake.nix
View file

@ -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";
};
};
}; };