proxmox/nixprox.sh: prepare the nixos

This commit is contained in:
Astro 2021-09-10 22:06:32 +02:00
parent 2ad513da4a
commit 662d4f9efa
1 changed files with 53 additions and 1 deletions

54
proxmox/nixprox.sh Normal file → Executable file
View File

@ -24,8 +24,60 @@ NAME=$2
# net vlan tag 5: c3d2 (with dhcp). request a static IP address with Astro and move to 3 (serv).
pct create $ID $TEMPLATE --hostname $NAME --ostype unmanaged --arch amd64 --net0 name=eth0,bridge=vmbr0,tag=5 --storage vms-slow --memory 4096 --cmode shell --features nesting=1
# this boots the current profile
echo "lxc.init.cmd: /sw/bin/init" >> /etc/pve/lxc/$ID.conf
echo "lxc.init.cmd: /init" >> /etc/pve/lxc/$ID.conf
echo Starting $ID
pct start $ID
run() {
lxc-attach -n $ID -- /run/current-system/sw/bin/sh -c ". /etc/profile && $*"
}
echo -n Wait for container to ship
while S=$(run systemctl is-system-running --wait 2> /dev/null); [ "$S" != running ] && [ "$S" != degraded ]; do
sleep 1
echo -n .
done
echo " $S"
echo Preparing sensible defaults
run "cat > /etc/nixos/configuration.nix" <<EOF
{ pkgs, ... }:
{
boot.isContainer = true;
boot.loader.initScript.enable = true;
networking.hostName = "$NAME";
nix = {
useSandbox = false;
extraOptions = "experimental-features = nix-command flakes";
# package = pkgs.nixFlakes;
};
networking.useDHCP = false;
networking.interfaces.eth0.useDHCP = true;
networking.firewall.allowedTCPPorts = [ 22 ];
services.openssh.enable = true;
environment.systemPackages = with pkgs; [ vim git ];
}
EOF
# Disable Nix sandbox
run rm /etc/nix/nix.conf
run cp /etc/static/nix/nix.conf /etc/nix/nix.conf
run chmod u+w /etc/nix/nix.conf
run sed \
-e '"s/sandbox = true/sandbox = false/"' \
-e '"s/max-jobs = auto/max-jobs = 2/"' \
-i /etc/nix/nix.conf
run systemctl restart nix-daemon
# Use fast upstream
echo -n IPv4
while ! run ip r a 0/0 via 172.22.99.4 metric 1 2> /dev/null; do
sleep 1
echo -n .
done
echo " fast"
# Fixup init path to use new profile
sed -e "s#lxc.init.cmd: /init#lxc.init.cmd: /sbin/init#" -i /etc/pve/lxc/$ID.conf
# Rebuild
run nixos-rebuild switch