From e5e3433df03cc6e1605d26ea4c6e5bbd2179a646 Mon Sep 17 00:00:00 2001 From: kalipso Date: Sat, 23 Nov 2024 12:30:29 +0100 Subject: [PATCH] [microvm] automatic update from master every 20mins --- machines/modules/malobeo/microvm_host.nix | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/machines/modules/malobeo/microvm_host.nix b/machines/modules/malobeo/microvm_host.nix index 9fbfcdeb..979de322 100644 --- a/machines/modules/malobeo/microvm_host.nix +++ b/machines/modules/malobeo/microvm_host.nix @@ -85,5 +85,36 @@ in }; }; in builtins.listToAttrs (map mapperFunc cfg.deployHosts); + + systemd.services = builtins.foldl' (services: name: services // { + "microvm-update@${name}" = { + description = "Update MicroVMs automatically"; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + unitConfig.ConditionPathExists = "/var/lib/microvms/${name}"; + serviceConfig = { + LimitNOFILE = "1048576"; + Type = "oneshot"; + }; + path = with pkgs; [ nix git ]; + environment.HOME = config.users.users.root.home; + scriptArgs = "%i"; + script = '' + /run/current-system/sw/bin/microvm -Ru ${name} + ''; + }; + }) {} (cfg.deployHosts); + + systemd.timers = builtins.foldl' (timers: name: timers // { + "microvm-update-${name}" = { + wantedBy = [ "timers.target" ]; + timerConfig = { + Unit = "microvm-update@${name}.service"; + # three times per hour + OnCalendar = "*:0,20,40:00"; + Persistent = true; + }; + }; + }) {} (cfg.deployHosts); }; }