@@ -46,6 +46,8 @@ Options:
4646 URL of the source Nix store to copy the nixos and disko closure from
4747* --build-on-remote
4848 build the closure on the remote machine instead of locally and copy-closuring it
49+ * --vm-test
50+ build the system and test the disk configuration inside a VM without installing it to the target.
4951USAGE
5052}
5153
@@ -155,7 +157,9 @@ while [[ $# -gt 0 ]]; do
155157 --build-on-remote)
156158 build_on_remote=y
157159 ;;
158-
160+ --vm-test)
161+ vm_test=y
162+ ;;
159163 * )
160164 if [[ -z ${ssh_connection-} ]]; then
161165 ssh_connection=" $1 "
@@ -198,17 +202,19 @@ nix_build() {
198202 " $@ "
199203}
200204
201- if [[ -z ${ssh_connection-} ]]; then
202- abort " ssh-host must be set"
203- fi
205+ if [[ -z ${vm_test-} ]]; then
206+ if [[ -z ${ssh_connection-} ]]; then
207+ abort " ssh-host must be set"
208+ fi
204209
205- # we generate a temporary ssh keypair that we can use during nixos-anywhere
206- ssh_key_dir=$( mktemp -d)
207- trap ' rm -rf "$ssh_key_dir"' EXIT
208- mkdir -p " $ssh_key_dir "
209- # ssh-copy-id requires this directory
210- mkdir -p " $HOME /.ssh/"
211- ssh-keygen -t ed25519 -f " $ssh_key_dir " /nixos-anywhere -P " " -C " nixos-anywhere" > /dev/null
210+ # we generate a temporary ssh keypair that we can use during nixos-anywhere
211+ ssh_key_dir=$( mktemp -d)
212+ trap ' rm -rf "$ssh_key_dir"' EXIT
213+ mkdir -p " $ssh_key_dir "
214+ # ssh-copy-id requires this directory
215+ mkdir -p " $HOME /.ssh/"
216+ ssh-keygen -t ed25519 -f " $ssh_key_dir " /nixos-anywhere -P " " -C " nixos-anywhere" > /dev/null
217+ fi
212218
213219# parse flake nixos-install style syntax, get the system attr
214220if [[ -n ${flake-} ]]; then
@@ -222,6 +228,14 @@ if [[ -n ${flake-} ]]; then
222228 exit 1
223229 fi
224230 if [[ ${build_on_remote-n} == " n" ]]; then
231+ if [[ -n ${vm_test-} ]]; then
232+ exec nix build \
233+ --print-out-paths \
234+ --no-link \
235+ -L \
236+ " ${nix_options[@]} " \
237+ " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.installTest"
238+ fi
225239 disko_script=$( nix_build " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.diskoScript" )
226240 nixos_system=$( nix_build " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.toplevel" )
227241 fi
0 commit comments