aboutsummaryrefslogtreecommitdiffstats
path: root/layers/switch.nix
blob: 458026f1e8b78ad912dcc06cf240dbe5df715a10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Switching a running guest to a new build of its system, instead of
# rebooting it, for a faster development loop.  Not for production: a
# switched guest runs what it didn't boot (/run/current-system isn't
# /run/booted-system), from the host's store; reboot it with the new run
# script, whose images have the new system.  Needs layers/nix.nix (the
# guest sees the host's store, where the new system gets built).  Small,
# so better imported by another layer:
#   imports = [ /path/to/rigs/layers/switch.nix ];
# Then, on the host, with the same arguments as the running guest's build:
#   sys=$(nix-build --no-out-link pkgs/run-rig -A toplevel ...)
#   ssh root@VM $sys/bin/switch-to-configuration test
# A store path that the guest looked for before the host had it stays
# missing in the guest's store (the overlay remembers), until the guest
# drops its caches: echo 2 > /proc/sys/vm/drop_caches (takes seconds).
# What needs a reboot anyway: the kernel, its command line, the initrd,
# Firecracker's configuration (memory, vCPUs), new secrets, and layers
# added or removed (the store's overlay would change).
{ config, ... }:
{
  system.switch.enable = true;
  assertions = [{
    assertion = config.rig.nix;
    message = "layers/switch.nix needs layers/nix.nix, for the host's store.";
  }];
}