aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/run-firecracker-vm
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/run-firecracker-vm')
-rw-r--r--pkgs/run-firecracker-vm/default.nix24
1 files changed, 22 insertions, 2 deletions
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix
index 11dfa46..23507b2 100644
--- a/pkgs/run-firecracker-vm/default.nix
+++ b/pkgs/run-firecracker-vm/default.nix
@@ -550,7 +550,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ ''
# restarts the guest on reboot (leave it with poweroff instead), and
# takes no commas in --store and --home.
set -efu
- export PATH=${lib.makeBinPath [ pkgs.coreutils pkgs.e2fsprogs pkgs.findutils pkgs.gnugrep pkgs.gnused pkgs.jq pkgs.openssh pkgs.util-linux pkgs.firecracker pkgs.cloud-hypervisor pkgs.unpfs ]}
+ export PATH=${lib.makeBinPath [ pkgs.coreutils pkgs.e2fsprogs pkgs.findutils pkgs.gnugrep pkgs.gnused pkgs.jq pkgs.openssh pkgs.util-linux pkgs.firecracker pkgs.cloud-hypervisor pkgs.git pkgs.socat pkgs.unpfs ]}
usage() {
echo "usage: $0 [--store FILE] [--store-size SIZE] [--home FILE] [--home-size SIZE] [--mem-size MIB] [--nixpkgs DIR] [--nixpkgs-cache MODE] [--egress LIST] [--name NAME] [--vcpus N] [--secret NAME=FILE]... [--vmm firecracker|cloud-hypervisor]"
@@ -566,6 +566,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ ''
vcpus=2
vmm=firecracker
nixpkgs=${lib.escapeShellArg (toString pkgs.path)}
+ nixpkgs_cache=
nix_opt= # the last option that's only for a guest with nix
secrets=() # NAME=FILE, as given
while test $# -gt 0; do
@@ -577,7 +578,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ ''
--home-size) home_size=$2; shift 2 ;;
--mem-size) mem_size=$2; shift 2 ;;
--nixpkgs) nixpkgs=$2; nix_opt=$1; shift 2 ;;
- --nixpkgs-cache) args="$args fc.9p566=cache=$2"; nix_opt=$1; shift 2 ;;
+ --nixpkgs-cache) args="$args fc.9p566=cache=$2"; nixpkgs_cache=$2; nix_opt=$1; shift 2 ;;
--egress) egress=$2; shift 2 ;;
--name) name=$2; shift 2 ;;
--vcpus) vcpus=$2; shift 2 ;;
@@ -831,6 +832,25 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ ''
${lib.optionalString nix ''
serve 565 /nix/store
serve 566 "$nixpkgs"
+ # With a cache mode for nixpkgs, the guest doesn't see changes to it
+ # (see fc-drop-caches in layers/nix.nix). When it's a Git checkout
+ # whose commit changes (checkout, pull, rebase), the guest gets told
+ # to drop its caches: a connection to its vsock port 1235 (on the
+ # socket uds_path, with CONNECT PORT). Changes without a commit
+ # need fc-drop-caches by hand.
+ if test -n "$nixpkgs_cache" && git -C "$nixpkgs" rev-parse HEAD > /dev/null 2>&1; then
+ (
+ head=$(git -C "$nixpkgs" rev-parse HEAD)
+ while sleep 5; do
+ new=$(git -C "$nixpkgs" rev-parse HEAD 2>/dev/null) || continue
+ if test "$new" != "$head"; then
+ printf 'CONNECT 1235\n' | socat -t 10 - UNIX-CONNECT:"$tmp/vsock\:" > /dev/null 2>&1 || :
+ head=$new
+ fi
+ done
+ ) &
+ servers="$servers $!"
+ fi
''}
trap 'kill $servers; rm -rf "$tmp"; if test -n "$vm"; then : > "$vm"; if test -w "$vm.name"; then : > "$vm.name"; fi; fi' EXIT
for port in $ports; do