Skip to content

Commit

Permalink
add --vm-test mode for local vm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lassulus committed Jul 20, 2023
1 parent 11d3803 commit 2e0ab3e
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Options:
URL of the source Nix store to copy the nixos and disko closure from
* --build-on-remote
build the closure on the remote machine instead of locally and copy-closuring it
* --vm-test
run a test locally to debug the disk configuration
USAGE
}

Expand Down Expand Up @@ -155,7 +157,9 @@ while [[ $# -gt 0 ]]; do
--build-on-remote)
build_on_remote=y
;;

--vm-test)
vm_test=y
;;
*)
if [[ -z ${ssh_connection-} ]]; then
ssh_connection="$1"
Expand Down Expand Up @@ -198,17 +202,19 @@ nix_build() {
"$@"
}

if [[ -z ${ssh_connection-} ]]; then
abort "ssh-host must be set"
fi
if [[ -z ${vm_test-} ]]; then
if [[ -z ${ssh_connection-} ]]; then
abort "ssh-host must be set"
fi

# we generate a temporary ssh keypair that we can use during nixos-anywhere
ssh_key_dir=$(mktemp -d)
trap 'rm -rf "$ssh_key_dir"' EXIT
mkdir -p "$ssh_key_dir"
# ssh-copy-id requires this directory
mkdir -p "$HOME/.ssh/"
ssh-keygen -t ed25519 -f "$ssh_key_dir"/nixos-anywhere -P "" -C "nixos-anywhere" >/dev/null
# we generate a temporary ssh keypair that we can use during nixos-anywhere
ssh_key_dir=$(mktemp -d)
trap 'rm -rf "$ssh_key_dir"' EXIT
mkdir -p "$ssh_key_dir"
# ssh-copy-id requires this directory
mkdir -p "$HOME/.ssh/"
ssh-keygen -t ed25519 -f "$ssh_key_dir"/nixos-anywhere -P "" -C "nixos-anywhere" >/dev/null
fi

# parse flake nixos-install style syntax, get the system attr
if [[ -n ${flake-} ]]; then
Expand All @@ -222,6 +228,13 @@ if [[ -n ${flake-} ]]; then
exit 1
fi
if [[ ${build_on_remote-n} == "n" ]]; then
if [[ -n ${vm_test-} ]]; then
exec nix build \
--print-out-paths \
--no-link \
"${nix_options[@]}" \
"${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.installTest"
fi
disko_script=$(nix_build "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.diskoScript")
nixos_system=$(nix_build "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.toplevel")
fi
Expand Down

0 comments on commit 2e0ab3e

Please sign in to comment.