#!/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 # Prints the attribute names under #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 # 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 } # flake_target_lxc_privileged # Prints "true" or "false" for one lxc-* target's config.proxmoxLXC.privileged # (modules/platforms/lxc.nix is the single source of truth -- e.g. # lxc-docker sets this true so it can NFS-mount; every other lxc-* host # stays unprivileged). Only meaningful for lxc-* targets -- the option # doesn't exist for linode-*/proxmox-* (nixpkgs' proxmox-lxc.nix, which # declares it, is only ever imported by modules/platforms/lxc.nix). Empty # (not an error under set -e) if the eval fails. flake_target_lxc_privileged() { local flake_ref="$1" target="$2" # Not --raw: the option is a Nix boolean, and --raw can only coerce # strings ("cannot coerce a Boolean to a string"). Plain `nix eval` # prints a bare `true`/`false` for a boolean, which is exactly the # string this needs. nix eval "${NIX_EVAL_FLAGS[@]}" \ "${flake_ref}#nixosConfigurations.${target}.config.proxmoxLXC.privileged" 2>/dev/null }