Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/proxmox-image: qemu 7.2.1 -> 8.1.5, add cloud-init #307287

Merged
merged 4 commits into from
Jun 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 53 additions & 30 deletions nixos/modules/virtualisation/proxmox-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ with lib;
};
scsihw = mkOption {
type = types.str;
default = "virtio-scsi-pci";
default = "virtio-scsi-single";
example = "lsi";
description = ''
SCSI controller type. Must be one of the supported values given in
Expand Down Expand Up @@ -158,6 +158,31 @@ with lib;
any specific VMID.
'';
};
cloudInit = {
enable = mkOption {
type = types.bool;
default = true;
description = ''
Whether the VM should accept cloud init configurations from PVE.
'';
};
defaultStorage = mkOption {
default = "local-lvm";
example = "tank";
type = types.str;
description = ''
Default storage name for cloud init drive.
'';
};
device = mkOption {
default = "ide2";
example = "scsi0";
type = types.str;
description = ''
Bus/device to which the cloud init drive is attached.
'';
};
};
};

config = let
Expand Down Expand Up @@ -216,37 +241,21 @@ with lib;
seccompSupport = false;
guestAgentSupport = false;
}).overrideAttrs ( super: rec {

version = "7.2.1";
# Check https://github.com/proxmox/pve-qemu/tree/master for the version
# of qemu and patch to use
version = "8.1.5";
src = pkgs.fetchurl {
url= "https://download.qemu.org/qemu-${version}.tar.xz";
sha256 = "sha256-jIVpms+dekOl/immTN1WNwsMLRrQdLr3CYqCTReq1zs=";
url = "https://download.qemu.org/qemu-${version}.tar.xz";
hash = "sha256-l2Ox7+xP1JeWtQgNCINRLXDLY4nq1lxmHMNoalIjKJY=";
};
patches = [
# Proxmox' VMA tool is published as a particular patch upon QEMU
(pkgs.fetchpatch {
url =
let
rev = "abb04bb6272c1202ca9face0827917552b9d06f6";
path = "debian/patches/pve/0027-PVE-Backup-add-vma-backup-format-code.patch";
in "https://git.proxmox.com/?p=pve-qemu.git;a=blob_plain;hb=${rev};f=${path}";
hash = "sha256-3d0HHdvaExCry6zcULnziYnWIAnn24vECkI4sjj2BMg=";
})

# Proxmox' VMA tool uses O_DIRECT which fails on tmpfs
# Filed to upstream issue tracker: https://bugzilla.proxmox.com/show_bug.cgi?id=4710
(pkgs.writeText "inline.patch" ''
--- a/vma-writer.c 2023-05-01 15:11:13.361341177 +0200
+++ b/vma-writer.c 2023-05-01 15:10:51.785293129 +0200
@@ -306,7 +306,7 @@
/* try to use O_NONBLOCK */
fcntl(vmaw->fd, F_SETFL, fcntl(vmaw->fd, F_GETFL)|O_NONBLOCK);
} else {
- oflags = O_NONBLOCK|O_DIRECT|O_WRONLY|O_EXCL;
+ oflags = O_NONBLOCK|O_WRONLY|O_EXCL;
vmaw->fd = qemu_create(filename, oflags, 0644, errp);
}
'')
"${pkgs.fetchFromGitHub {
owner = "proxmox";
repo = "pve-qemu";
rev = "71dd2d48f9122e60e4c0a8480122a27aab15dc70";
hash = "sha256-Q8AxNv4geDdlbVIWphRO5P3ESo0SGgvUpVPmPJzubJM=";
}}/debian/patches/pve/0027-PVE-Backup-add-vma-backup-format-code.patch"
];

buildInputs = super.buildInputs ++ [ pkgs.libuuid ];
Expand All @@ -262,7 +271,7 @@ with lib;
mv "vzdump-qemu-${cfg.filenameSuffix}.vma.zst" $out/

mkdir -p $out/nix-support
echo "file vma $out/vzdump-qemu-${cfg.filenameSuffix}.vma.zst" >> $out/nix-support/hydra-build-products
echo "file vma $out/vzdump-qemu-${cfg.filenameSuffix}.vma.zst" > $out/nix-support/hydra-build-products
'';
inherit (cfg.qemuConf) additionalSpace diskSize bootSize;
format = "raw";
Expand Down Expand Up @@ -298,6 +307,20 @@ with lib;
fsType = "vfat";
};

services.qemuGuest.enable = lib.mkDefault true;
networking = mkIf cfg.cloudInit.enable {
hostName = mkForce "";
useDHCP = false;
};

services = {
cloud-init = mkIf cfg.cloudInit.enable {
enable = true;
network.enable = true;
};
sshd.enable = mkDefault true;
qemuGuest.enable = true;
};

proxmox.qemuExtraConf.${cfg.cloudInit.device} = "${cfg.cloudInit.defaultStorage}:vm-9999-cloudinit,media=cdrom";
};
}