Skip to content

Commit

Permalink
Convert libvirtd to use make-disk-image
Browse files Browse the repository at this point in the history
This fixes #931 by reusing the
image builder of <nixpkgs/nixos/lib/make-disk-image.nix>. This image
builder produces nixos.qcow2 instead of disk.qcow2. This image is now
"baseless", so it obsoletes "qemu-img rebase". We can also remove our
special-case image builder libvirtd-image.nix as a whole.
  • Loading branch information
teto committed Oct 16, 2019
1 parent 8c278af commit bdfa512
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 120 deletions.
89 changes: 0 additions & 89 deletions nix/libvirtd-image.nix

This file was deleted.

38 changes: 12 additions & 26 deletions nix/libvirtd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,19 @@
with lib;

let
sz = toString config.deployment.libvirtd.baseImageSize;
base_image = import ./libvirtd-image.nix { size = sz; };
the_key = builtins.getEnv "NIXOPS_LIBVIRTD_PUBKEY";
ssh_image = pkgs.vmTools.runInLinuxVM (
pkgs.runCommand "libvirtd-ssh-image"
{ memSize = 768;
preVM =
''
mkdir $out
diskImage=$out/image
${pkgs.vmTools.qemu}/bin/qemu-img create -f qcow2 -b ${base_image}/disk.qcow2 $diskImage
'';
buildInputs = [ pkgs.utillinux ];
postVM =
''
mv $diskImage $out/disk.qcow2
'';
}
''
mkdir /mnt
mount /dev/vda1 /mnt
mkdir -p /mnt/etc/ssh/authorized_keys.d
echo '${the_key}' > /mnt/etc/ssh/authorized_keys.d/root
umount /mnt
''
);
ssh_image = import <nixpkgs/nixos/lib/make-disk-image.nix> {
name = "libvirtd-ssh-image";
format = "qcow2";
diskSize = config.deployment.libvirtd.baseImageSize * 1024;
config = config;
contents = [{
source = (pkgs.writeText "authorized_keys.d-root" the_key);
target = "/etc/ssh/authorized_keys.d/root";
}];
lib = pkgs.lib;
inherit pkgs;
};
in

{
Expand Down
6 changes: 1 addition & 5 deletions nixopsvirtd/backends/libvirtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ def _prepare_storage_volume(self):
capture_stdout=True, env=newEnv).rstrip()

temp_disk_path = os.path.join(self.depl.tempdir, 'disk-{}.qcow2'.format(self.name))
shutil.copyfile(os.path.join(temp_image_path, 'disk.qcow2'), temp_disk_path)
# Rebase onto empty backing file to prevent breaking the disk image
# when the backing file gets garbage collected.
self._logged_exec(["qemu-img", "rebase", "-f", "qcow2", "-b",
"", temp_disk_path])
shutil.copyfile(os.path.join(temp_image_path, 'nixos.qcow2'), temp_disk_path)

self.logger.log("uploading disk image...")
image_info = self._get_image_info(temp_disk_path)
Expand Down

0 comments on commit bdfa512

Please sign in to comment.