diff options
author | Franck Cuny <franck@fcuny.net> | 2024-12-08 13:05:18 -0800 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2024-12-08 15:35:17 -0800 |
commit | 44d47e517266cf82dea7a018301323de071ad12d (patch) | |
tree | 8ea37aa0bb8dbf5e9631cce05c66ac8b7b031887 /justfile | |
parent | add shell aliases for kubectl and kubie (diff) | |
download | world-44d47e517266cf82dea7a018301323de071ad12d.tar.gz |
add targets to create virtual machines
Diffstat (limited to 'justfile')
-rw-r--r-- | justfile | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/justfile b/justfile index b069c52..49d6f1d 100644 --- a/justfile +++ b/justfile @@ -1,3 +1,7 @@ +SSH_OPTIONS := "-o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + +nixaddr := "" + # update dependencies update-deps: nix flake update --commit-lock-file @@ -24,3 +28,37 @@ build-wildcat: switch-wildcat: nixos-rebuild switch --target-host fcuny.net --build-host fcuny.net --fast --use-remote-sudo --use-substitutes --flake .#wildcat + +vm-bootstrap: + #!/usr/bin/env bash + set -euxo pipefail + ssh {{SSH_OPTIONS}} root@{{nixaddr}} " \ + parted /dev/vda -- mklabel gpt; \ + parted /dev/vda -- mkpart primary 512MB 100%; \ + parted /dev/vda -- mkpart ESP fat32 1MB 512MB; \ + parted /dev/vda -- set 2 esp on; \ + sleep 1; \ + mkfs.ext4 -L nixos /dev/vda1; \ + mkfs.fat -F 32 -n boot /dev/vda2; \ + sleep 1; \ + mount /dev/disk/by-label/nixos /mnt; \ + mkdir -p /mnt/boot; \ + mount /dev/disk/by-label/boot /mnt/boot; \ + nixos-generate-config --root /mnt; \ + sed --in-place '/system\.stateVersion = .*/a \ + nix.extraOptions = \"experimental-features = nix-command flakes\";\n \ + services.openssh.enable = true;\n \ + services.openssh.settings.PasswordAuthentication = true;\n \ + services.openssh.settings.PermitRootLogin = \"yes\";\n \ + users.users.root.initialPassword = \"root\";\n \ + ' /mnt/etc/nixos/configuration.nix; \ + nixos-install --no-root-passwd && reboot; \ + " + +vm-copy: + #!/usr/bin/env bash + rsync -av -e 'ssh {{SSH_OPTIONS}}' \ + --exclude='.git/' \ + --exclude='result' \ + --rsync-path="sudo rsync" \ + $(dirname justfile)/ root@{{nixaddr}}:/nix-config |