nixos-config/common/services/autoupgrade.nix
2024-06-24 10:16:41 +02:00

54 lines
1.2 KiB
Nix

{pkgs, ...}: {
systemd.timers."nix-auto-upgrade" = {
enable = true;
wantedBy = ["timers.target"];
timerConfig = {
FixedRandomDelay = false;
RandomizedDelaySec = 0;
OnCalendar = "weekly";
Persistent = true;
Unit = "nix-auto-upgrade";
};
};
systemd.services."nix-auto-upgrade" = {
enable = true;
description = "NixOS Upgrade";
restartIfChanged = false;
unitConfig.X-StopOnRemoval = false;
after = ["network-online.target"];
wants = ["network-online.target"];
serviceConfig = {
Type = "oneshot";
User = "root";
WorkingDirectory = /etc/nixos/nixos-config;
};
path = with pkgs; [
coreutils
gnutar
xz.bin
gzip
gitMinimal
# curl
];
script = ''
set -eu
${pkgs.nixos-rebuild}/bin/nixos-rebuild boot -L --flake git+https://gitea.com/tasiaiso/nixos-config --upgrade
${pkgs.curl}/bin/curl \
-H "Title: NixOS upgrade done" \
-H "Priority: low" \
-H "Tags: low" \
-d "$(cat /etc/hostname): upgrade script done" \
ntfy.sh/tasiaiso_upgrades &> /dev/null # Please don't make me learn how to manage secrets
'';
};
}