diff --git a/config/profiles/lxc.nix b/config/profiles/lxc.nix index 3cbac97..1cf49e3 100644 --- a/config/profiles/lxc.nix +++ b/config/profiles/lxc.nix @@ -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; diff --git a/lib/shinyflakes/default.nix b/lib/shinyflakes/default.nix index 6d5e2eb..dc3c20b 100644 --- a/lib/shinyflakes/default.nix +++ b/lib/shinyflakes/default.nix @@ -33,6 +33,7 @@ ({ ... }: { nixpkgs.overlays = [ self.overlays.kyouma self.overlays.otherPkgs ]; nixpkgs.hostPlatform.system = system; + kyouma.deployment.upgradeSystem.hostName = hostname; }) ]; }; diff --git a/modules/deployment/default.nix b/modules/deployment/default.nix index 161bc5d..5a29830 100644 --- a/modules/deployment/default.nix +++ b/modules/deployment/default.nix @@ -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" ]; diff --git a/pkgs/upgrade-system/upgrade-system.sh b/pkgs/upgrade-system/upgrade-system.sh index de09135..01338ba 100644 --- a/pkgs/upgrade-system/upgrade-system.sh +++ b/pkgs/upgrade-system/upgrade-system.sh @@ -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 -nixos-needsreboot +if [[ -n "$ALLOW_REBOOT" ]]; then + nixos-needsreboot +fi if [[ -n "$NO_DELAY" ]]; then delay="1"