Archived
Check NixOS configurations / eval-hosts (pull_request) Failing after 11m29s
Three chunks of copy-pasted logic were drifting across scripts/*.sh: - codex-setup.sh and codex-maintenance.sh each carried an identical NIX_CONFIG bootstrap + ensure_nix_profile() -> scripts/lib/nix-bootstrap.sh - sync-host-keys.sh and prepare-host-key.sh each ran the same ssh-keygen/ssh-to-age nix-shell invocations -> scripts/lib/ssh-host-keys.sh (prepare-host-key.sh now also calls env.sh's nix_extra_opts before using them, closing a gap where it alone skipped the nix-cache reachability check env.sh exists for) - the "list nixosConfigurations attrNames" / "get one target's hostName" nix eval pattern was repeated across codex-setup.sh, codex-maintenance.sh, sync-host-keys.sh and create-proxmox-resource.sh (the latter twice, in its own --list and --host lookup) -> scripts/lib/nix-eval.sh, which also centralizes the --no-use-registries --no-accept-flake-config flag pair used on every such call Verified against the real flake/node config (nix is available here): create-proxmox-resource.sh --list for both --type lxc/vm, a full --dry-run create, and prepare-host-key.sh generating and cleaning up a real key/age-pubkey pair. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
37 lines
1.6 KiB
Bash
37 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
# Shared flake-introspection helpers for scripts/*.sh. Source alongside
|
|
# env.sh:
|
|
# source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/nix-eval.sh"
|
|
#
|
|
# NIX_EVAL_FLAGS: --no-use-registries so a call here never resolves through
|
|
# the user's global flake registry (every call targets this repo's own
|
|
# flake, or an explicit github: ref, not a registry alias); --no-accept-flake-config
|
|
# so a flake input's own nixConfig (e.g. a dependency's substituters) is
|
|
# never honored -- matches accept-flake-config = false already set repo-wide
|
|
# (see lib/nix-bootstrap.sh / CLAUDE.md). Reuse this array rather than
|
|
# retyping the two flags at each call site.
|
|
declare -a NIX_EVAL_FLAGS=(--no-use-registries --no-accept-flake-config)
|
|
|
|
# list_flake_targets <flake_ref>
|
|
# Prints the attribute names under <flake_ref>#nixosConfigurations, one per
|
|
# line, e.g.:
|
|
# list_flake_targets . # from inside the repo
|
|
# list_flake_targets "$repo_root" # from anywhere
|
|
list_flake_targets() {
|
|
local flake_ref="$1"
|
|
nix eval --json "${NIX_EVAL_FLAGS[@]}" \
|
|
"${flake_ref}#nixosConfigurations" --apply builtins.attrNames \
|
|
| jq -r '.[]'
|
|
}
|
|
|
|
# flake_target_hostname <flake_ref> <target>
|
|
# Prints one nixosConfigurations target's config.networking.hostName.
|
|
# Empty (not an error under set -e) if the target doesn't exist or the
|
|
# eval otherwise fails -- callers that need to distinguish "empty" from
|
|
# "eval failed" should check $? themselves instead of relying on this.
|
|
flake_target_hostname() {
|
|
local flake_ref="$1" target="$2"
|
|
nix eval --raw "${NIX_EVAL_FLAGS[@]}" \
|
|
"${flake_ref}#nixosConfigurations.${target}.config.networking.hostName" 2>/dev/null
|
|
}
|