modules/nixos: add update-host
This commit is contained in:
parent
fe8818dceb
commit
4f10f3d3c0
4 changed files with 63 additions and 31 deletions
modules/nixos/common
33
modules/nixos/common/update.bash
Normal file
33
modules/nixos/common/update.bash
Normal file
|
@ -0,0 +1,33 @@
|
|||
arch=$(uname -m)
|
||||
hostname=$(uname -n)
|
||||
p=$(curl -L https://buildbot.nix-community.org/nix-outputs/nix-community/infra/master/"$arch"-linux.host-"$hostname")
|
||||
|
||||
if [[ "$(readlink /run/booted-system)" == "$p" ]]; then
|
||||
return
|
||||
fi
|
||||
if [[ "$(readlink /run/current-system)" == "$p" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
nix-store --realise "$p"
|
||||
nix-env --profile /nix/var/nix/profiles/system --set "$p"
|
||||
|
||||
booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules} && cat /run/booted-system/kernel-params)"
|
||||
built="$(readlink "$p"/{initrd,kernel,kernel-modules} && cat "$p"/kernel-params)"
|
||||
if [[ $booted != "$built" ]]; then
|
||||
if [[ -e /run/current-system ]]; then
|
||||
echo "--- diff to current-system"
|
||||
nvd diff /run/current-system "$p"
|
||||
echo "---"
|
||||
fi
|
||||
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
|
||||
# don't use kexec if system is virtualized, reboots are fast enough
|
||||
if ! systemd-detect-virt -q; then
|
||||
kexec --load "$p"/kernel --initrd="$p"/initrd --append="$(cat "$p"/kernel-params) init=$p/init"
|
||||
fi
|
||||
if [[ ! -e /run/systemd/shutdown/scheduled ]]; then
|
||||
shutdown -r "+$(shuf -i 5-60 -n 1)"
|
||||
fi
|
||||
else
|
||||
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue