lib/autoupdate: init, enable on mucbot
This commit is contained in:
parent
d678c69d23
commit
838ea568bc
|
@ -1,6 +1,7 @@
|
||||||
{ zentralwerk, config, pkgs, lib, tigger, ... }:
|
{ zentralwerk, config, pkgs, lib, tigger, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
c3d2.autoUpdate = true;
|
||||||
networking.hostName = "mucbot";
|
networking.hostName = "mucbot";
|
||||||
networking.interfaces.eth0.ipv4.addresses = [{
|
networking.interfaces.eth0.ipv4.addresses = [{
|
||||||
address = "172.20.73.27";
|
address = "172.20.73.27";
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
options.c3d2.autoUpdate = with lib; mkOption {
|
||||||
|
description = ''
|
||||||
|
Enables a timer that periodically checks hydra.hq.c3d2.de for the last build of the local system, and switches to it if it is different.
|
||||||
|
|
||||||
|
Also enables periodical /nix/store GC.
|
||||||
|
'';
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf config.c3d2.autoUpdate {
|
||||||
|
systemd.services.autoupdate = {
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
path = with pkgs; [ nixFlakes nettools curl jq ];
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
script = ''
|
||||||
|
OLD=$(readlink /run/current-system)
|
||||||
|
NEW=$(curl -sLH "Accept: application/json" https://hydra.hq.c3d2.de/job/c3d2/nix-config/x86_64-linux.$(hostname)/latest | jq -r .buildoutputs.out.path)
|
||||||
|
if [ -z "$NEW" ]; then
|
||||||
|
echo "Unable to obtain updated system"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$OLD" != "$NEW" ]; then
|
||||||
|
echo "New system available: $NEW"
|
||||||
|
# this should fetch the new system from the binary cache
|
||||||
|
nix build --no-link "$NEW"
|
||||||
|
# switch to the new system
|
||||||
|
"$NEW/bin/switch-to-configuration" switch
|
||||||
|
else
|
||||||
|
echo "No update required"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
# don't let the switch kill this service, aborting the switch
|
||||||
|
restartIfChanged = false;
|
||||||
|
unitConfig.X-StopOnRemoval = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.timers.autoupdate = {
|
||||||
|
partOf = [ "autoupdate.service" ];
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig.OnCalendar = "hourly";
|
||||||
|
};
|
||||||
|
|
||||||
|
nix.gc = {
|
||||||
|
automatic = true;
|
||||||
|
randomizedDelaySec = "6h";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ in {
|
||||||
./pi-sensors.nix
|
./pi-sensors.nix
|
||||||
./ceph-storage.nix
|
./ceph-storage.nix
|
||||||
./cache.nix
|
./cache.nix
|
||||||
|
./autoupdate.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
options.c3d2 = with lib;
|
options.c3d2 = with lib;
|
||||||
|
|
Loading…
Reference in New Issue