config/pkgs/mk-nspawn-deployer/setup-nspawn.sh

45 lines
1.1 KiB
Bash
Raw Normal View History

2024-01-31 22:17:55 +01:00
#!/usr/bin/env bash
# TODO: assert correct system
NSPAWN=nixos-@hostname@
TARBALL=./"$NSPAWN".tar #"https://github.com/tfc/nspawn-nixos/releases/download/v1.0/nixos-system-x86_64-linux.tar.xz"
test $(id -u) -eq 0 || {
>&2 echo you must run this as root
exit 1
}
install_pkg() {
# TODO: use bash hashmaps to map from apt to other package managers
# * [x] apt
# * [ ] apk
# * [ ] pacman
# * [ ] dnf
DEBIAN_FRONTEND=noninteractive apt install -y "$@"
}
if ! >/dev/null command -v systemd-nspawn; then
# TODO: support more than ubuntu
install_pkg systemd-container
fi
machinectl remove "$NSPAWN" || true # TODO: interactive?
2024-02-25 21:26:02 +01:00
#machinectl pull-tar "https://github.com/tfc/nspawn-nixos/releases/download/v1.0/nixos-system-x86_64-linux.tar.xz" "$NSPAWN" --verify=no
2024-01-31 22:17:55 +01:00
machinectl import-tar "$TARBALL" "$NSPAWN"
# use host network
cat <<"EOF" > /etc/systemd/nspawn/"$NSPAWN".nspawn
[Network]
VirtualEthernet=no
EOF
machinectl enable "$NSPAWN"
machinectl start "$NSPAWN"
echo Setting root password...
machinectl shell "$NSPAWN" /usr/bin/env passwd
machinectl status "$NSPAWN"