Files
nix-config-ryan4yin/utils.nu
T
Ryan Yin 6180072646 chore: drop the KubeVirt guest bits
The k3s-test workers never ran (they were stuck waiting for volume
binding) and will be re-added as microVMs, so remove their KubeVirt
configs and everything that only existed for KubeVirt guests:

- hosts/k8s/k3s-test-1-worker-{1,2,3} and their outputs
- lib/genKubeVirtGuestModule.nix and lib/genK3sAgentModule.nix (the
  latter was only used by the workers)
- the KubeVirt image upload recipes (upload-vm, upload-idols,
  upload-k3s-test) and the kubevirt image package in the idols outputs
- refresh the docs; keep only accurate historical mentions (e.g. the
  restic backup path must stay as it is)
2026-09-21 17:24:40 +08:00

104 lines
3.3 KiB
Nu

def repeat-str [s: string, n: int] {
(1..$n | each { $s } | str join)
}
# ================= NixOS related =========================
export def nixos-switch [
name: string
mode: string
verbosity: string
] {
if $mode not-in ["switch" "boot"] {
error make { msg: $"unsupported deployment mode '($mode)'; expected switch or boot" }
}
if $verbosity not-in ["normal" "debug"] {
error make { msg: $"unsupported verbosity '($verbosity)'; expected normal or debug" }
}
print $"nixos-switch '($name)' in '($mode)' mode with '($verbosity)' verbosity..."
print (repeat-str "=" 50)
if $verbosity == "debug" {
# show details via nix-output-monitor
nom build $".#nixosConfigurations.($name).config.system.build.toplevel" --accept-flake-config --show-trace --verbose
nixos-rebuild $mode --sudo --flake $".#($name)" --accept-flake-config --show-trace --verbose
} else {
nixos-rebuild $mode --sudo --flake $".#($name)" --accept-flake-config
}
}
# ====================== Misc =============================
export def make-editable [
path: string
] {
print (repeat-str "=" 50)
let tmpdir = (mktemp -d)
rsync -avz --copy-links $"($path)/" $tmpdir
rsync -avz --copy-links --chmod=D2755,F744 $"($tmpdir)/" $path
}
# ================= macOS related =========================
export def darwin-build [
name: string
verbosity: string
] {
print $"darwin-build '($name)' with '($verbosity)' verbosity..."
print (repeat-str "=" 50)
let target = $".#darwinConfigurations.($name).system"
if "debug" == $verbosity {
nom build $target --extra-experimental-features "nix-command flakes" --show-trace --verbose
} else {
nix build $target --extra-experimental-features "nix-command flakes"
}
}
export def darwin-switch [
name: string
verbosity: string
] {
print $"darwin-switch '($name)' with '($verbosity)' verbosity..."
print (repeat-str "=" 50)
if "debug" == $verbosity {
sudo -E ./result/sw/bin/darwin-rebuild switch --flake $".#($name)" --show-trace --verbose
} else {
sudo -E ./result/sw/bin/darwin-rebuild switch --flake $".#($name)"
}
}
export def darwin-rollback [] {
./result/sw/bin/darwin-rebuild --rollback
}
# ==================== Virtual Machines related =====================
# Build and upload a VM image
export def upload-vm [
name: string
size: string
verbosity: string
] {
print $"upload-vm '($name)' with '($verbosity)' verbosity..."
print (repeat-str "=" 50)
let target = $".#($name)"
if "debug" == $verbosity {
nom build $target --show-trace --verbose
} else {
nix build $target
}
# Write the freshly built image straight into the VM's own root disk (a
# DataVolume with `source: upload` in k8s-gitops). CDI only accepts an
# upload into a DataVolume, and this way the disk is populated once, on the
# node the VM is pinned to.
#
# Requires the CDI upload proxy to be reachable from here; it is exposed
# as a NodePort by the cluster.
let uploadProxyUrl = "https://192.168.5.181:30443"
let image = (glob result/nixos-image-*.qcow2 | first)
virtctl image-upload dv $"($name)-disk" -n vms --size $size --image-path $image --uploadproxy-url $uploadProxyUrl --insecure
}