autoupdate: set up a systemd timer

This commit is contained in:
2026-05-15 15:59:31 +02:00
parent 9b15ec3f9b
commit dcca37ab19
4 changed files with 111 additions and 3 deletions
+2 -1
View File
@@ -22,7 +22,8 @@
../../hostsModules/laptop/nixos/disk.nix ../../hostsModules/laptop/nixos/disk.nix
../../modules/nixos/printer.nix ../../modules/nixos/printer.nix
../../hostsModules/laptop/nixos/ollama.nix # llm config ../../hostsModules/laptop/nixos/ollama.nix # llm config
../../modules/nixos/mullvad.nix # vpn config ../../modules/nixos/mullvad.nix # vpn config
../../hostsModules/laptop/nixos/autoUpdate.nix # auto update the flakes. Handles notification via libnotify and matrix-commander-rs
]; ];
-2
View File
@@ -71,8 +71,6 @@
# checks if matrix-commander-rs is installed and logged in # checks if matrix-commander-rs is installed and logged in
(pkgs.callPackage ../../hostsModules/laptop/scripts/checkMatrix.nix {}) (pkgs.callPackage ../../hostsModules/laptop/scripts/checkMatrix.nix {})
# autoupdate the flake and send notification to system and to matrix
(pkgs.callPackage ../../hostsModules/laptop/scripts/autoUpdate.nix {})
(pkgs.callPackage ../../modules/scripts/weather.nix {}) (pkgs.callPackage ../../modules/scripts/weather.nix {})
(pkgs.callPackage ../../modules/scripts/wallpaper.nix {}) (pkgs.callPackage ../../modules/scripts/wallpaper.nix {})
+47
View File
@@ -0,0 +1,47 @@
{ pkgs, ... }:
{
# Ensure your script is available system-wide
environment.systemPackages = [
(pkgs.callPackage ../scripts/autoUpdate.nix {})
];
users.users.tomasr = {
linger = true; # lingering is required
};
systemd.user.services.custom-autoupdate = {
description = "NixOS flake auto update";
serviceConfig = {
Type = "oneshot";
ExecStart = "/run/current-system/sw/bin/custom-autoupdate";
# safety for long rebuilds
TimeoutStartSec = "45min";
TimeoutStopSec = "10min";
# avoid overlap
RemainAfterExit = true;
# tweaks that should make the system run normally during the rebuilds
Nice = 10;
IOSchedulingClass = "best-effort";
IOSchedulingPriority = 7;
};
};
# Systemd USER timer
systemd.user.timers.custom-autoupdate = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "Fri *-*-* 20:00:00"; # runs friday night. If for whatever reason something breaks. I have whole week-end to fix it.
Persistent = true; # if it happens during shutted down
# avoids thundering herd on boot
RandomizedDelaySec = "2h";
};
};
}
+62
View File
@@ -0,0 +1,62 @@
{ pkgs, ... }:
{
# Ensure your script is available system-wide
environment.systemPackages = [
(pkgs.callPackage ./custom-autoupdate.nix {})
];
# ----------------------------
# 🔥 Enable lingering for user services (IMPORTANT)
# ----------------------------
users.users.tomasr = {
isNormalUser = true;
# other config...
linger = true; # <-- declarative equivalent of `loginctl enable-linger`
};
# ----------------------------
# ✅ 2. Systemd USER service
# ----------------------------
systemd.user.services.custom-autoupdate = {
description = "NixOS flake auto update";
serviceConfig = {
Type = "oneshot";
ExecStart = "/run/current-system/sw/bin/custom-autoupdate";
# safety for long rebuilds
TimeoutStartSec = "45min";
TimeoutStopSec = "10min";
# avoid overlap
RemainAfterExit = true;
# 🔥 recommended reliability tweaks
Nice = 10;
IOSchedulingClass = "best-effort";
IOSchedulingPriority = 7;
};
};
# ----------------------------
# ⏱️ 3. Systemd USER timer
# ----------------------------
systemd.user.timers.custom-autoupdate = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "10min"; # run after boot
OnUnitActiveSec = "6h"; # every 6 hours
# 🔥 ensures missed runs after shutdown happen
Persistent = true;
# avoids thundering herd on boot
RandomizedDelaySec = "30min";
};
};
}