nixos-config/common/services/autoupgrade.nix

56 lines
1.3 KiB
Nix
Raw Permalink Normal View History

2024-05-24 12:57:53 +02:00
{pkgs, ...}: {
2024-08-10 19:23:59 +02:00
# Sets a timer that will pull a new version
# of the flake and rebuild each week.
2024-06-07 18:06:59 +02:00
systemd.timers."nix-auto-upgrade" = {
2024-06-07 18:16:19 +02:00
enable = true;
2024-06-07 18:06:59 +02:00
wantedBy = ["timers.target"];
timerConfig = {
FixedRandomDelay = false;
RandomizedDelaySec = 0;
OnCalendar = "weekly";
Persistent = true;
Unit = "nix-auto-upgrade";
};
};
2024-05-24 13:43:30 +02:00
2024-06-07 18:06:59 +02:00
systemd.services."nix-auto-upgrade" = {
2024-06-07 18:16:19 +02:00
enable = true;
2024-06-07 18:27:05 +02:00
2024-08-10 19:23:59 +02:00
description = "Unattended Upgrade";
2024-06-07 18:27:05 +02:00
restartIfChanged = false;
unitConfig.X-StopOnRemoval = false;
after = ["network-online.target"];
wants = ["network-online.target"];
2024-06-07 18:06:59 +02:00
serviceConfig = {
Type = "oneshot";
User = "root";
WorkingDirectory = /etc/nixos/nixos-config;
};
2024-05-24 12:51:50 +02:00
2024-06-07 18:27:05 +02:00
path = with pkgs; [
coreutils
gnutar
xz.bin
gzip
gitMinimal
2024-08-10 19:23:59 +02:00
curl
2024-06-07 18:27:05 +02:00
];
2024-06-07 18:06:59 +02:00
script = ''
set -eu
2024-05-24 12:51:50 +02:00
${pkgs.nixos-rebuild}/bin/nixos-rebuild boot -L --flake git+https://git.vulpecula.zone/tasiaiso/nixos-config
2024-06-07 18:27:05 +02:00
2024-06-07 18:06:59 +02:00
${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
'';
2024-05-24 12:51:50 +02:00
};
2024-05-24 12:57:53 +02:00
}