HASH a15645c7851b
DATE 2025-05-12
SUBJECT infra: pooknet-provision script init
FILES 6 CHANGED
HASH a15645c7851b
DATE 2025-05-12
SUBJECT infra: pooknet-provision script init
FILES 6 CHANGED
┌─ hosts/ooksdesk/default.nix ───────────────────────────────────────────────┐
│ diff --git a/hosts/ooksdesk/default.nix b/hosts/ooksdesk/default.nix │
│ index 1807fb2..ce8ce01 100644 │
│ --- a/hosts/ooksdesk/default.nix │
│ +++ b/hosts/ooksdesk/default.nix │
│ @@ -24,7 +24,7 @@ │
│ workstation = { │
│ environment = "hyprland"; │
│ theme = "minimal"; │
│ - profiles = ["creative" "virtualization" "gaming" "media" "communication" "p │
│ roductivity"]; │
│ + profiles = ["creative" "virtualization" "gaming" "media" "communication" "p │
│ roductivity" "infra"]; │
│ default = { │
│ browser = "zen"; │
│ terminal = "foot"; │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ hosts/ooksdesk/default.nix ─────────┐
│ diff --git a/hosts/ooksdesk/default.nix b/ho │
│ sts/ooksdesk/default.nix │
│ index 1807fb2..ce8ce01 100644 │
│ --- a/hosts/ooksdesk/default.nix │
│ +++ b/hosts/ooksdesk/default.nix │
│ @@ -24,7 +24,7 @@ │
│ workstation = { │
│ environment = "hyprland"; │
│ theme = "minimal"; │
│ - profiles = ["creative" "virtualizatio │
│ n" "gaming" "media" "communication" "product │
│ ivity"]; │
│ + profiles = ["creative" "virtualizatio │
│ n" "gaming" "media" "communication" "product │
│ ivity" "infra"]; │
│ default = { │
│ browser = "zen"; │
│ terminal = "foot"; │
└──────────────────────────────────────────────┘
┌─ modules/home/console/tools/default.nix ───────────────────────────────────┐
│ diff --git a/modules/home/console/tools/default.nix b/modules/home/console/tools/d │
│ efault.nix │
│ index d79fdcf..63c742c 100644 │
│ --- a/modules/home/console/tools/default.nix │
│ +++ b/modules/home/console/tools/default.nix │
│ @@ -15,5 +15,6 @@ │
│ ./nixIndex.nix │
│ ./multiplexer │
│ ./editor │
│ + ./infra │
│ ]; │
│ } │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...ome/console/tools/default.nix ───┐
│ diff --git a/modules/home/console/tools/defa │
│ ult.nix b/modules/home/console/tools/default │
│ .nix │
│ index d79fdcf..63c742c 100644 │
│ --- a/modules/home/console/tools/default.nix │
│ +++ b/modules/home/console/tools/default.nix │
│ @@ -15,5 +15,6 @@ │
│ ./nixIndex.nix │
│ ./multiplexer │
│ ./editor │
│ + ./infra │
│ ]; │
│ } │
└──────────────────────────────────────────────┘
┌─ modules/home/console/tools/infra/default.nix ─────────────────────────────┐
│ diff --git a/modules/home/console/tools/infra/default.nix b/modules/home/console/t │
│ ools/infra/default.nix │
│ new file mode 100644 │
│ index 0000000..852790c │
│ --- /dev/null │
│ +++ b/modules/home/console/tools/infra/default.nix │
│ @@ -0,0 +1,5 @@ │
│ +{ │
│ + imports = [ │
│ + ./ooknet-provision.nix │
│ + ]; │
│ +} │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...nsole/tools/infra/default.nix ───┐
│ diff --git a/modules/home/console/tools/infr │
│ a/default.nix b/modules/home/console/tools/i │
│ nfra/default.nix │
│ new file mode 100644 │
│ index 0000000..852790c │
│ --- /dev/null │
│ +++ b/modules/home/console/tools/infra/defau │
│ lt.nix │
│ @@ -0,0 +1,5 @@ │
│ +{ │
│ + imports = [ │
│ + ./ooknet-provision.nix │
│ + ]; │
│ +} │
└──────────────────────────────────────────────┘
┌─ modules/home/console/tools/infra/ooknet-provision.nix ────────────────────┐
│ diff --git a/modules/home/console/tools/infra/ooknet-provision.nix b/modules/home/ │
│ console/tools/infra/ooknet-provision.nix │
│ new file mode 100644 │
│ index 0000000..f09f5cd │
│ --- /dev/null │
│ +++ b/modules/home/console/tools/infra/ooknet-provision.nix │
│ @@ -0,0 +1,313 @@ │
│ +{ │
│ + osConfig, │
│ + config, │
│ + lib, │
│ + pkgs, │
│ + ... │
│ +}: let │
│ + inherit (lib) mkIf elem; │
│ + inherit (builtins) attrValues; │
│ + inherit (osConfig.ooknet.workstation) profiles; │
│ +in { │
│ + config = mkIf (elem "infra" profiles) { │
│ + home.packages = [ │
│ + (pkgs.writeShellApplication { │
│ + name = "ooknet-provision"; │
│ + runtimeInputs = attrValues { │
│ + inherit │
│ + (pkgs) │
│ + gum │
│ + jq │
│ + coreutils │
│ + nixos-anywhere │
│ + ; │
│ + # I could add 1password here but it is included in all workstation conf │
│ igurations by default │
│ + }; │
│ + # wrapper around nixos-anywhere with 1password integration for fetching h │
│ ostkeys for │
│ + # secret decryption. │
│ + # this script is not intended for general use, but specifically tailored │
│ to my needs. │
│ + text = '' │
│ + #TODO: │
│ + # - add options for install-key/target user │
│ + # - add log file output │
│ + # - write this in go │
│ + set -euo pipefail │
│ + │
│ + hostname="" │
│ + targetIP="" │
│ + targetUser="root" │
│ + localHostConfigDir="" │
│ + installKey=${config.home.homeDirectory}/.ssh/install-key │
│ + additionalFlags="" │
│ + verbose="" │
│ + temp=$(mktemp -d) │
│ + │
│ + cleanup() { │
│ + find "$temp" -type f -exec shred -uzn 3 {} \; │
│ + rm -rf "$temp" │
│ + } │
│ + │
│ + helpCmd() { │
│ + cat <<USAGE │
│ + │
│ + Usage: ooknet-provision [target hostname] [target ip] │
│ + │
│ + Options: │
│ + │
│ + * -v, --verbose │
│ + Enable verbose output │
│ + * -o, --extra-options │
│ + Pass additional options to nixos-anywhere │
│ + * -h, --help │
│ + Print help │
│ + * -d, --host-config-dir │
│ + Specify the location of the target hosts confuration location where h │
│ ardware.nix will be written. │
│ + Defaults to "<FLAKE>/hosts/<hostname>" │
│ + USAGE │
│ + } │
│ + │
│ + log() { │
│ + local type="$1" │
│ + local message="$2" │
│ + │
│ + if [ "$type" = "verbose" ]; then │
│ + if [ -n "$verbose" ]; then │
│ + gum log --structured --level debug "$message" │
│ + fi │
│ + return │
│ + fi │
│ + if [ "$type" = "abort" ]; then │
│ + gum log --structured --level error "$message" │
│ + exit 1 │
│ + else │
│ + gum log --structured --level "$type" "$message" │
│ + fi │
│ + } │
│ + │
│ + arguments() { │
│ + while [[ $# -gt 0 ]]; do │
│ + case "$1" in │
│ + -h | --help) │
│ + helpCmd │
│ + exit 0 │
│ + ;; │
│ + -v | --verbose) │
│ + verbose="y" │
│ + shift │
│ + ;; │
│ + -o | --extra-options) │
│ + if [[ -z "$2" || "$2" == -* ]]; then │
│ + log abort "Missing value for -o, --extra-options" │
│ + fi │
│ + additionalFlags="$2" │
│ + shift 2 │
│ + ;; │
│ + -d | --host-config-dir) │
│ + if [[ -z "$2" || "$2" == -* ]]; then │
│ + log abort "Missing value for -d, --host-config-dir" │
│ + fi │
│ + localHostConfigDir="$2" │
│ + shift 2 │
│ + ;; │
│ + -*) │
│ + log abort "Unknown option: $1" │
│ + ;; │
│ + *) │
│ + if [ -z "$hostname" ]; then │
│ + hostname="$1" │
│ + elif [ -z "$targetIP" ]; then │
│ + targetIP="$1" │
│ + else │
│ + log abort "Too many positional arguments: $1. Expected [hostnam │
│ e] [targetIP]" │
│ + fi │
│ + shift │
│ + ;; │
│ + esac │
│ + done │
│ + if [ -z "$hostname" ]; then │
│ + log abort "Target hostname is required. Use: provision <hostname> < │
│ targetIP> [options]" │
│ + fi │
│ + │
│ + if [ -z "$targetIP" ]; then │
│ + log abort "Target IP address is required. Use: provision <hostname> │
│ <targetIP> [options]" │
│ + fi │
│ + │
│ + if [ -z "$localHostConfigDir" ]; then │
│ + if [ -n "$FLAKE" ]; then │
│ + localHostConfigDir="$FLAKE/hosts/$hostname" │
│ + log verbose "Defaulting local host config directory to: $localHos │
│ tConfigDir" │
│ + else │
│ + log verbose "FLAKE variable not set; cannot form default for loca │
│ lHostConfigDir." │
│ + fi │
│ + else │
│ + log verbose "Using specified local config directory $localHostConfi │
│ gDir" │
│ + fi │
│ + } │
│ + │
│ + preChecks() { │
│ + # we need to authenticate early │
│ + log info "Authenicating with 1Password" │
│ + if ! op account get >/dev/null; then │
│ + log abort "Failed to authenicate with 1Password..." │
│ + fi │
│ + │
│ + log info "Running pre-installation checks..." │
│ + │
│ + # have you set $FLAKE │
│ + log verbose "Checking FLAKE variable is set..." │
│ + if [ -z "$FLAKE" ]; then │
│ + log abort "FLAKE variable unset, please set the FLAKE variable to t │
│ he root location of the ooknet flake" │
│ + else │
│ + log verbose "FLAKE location found..." │
│ + fi │
│ + │
│ + # is there a valid nixosConfigurations.$hostname flake output │
│ + log verbose "Checking for nixosConfiguration.$hostname" │
│ + if ! nix flake show "$FLAKE" \ │
│ + --json \ │
│ + --no-update-lock-file \ │
│ + --quiet \ │
│ + --all-systems | │
│ + jq -e --arg hn "$hostname" '.nixosConfigurations[$hn]'; then │
│ + log abort "nixosConfigurations.$hostname not found..." │
│ + else │
│ + log verbose "nixosConfigurations.$hostname found..." │
│ + fi │
│ + │
│ + # ensure $hostname has valid configuration directory │
│ + # we could make this more robust │
│ + log verbose "Checking for $hostname configuration file" │
│ + if [ ! -d "$localHostConfigDir" ]; then │
│ + log abort "Host confguration directory: '$localHostConfigDir' (for │
│ hardware.nix) does not exist..." │
│ + else │
│ + log verbose "Host configuration directory: '$localHostConfigDir' fo │
│ und..." │
│ + fi │
│ + │
│ + # does the configuration evaluate │
│ + log verbose "Evaluting configuration" │
│ + if ! nix eval --raw "$FLAKE"#nixosConfigurations."$hostname".config.s │
│ ystem.build.toplevel; then │
│ + log abort "nixosConfigurations.$hostname.config.system.build.toplev │
│ el failed to evaluate" │
│ + else │
│ + log verbose "nixosConfigurations.$hostname.config.system.build.topl │
│ evel successfully evaluated..." │
│ + fi │
│ + │
│ + # for jq arg (there is a better way to do this...) │
│ + local target_title="$hostname-hostkey" │
│ + │
│ + # have you setup a hostkey in 1Password │
│ + log verbose "Checking if hostkey '$target_title' is available in 1Pas │
│ sword" │
│ + if ! op item list --vault ooknet --tags hostkey --format=json | │
│ + jq -e --arg title_to_find "$target_title" 'any(.[]; .title == $titl │
│ e_to_find)'; then │
│ + log abort "Hostkey '$target_title' not found in vault 'ooknet' with │
│ tag 'hostkey'. Ensure $hostname hostkey has been defined in 1Password" │
│ + else │
│ + log verbose "Hostkey found..." │
│ + fi │
│ + │
│ + log verbose "Checking for install key" │
│ + │
│ + if [ ! -f "$installKey" ]; then │
│ + log abort "Install key not found at $installKey" │
│ + else │
│ + log verbose "Install key found..." │
│ + fi │
│ + │
│ + local ssh_output │
│ + if ! ssh_output=$(ssh \ │
│ + -F /dev/null \ │
│ + -l "$targetUser" \ │
│ + -i "$installKey" \ │
│ + -o BatchMode=yes \ │
│ + -o StrictHostKeyChecking=no \ │
│ + -o ConnectTimeout=30 \ │
│ + "$targetIP" \ │
│ + true 2>&1); then │
│ + log error "$ssh_output" │
│ + log abort "$0 SSH connection to $targetUser@$targetIP cannot be est │
│ ablished at this time..." │
│ + else │
│ + log info "SSH connection successful..." │
│ + fi │
│ + log info "All checks passed" │
│ + } │
│ + │
│ + getHostKey() { │
│ + log info "Retrieving Host keys from 1Password vault..." │
│ + install -d -m755 "$temp/etc/ssh" │
│ + if ! op read \ │
│ + --out-file "$temp/etc/ssh/ssh_host_ed25519_key" \ │
│ + --file-mode 0600 \ │
│ + "op://ooknet/$hostname-hostkey/private key"; then │
│ + log abort "Failed to retrieve private host key" │
│ + fi │
│ + if ! op read \ │
│ + --out-file "$temp/etc/ssh/ssh_host_ed25519_key.pub" \ │
│ + --file-mode 0644 \ │
│ + "op://ooknet/$hostname-hostkey/public key"; then │
│ + log abort "Failed to retrieve public host key" │
│ + fi │
│ + } │
│ + │
│ + deploySystem() { │
│ + log info "Running nixos-anywhere..." │
│ + │
│ + if [ -z "$localHostConfigDir" ]; then │
│ + log abort "localHostConfigDir is not set. This is a script bug or w │
│ as not defaulted correctly" │
│ + fi │
│ + │
│ + local hardware_config_path="$localHostConfigDir/hardware.nix" │
│ + nixos_anywhere_cmd=( │
│ + "nixos-anywhere" │
│ + "--generate-hardware-config" "nixos-generate-config" "$hardware_con │
│ fig_path" │
│ + "--extra-files" "$temp" │
│ + "--flake" "$FLAKE#$hostname" │
│ + "--target-host" "$targetUser@$targetIP" │
│ + "-i" "$installKey" │
│ + ) │
│ + log verbose "Base command: nixos-anywhere with standard options" │
│ + │
│ + if [ -n "$additionalFlags" ]; then │
│ + log verbose "Adding additional flags: $additionalFlags" │
│ + │
│ + declare -a extra_args │
│ + read -r -a extra_args <<<"$additionalFlags" │
│ + │
│ + for arg in "''${extra_args[@]}"; do │
│ + nixos_anywhere_cmd+=("$arg") │
│ + done │
│ + │
│ + log verbose "Command array now has ''${#nixos_anywhere_cmd[@]} elem │
│ ents. Full command: ''${nixos_anywhere_cmd[*]}" │
│ + fi │
│ + │
│ + if [ -n "$verbose" ]; then │
│ + log verbose "Executing: ''${nixos_anywhere_cmd[*]}" │
│ + fi │
│ + │
│ + "''${nixos_anywhere_cmd[@]}" │
│ + │
│ + local exit_code=$? │
│ + if [ $exit_code -eq 0 ]; then │
│ + log info "nixos-anywhere completed successfully" │
│ + else │
│ + log error "nixos-anywhere failed with exit code $exit_code" │
│ + fi │
│ + } │
│ + │
│ + main() { │
│ + arguments "$@" │
│ + preChecks │
│ + getHostKey │
│ + deploySystem │
│ + log info "Installation completed!" │
│ + } │
│ + │
│ + if [ "$#" -lt 2 ]; then │
│ + helpCmd │
│ + fi │
│ + │
│ + trap cleanup EXIT │
│ + main "$@" │
│ + │
│ + ''; │
│ + }) │
│ + ]; │
│ + }; │
│ +} │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...ls/infra/ooknet-provision.nix ───┐
│ diff --git a/modules/home/console/tools/infr │
│ a/ooknet-provision.nix b/modules/home/consol │
│ e/tools/infra/ooknet-provision.nix │
│ new file mode 100644 │
│ index 0000000..f09f5cd │
│ --- /dev/null │
│ +++ b/modules/home/console/tools/infra/ookne │
│ t-provision.nix │
│ @@ -0,0 +1,313 @@ │
│ +{ │
│ + osConfig, │
│ + config, │
│ + lib, │
│ + pkgs, │
│ + ... │
│ +}: let │
│ + inherit (lib) mkIf elem; │
│ + inherit (builtins) attrValues; │
│ + inherit (osConfig.ooknet.workstation) pro │
│ files; │
│ +in { │
│ + config = mkIf (elem "infra" profiles) { │
│ + home.packages = [ │
│ + (pkgs.writeShellApplication { │
│ + name = "ooknet-provision"; │
│ + runtimeInputs = attrValues { │
│ + inherit │
│ + (pkgs) │
│ + gum │
│ + jq │
│ + coreutils │
│ + nixos-anywhere │
│ + ; │
│ + # I could add 1password here but │
│ it is included in all workstation configurat │
│ ions by default │
│ + }; │
│ + # wrapper around nixos-anywhere wit │
│ h 1password integration for fetching hostkey │
│ s for │
│ + # secret decryption. │
│ + # this script is not intended for g │
│ eneral use, but specifically tailored to my │
│ needs. │
│ + text = '' │
│ + #TODO: │
│ + # - add options for install-key/t │
│ arget user │
│ + # - add log file output │
│ + # - write this in go │
│ + set -euo pipefail │
│ + │
│ + hostname="" │
│ + targetIP="" │
│ + targetUser="root" │
│ + localHostConfigDir="" │
│ + installKey=${config.home.homeDire │
│ ctory}/.ssh/install-key │
│ + additionalFlags="" │
│ + verbose="" │
│ + temp=$(mktemp -d) │
│ + │
│ + cleanup() { │
│ + find "$temp" -type f -exec shre │
│ d -uzn 3 {} \; │
│ + rm -rf "$temp" │
│ + } │
│ + │
│ + helpCmd() { │
│ + cat <<USAGE │
│ + │
│ + Usage: ooknet-provision [target h │
│ ostname] [target ip] │
│ + │
│ + Options: │
│ + │
│ + * -v, --verbose │
│ + Enable verbose output │
│ + * -o, --extra-options │
│ + Pass additional options to nixo │
│ s-anywhere │
│ + * -h, --help │
│ + Print help │
│ + * -d, --host-config-dir │
│ + Specify the location of the tar │
│ get hosts confuration location where hardwar │
│ e.nix will be written. │
│ + Defaults to "<FLAKE>/hosts/<hos │
│ tname>" │
│ + USAGE │
│ + } │
│ + │
│ + log() { │
│ + local type="$1" │
│ + local message="$2" │
│ + │
│ + if [ "$type" = "verbose" ]; the │
│ n │
│ + if [ -n "$verbose" ]; then │
│ + gum log --structured --leve │
│ l debug "$message" │
│ + fi │
│ + return │
│ + fi │
│ + if [ "$type" = "abort" ]; then │
│ + gum log --structured --level │
│ error "$message" │
│ + exit 1 │
│ + else │
│ + gum log --structured --level │
│ "$type" "$message" │
│ + fi │
│ + } │
│ + │
│ + arguments() { │
│ + while [[ $# -gt 0 ]]; do │
│ + case "$1" in │
│ + -h | --help) │
│ + helpCmd │
│ + exit 0 │
│ + ;; │
│ + -v | --verbose) │
│ + verbose="y" │
│ + shift │
│ + ;; │
│ + -o | --extra-options) │
│ + if [[ -z "$2" || "$2" == -* │
│ ]]; then │
│ + log abort "Missing value │
│ for -o, --extra-options" │
│ + fi │
│ + additionalFlags="$2" │
│ + shift 2 │
│ + ;; │
│ + -d | --host-config-dir) │
│ + if [[ -z "$2" || "$2" == -* │
│ ]]; then │
│ + log abort "Missing value │
│ for -d, --host-config-dir" │
│ + fi │
│ + localHostConfigDir="$2" │
│ + shift 2 │
│ + ;; │
│ + -*) │
│ + log abort "Unknown option: │
│ $1" │
│ + ;; │
│ + *) │
│ + if [ -z "$hostname" ]; then │
│ + hostname="$1" │
│ + elif [ -z "$targetIP" ]; th │
│ en │
│ + targetIP="$1" │
│ + else │
│ + log abort "Too many posit │
│ ional arguments: $1. Expected [hostname] [ta │
│ rgetIP]" │
│ + fi │
│ + shift │
│ + ;; │
│ + esac │
│ + done │
│ + if [ -z "$hostname" ]; then │
│ + log abort "Target hostname is │
│ required. Use: provision <hostname> <target │
│ IP> [options]" │
│ + fi │
│ + │
│ + if [ -z "$targetIP" ]; then │
│ + log abort "Target IP address │
│ is required. Use: provision <hostname> <targ │
│ etIP> [options]" │
│ + fi │
│ + │
│ + if [ -z "$localHostConfigDir" ] │
│ ; then │
│ + if [ -n "$FLAKE" ]; then │
│ + localHostConfigDir="$FLAKE/ │
│ hosts/$hostname" │
│ + log verbose "Defaulting loc │
│ al host config directory to: $localHostConfi │
│ gDir" │
│ + else │
│ + log verbose "FLAKE variable │
│ not set; cannot form default for localHostC │
│ onfigDir." │
│ + fi │
│ + else │
│ + log verbose "Using specified │
│ local config directory $localHostConfigDir" │
│ + fi │
│ + } │
│ + │
│ + preChecks() { │
│ + # we need to authenticate early │
│ + log info "Authenicating with 1P │
│ assword" │
│ + if ! op account get >/dev/null; │
│ then │
│ + log abort "Failed to authenic │
│ ate with 1Password..." │
│ + fi │
│ + │
│ + log info "Running pre-installat │
│ ion checks..." │
│ + │
│ + # have you set $FLAKE │
│ + log verbose "Checking FLAKE var │
│ iable is set..." │
│ + if [ -z "$FLAKE" ]; then │
│ + log abort "FLAKE variable uns │
│ et, please set the FLAKE variable to the roo │
│ t location of the ooknet flake" │
│ + else │
│ + log verbose "FLAKE location f │
│ ound..." │
│ + fi │
│ + │
│ + # is there a valid nixosConfigu │
│ rations.$hostname flake output │
│ + log verbose "Checking for nixos │
│ Configuration.$hostname" │
│ + if ! nix flake show "$FLAKE" \ │
│ + --json \ │
│ + --no-update-lock-file \ │
│ + --quiet \ │
│ + --all-systems | │
│ + jq -e --arg hn "$hostname" '. │
│ nixosConfigurations[$hn]'; then │
│ + log abort "nixosConfiguration │
│ s.$hostname not found..." │
│ + else │
│ + log verbose "nixosConfigurati │
│ ons.$hostname found..." │
│ + fi │
│ + │
│ + # ensure $hostname has valid co │
│ nfiguration directory │
│ + # we could make this more robus │
│ t │
│ + log verbose "Checking for $host │
│ name configuration file" │
│ + if [ ! -d "$localHostConfigDir" │
│ ]; then │
│ + log abort "Host confguration │
│ directory: '$localHostConfigDir' (for hardwa │
│ re.nix) does not exist..." │
│ + else │
│ + log verbose "Host configurati │
│ on directory: '$localHostConfigDir' found... │
│ " │
│ + fi │
│ + │
│ + # does the configuration evalua │
│ te │
│ + log verbose "Evaluting configur │
│ ation" │
│ + if ! nix eval --raw "$FLAKE"#ni │
│ xosConfigurations."$hostname".config.system. │
│ build.toplevel; then │
│ + log abort "nixosConfiguration │
│ s.$hostname.config.system.build.toplevel fai │
│ led to evaluate" │
│ + else │
│ + log verbose "nixosConfigurati │
│ ons.$hostname.config.system.build.toplevel s │
│ uccessfully evaluated..." │
│ + fi │
│ + │
│ + # for jq arg (there is a better │
│ way to do this...) │
│ + local target_title="$hostname-h │
│ ostkey" │
│ + │
│ + # have you setup a hostkey in 1 │
│ Password │
│ + log verbose "Checking if hostke │
│ y '$target_title' is available in 1Password" │
│ + if ! op item list --vault ookne │
│ t --tags hostkey --format=json | │
│ + jq -e --arg title_to_find "$t │
│ arget_title" 'any(.[]; .title == $title_to_f │
│ ind)'; then │
│ + log abort "Hostkey '$target_t │
│ itle' not found in vault 'ooknet' with tag ' │
│ hostkey'. Ensure $hostname hostkey has been │
│ defined in 1Password" │
│ + else │
│ + log verbose "Hostkey found... │
│ " │
│ + fi │
│ + │
│ + log verbose "Checking for insta │
│ ll key" │
│ + │
│ + if [ ! -f "$installKey" ]; then │
│ + log abort "Install key not fo │
│ und at $installKey" │
│ + else │
│ + log verbose "Install key foun │
│ d..." │
│ + fi │
│ + │
│ + local ssh_output │
│ + if ! ssh_output=$(ssh \ │
│ + -F /dev/null \ │
│ + -l "$targetUser" \ │
│ + -i "$installKey" \ │
│ + -o BatchMode=yes \ │
│ + -o StrictHostKeyChecking=no \ │
│ + -o ConnectTimeout=30 \ │
│ + "$targetIP" \ │
│ + true 2>&1); then │
│ + log error "$ssh_output" │
│ + log abort "$0 SSH connection │
│ to $targetUser@$targetIP cannot be establish │
│ ed at this time..." │
│ + else │
│ + log info "SSH connection succ │
│ essful..." │
│ + fi │
│ + log info "All checks passed" │
│ + } │
│ + │
│ + getHostKey() { │
│ + log info "Retrieving Host keys │
│ from 1Password vault..." │
│ + install -d -m755 "$temp/etc/ssh │
│ " │
│ + if ! op read \ │
│ + --out-file "$temp/etc/ssh/ssh │
│ _host_ed25519_key" \ │
│ + --file-mode 0600 \ │
│ + "op://ooknet/$hostname-hostke │
│ y/private key"; then │
│ + log abort "Failed to retrieve │
│ private host key" │
│ + fi │
│ + if ! op read \ │
│ + --out-file "$temp/etc/ssh/ssh │
│ _host_ed25519_key.pub" \ │
│ + --file-mode 0644 \ │
│ + "op://ooknet/$hostname-hostke │
│ y/public key"; then │
│ + log abort "Failed to retrieve │
│ public host key" │
│ + fi │
│ + } │
│ + │
│ + deploySystem() { │
│ + log info "Running nixos-anywher │
│ e..." │
│ + │
│ + if [ -z "$localHostConfigDir" ] │
│ ; then │
│ + log abort "localHostConfigDir │
│ is not set. This is a script bug or was not │
│ defaulted correctly" │
│ + fi │
│ + │
│ + local hardware_config_path="$lo │
│ calHostConfigDir/hardware.nix" │
│ + nixos_anywhere_cmd=( │
│ + "nixos-anywhere" │
│ + "--generate-hardware-config" │
│ "nixos-generate-config" "$hardware_config_pa │
│ th" │
│ + "--extra-files" "$temp" │
│ + "--flake" "$FLAKE#$hostname" │
│ + "--target-host" "$targetUser@ │
│ $targetIP" │
│ + "-i" "$installKey" │
│ + ) │
│ + log verbose "Base command: nixo │
│ s-anywhere with standard options" │
│ + │
│ + if [ -n "$additionalFlags" ]; t │
│ hen │
│ + log verbose "Adding additiona │
│ l flags: $additionalFlags" │
│ + │
│ + declare -a extra_args │
│ + read -r -a extra_args <<<"$ad │
│ ditionalFlags" │
│ + │
│ + for arg in "''${extra_args[@] │
│ }"; do │
│ + nixos_anywhere_cmd+=("$arg" │
│ ) │
│ + done │
│ + │
│ + log verbose "Command array no │
│ w has ''${#nixos_anywhere_cmd[@]} elements. │
│ Full command: ''${nixos_anywhere_cmd[*]}" │
│ + fi │
│ + │
│ + if [ -n "$verbose" ]; then │
│ + log verbose "Executing: ''${n │
│ ixos_anywhere_cmd[*]}" │
│ + fi │
│ + │
│ + "''${nixos_anywhere_cmd[@]}" │
│ + │
│ + local exit_code=$? │
│ + if [ $exit_code -eq 0 ]; then │
│ + log info "nixos-anywhere comp │
│ leted successfully" │
│ + else │
│ + log error "nixos-anywhere fai │
│ led with exit code $exit_code" │
│ + fi │
│ + } │
│ + │
│ + main() { │
│ + arguments "$@" │
│ + preChecks │
│ + getHostKey │
│ + deploySystem │
│ + log info "Installation complete │
│ d!" │
│ + } │
│ + │
│ + if [ "$#" -lt 2 ]; then │
│ + helpCmd │
│ + fi │
│ + │
│ + trap cleanup EXIT │
│ + main "$@" │
│ + │
│ + ''; │
│ + }) │
│ + ]; │
│ + }; │
│ +} │
└──────────────────────────────────────────────┘
┌─ modules/nixos/virtualization/host/ooknet-install-vm.nix ──────────────────┐
│ diff --git a/modules/nixos/virtualization/host/ooknet-install-vm.nix b/modules/nix │
│ os/virtualization/host/ooknet-install-vm.nix │
│ index 1c48539..6722734 100644 │
│ --- a/modules/nixos/virtualization/host/ooknet-install-vm.nix │
│ +++ b/modules/nixos/virtualization/host/ooknet-install-vm.nix │
│ @@ -128,7 +128,7 @@ in { │
│ fi │
│ │
│ log warn "Deleting VM..." │
│ - if ! virsh undefine "$NAME" --remove-all-storage >/dev/null 2>&1; t │
│ hen │
│ + if ! virsh undefine "$NAME" --nvram --remove-all-storage >/dev/null │
│ 2>&1; then │
│ log warn "Standard undefine failed, removing manually..." │
│ │
│ virsh undefine "$NAME" >/dev/null 2>&1 || true │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...on/host/ooknet-install-vm.nix ───┐
│ diff --git a/modules/nixos/virtualization/ho │
│ st/ooknet-install-vm.nix b/modules/nixos/vir │
│ tualization/host/ooknet-install-vm.nix │
│ index 1c48539..6722734 100644 │
│ --- a/modules/nixos/virtualization/host/ookn │
│ et-install-vm.nix │
│ +++ b/modules/nixos/virtualization/host/ookn │
│ et-install-vm.nix │
│ @@ -128,7 +128,7 @@ in { │
│ fi │
│ │
│ log warn "Deleting VM..." │
│ - if ! virsh undefine "$NAME" - │
│ -remove-all-storage >/dev/null 2>&1; then │
│ + if ! virsh undefine "$NAME" - │
│ -nvram --remove-all-storage >/dev/null 2>&1; │
│ then │
│ log warn "Standard undefine │
│ failed, removing manually..." │
│ │
│ virsh undefine "$NAME" >/de │
│ v/null 2>&1 || true │
└──────────────────────────────────────────────┘
┌─ modules/nixos/workstation/options.nix ────────────────────────────────────┐
│ diff --git a/modules/nixos/workstation/options.nix b/modules/nixos/workstation/opt │
│ ions.nix │
│ index 0383f89..547a952 100644 │
│ --- a/modules/nixos/workstation/options.nix │
│ +++ b/modules/nixos/workstation/options.nix │
│ @@ -15,7 +15,7 @@ in { │
│ default = null; │
│ }; │
│ profiles = mkOption { │
│ - type = listOf (enum ["gaming" "communication" "productivity" "creative" "me │
│ dia" "virtualization"]); │
│ + type = listOf (enum ["gaming" "communication" "productivity" "creative" "me │
│ dia" "virtualization" "infra"]); │
│ default = []; │
│ }; │
│ environment = mkOption { │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...nixos/workstation/options.nix ───┐
│ diff --git a/modules/nixos/workstation/optio │
│ ns.nix b/modules/nixos/workstation/options.n │
│ ix │
│ index 0383f89..547a952 100644 │
│ --- a/modules/nixos/workstation/options.nix │
│ +++ b/modules/nixos/workstation/options.nix │
│ @@ -15,7 +15,7 @@ in { │
│ default = null; │
│ }; │
│ profiles = mkOption { │
│ - type = listOf (enum ["gaming" "commun │
│ ication" "productivity" "creative" "media" " │
│ virtualization"]); │
│ + type = listOf (enum ["gaming" "commun │
│ ication" "productivity" "creative" "media" " │
│ virtualization" "infra"]); │
│ default = []; │
│ }; │
│ environment = mkOption { │
└──────────────────────────────────────────────┘
[ BACK TO LOG ]
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET