modules/microvm-host: add `update-microvm` command
This commit is contained in:
parent
ac2a9e2246
commit
5a6d495f71
|
@ -67,5 +67,43 @@
|
|||
"microvm.cachix.org-1:oXnBc6hRE3eX5rSYdRyMYXnfzcCxC7yKPTbZXALsqys="
|
||||
];
|
||||
};
|
||||
|
||||
environment.systemPackages = [ (
|
||||
# Provide a manual updating script that fetches the latest
|
||||
# updated+built system from Hydra
|
||||
pkgs.writeScriptBin "update-microvm" ''
|
||||
#! ${pkgs.runtimeShell} -e
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
NAMES="$(ls -1 /var/lib/microvms)"
|
||||
else
|
||||
NAMES="$@"
|
||||
fi
|
||||
|
||||
for NAME in $NAMES; do
|
||||
echo MicroVM $NAME
|
||||
cd /var/lib/microvms/$NAME
|
||||
if [ "$(cat flake)" = "git+https://gitea.c3d2.de/c3d2/nix-config?ref=flake-update" ]; then
|
||||
NEW=$(curl -sLH "Accept: application/json" https://hydra.hq.c3d2.de/job/c3d2/nix-config/$NAME/latest | ${pkgs.jq}/bin/jq -r .buildoutputs.out.path)
|
||||
nix copy --from https://hydra.hq.c3d2.de $NEW
|
||||
|
||||
if [ -e booted ]; then
|
||||
nix store diff-closures $(readlink booted) $NEW
|
||||
else
|
||||
echo "NOT BOOTED?"
|
||||
fi
|
||||
if [ "$(readlink current)" != $NEW ]; then
|
||||
rm -f old
|
||||
mv current old
|
||||
ln -s $NEW current
|
||||
fi
|
||||
fi
|
||||
|
||||
echo Run at your own peril:
|
||||
echo systemctl restart microvm@$NAME
|
||||
echo
|
||||
done
|
||||
''
|
||||
) ];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue