Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules/nixos/common/update: switch to apply script, refactor #1562

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions modules/nixos/common/update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,36 @@ if [[ "$(readlink /run/current-system)" == "$p" ]]; then
exit 0
fi

nix-store --option narinfo-cache-negative-ttl 0 --realise "$p"
nix-env --profile /nix/var/nix/profiles/system --set "$p"
nix-store \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add this code eventually to buildbot-nix in its current form (also with support for both macos & NixOS).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macos support is complicated, nix-darwin doesn't have something like restartIfChanged for services and there isn't a way of monitoring failed services like we have on linux. I was planning to just keep using push deployments for darwin but switching from actions to effects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to come up with a common interface for both? Otherwise deploy tools all have to take care of those differences.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand what a "common interface" means here if it isn't a deployment tool?

--option narinfo-cache-negative-ttl 0 \
--add-root /run/inbound-system \
--realise "$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
booted="$(
readlink /run/booted-system/{initrd,kernel,kernel-modules} &&
cat /run/booted-system/kernel-params
)"

inbound="$(
readlink /run/inbound-system/{initrd,kernel,kernel-modules} &&
cat /run/inbound-system/kernel-params
)"

if [[ $booted != "$inbound" ]]; then
echo "--- diff to current-system"
nvd diff /run/current-system /run/inbound-system
echo "---"
/run/inbound-system/bin/apply 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"
kexec \
--load /run/inbound-system/kernel \
--initrd=/run/inbound-system/initrd \
--append="$(cat /run/inbound-system/kernel-params) init=/run/inbound-system/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
/run/inbound-system/bin/apply switch
fi