feat: added the function to get teh data and updated teh times tehy run at #35
1 changed files with 65 additions and 67 deletions
132
flake.nix
132
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}";
|
||||||
|
@ -144,6 +182,13 @@
|
||||||
default = "/etc/skynet_${package_name}";
|
default = "/etc/skynet_${package_name}";
|
||||||
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";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -158,75 +203,28 @@
|
||||||
group = "${cfg.user}";
|
group = "${cfg.user}";
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services."${cfg.user}" = {
|
systemd.services = {
|
||||||
description = desc;
|
# main service
|
||||||
wantedBy = [ "multi-user.target" ];
|
"${cfg.user}" = {
|
||||||
after = [ "network-online.target" ];
|
description = desc;
|
||||||
wants = [ ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
environment = environment_config;
|
after = [ "network-online.target" ];
|
||||||
|
wants = [ ];
|
||||||
serviceConfig = {
|
environment = environment_config;
|
||||||
# because we are storing data we need a home for it
|
|
||||||
User = "${cfg.user}";
|
serviceConfig = {
|
||||||
Group = "${cfg.user}";
|
# because we are storing data we need a home for it
|
||||||
Restart = "always";
|
User = "${cfg.user}";
|
||||||
ExecStart = "${self.defaultPackage."${system}"}/bin/${package_name}";
|
Group = "${cfg.user}";
|
||||||
EnvironmentFile = "${cfg.envFile}";
|
Restart = "always";
|
||||||
|
ExecStart = "${self.defaultPackage."${system}"}/bin/${package_name}";
|
||||||
|
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