This commit is contained in:
emily 2024-05-14 11:10:01 +02:00
parent 48765e36f6
commit a939cd8d00
Signed by: emily
GPG key ID: F6F4C66207FCF995
4 changed files with 26 additions and 7 deletions

View file

@ -8,8 +8,13 @@ with lib; {
manageNetwork = true;
manageHostName = true;
};
kyouma.machine-type.virtual = true;
kyouma.deployment.tags = [ "pve-lxc" ];
kyouma ={
machine-type.virtual = true;
deployment = {
tags = [ "pve-lxc" ];
upgradeSystem.allowReboot = false;
};
};
networking.useDHCP = false;
networking.useHostResolvConf = false;

View file

@ -33,6 +33,7 @@
({ ... }: {
nixpkgs.overlays = [ self.overlays.kyouma self.overlays.otherPkgs ];
nixpkgs.hostPlatform.system = system;
kyouma.deployment.upgradeSystem.hostName = hostname;
})
];
};

View file

@ -25,6 +25,11 @@ in {
default = "main";
description = "branch to use for updates";
};
hostName = mkOption {
type = with types; nullOr str;
default = null;
description = "Set hostname";
};
noDelay = mkOption {
type = types.bool;
default = false;
@ -47,15 +52,15 @@ in {
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.upgrade-system}/bin/upgrade-system${optionalString cfg.allowReboot " --allow-reboot"} --branch ${cfg.branch}${
optionalString cfg.noDelay " --no-delay"
}";
optionalString (cfg.hostName != null) " --hostname ${cfg.hostName}"
}${optionalString cfg.noDelay " --no-delay"}";
};
};
systemd.timers.upgrade-system = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = if cfg.noDelay then "*-*-* *:*:00" else cfg.runFreq;
RandomizedDelaySec = if cfg.noDelay then "1s" else "1h";
RandomizedDelaySec = if cfg.noDelay then "1s" else "10m";
};
requires = [ "network-online.target" ];
after = [ "network-online.target" ];

View file

@ -4,6 +4,7 @@ set -euo pipefail
ALLOW_REBOOT=
BRANCH="main"
HOST_NAME=$HOSTNAME
NO_DELAY=
while [[ $# -gt 0 ]]; do
@ -17,6 +18,11 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
--hostname)
HOST_NAME="$2"
shift
shift
;;
--no-delay)
NO_DELAY=1
shift
@ -28,7 +34,7 @@ while [[ $# -gt 0 ]]; do
esac
done
HYDRA_URL="https://hydra.kyouma.net/job/nixfiles/${BRANCH}/nixosConfigurations.${HOSTNAME}/latest-finished"
HYDRA_URL="https://hydra.kyouma.net/job/nixfiles/${BRANCH}/nixosConfigurations.${HOST_NAME}/latest-finished"
NEW_STORE_PATH="$(curl --fail -s -L -H "Accept: application/json" "${HYDRA_URL}" | jq -r ".buildoutputs.out.path")"
@ -67,7 +73,9 @@ nix-env -p "/nix/var/nix/profiles/system" --set "${NEW_STORE_PATH}"
echo "Set new profile as boot target"
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
if [[ -n "$ALLOW_REBOOT" ]]; then
nixos-needsreboot
fi
if [[ -n "$NO_DELAY" ]]; then
delay="1"