diff options
author | rnhmjoj <rnhmjoj@inventati.org> | 2021-09-29 08:45:52 +0200 |
---|---|---|
committer | rnhmjoj <rnhmjoj@inventati.org> | 2021-09-29 08:46:03 +0200 |
commit | 1497e8f5f58eeb0bbc0cf97a0267db101726049b (patch) | |
tree | 2a99db791fc5557e7abece52c86a1bafbe0c1e34 /nixos/modules | |
parent | a46a8a13deefc3744a62efa0a83cab2b353f173a (diff) | |
download | nixpkgs-1497e8f5f58eeb0bbc0cf97a0267db101726049b.tar nixpkgs-1497e8f5f58eeb0bbc0cf97a0267db101726049b.tar.gz nixpkgs-1497e8f5f58eeb0bbc0cf97a0267db101726049b.tar.bz2 nixpkgs-1497e8f5f58eeb0bbc0cf97a0267db101726049b.tar.lz nixpkgs-1497e8f5f58eeb0bbc0cf97a0267db101726049b.tar.xz nixpkgs-1497e8f5f58eeb0bbc0cf97a0267db101726049b.tar.zst nixpkgs-1497e8f5f58eeb0bbc0cf97a0267db101726049b.zip |
nixos/qemu: use set -e in shell script
Also fix this: https://github.com/koalaman/shellcheck/wiki/SC2166
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/virtualisation/qemu-vm.nix | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index f7b6b4eac39..494c2c14284 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -108,15 +108,17 @@ let '' #! ${pkgs.runtimeShell} + set -e + NIX_DISK_IMAGE=$(readlink -f "''${NIX_DISK_IMAGE:-${config.virtualisation.diskImage}}") if ! test -e "$NIX_DISK_IMAGE"; then ${qemu}/bin/qemu-img create -f qcow2 "$NIX_DISK_IMAGE" \ - ${toString config.virtualisation.diskSize}M || exit 1 + ${toString config.virtualisation.diskSize}M fi # Create a directory for storing temporary data of the running VM. - if [ -z "$TMPDIR" -o -z "$USE_TMPDIR" ]; then + if [ -z "$TMPDIR" ] || [ -z "$USE_TMPDIR" ]; then TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir) fi @@ -127,7 +129,7 @@ let '' # Create a writable copy/snapshot of the boot disk. # A writable boot disk can be booted from automatically. - ${qemu}/bin/qemu-img create -f qcow2 -F qcow2 -b ${bootDisk}/disk.img "$TMPDIR/disk.img" || exit 1 + ${qemu}/bin/qemu-img create -f qcow2 -F qcow2 -b ${bootDisk}/disk.img "$TMPDIR/disk.img" NIX_EFI_VARS=$(readlink -f "''${NIX_EFI_VARS:-${cfg.efiVars}}") @@ -135,13 +137,13 @@ let '' # VM needs writable EFI vars if ! test -e "$NIX_EFI_VARS"; then - cp ${bootDisk}/efi-vars.fd "$NIX_EFI_VARS" || exit 1 - chmod 0644 "$NIX_EFI_VARS" || exit 1 + cp ${bootDisk}/efi-vars.fd "$NIX_EFI_VARS" + chmod 0644 "$NIX_EFI_VARS" fi ''} ''} - cd "$TMPDIR" || exit 1 + cd "$TMPDIR" ${lib.optionalString (cfg.emptyDiskImages != []) "idx=0"} ${flip concatMapStrings cfg.emptyDiskImages (size: '' |