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: init #144013

Merged
merged 5 commits into from
Nov 7, 2021
Merged

nixos/proxmox-image: init #144013

merged 5 commits into from
Nov 7, 2021

Conversation

illustris
Copy link
Contributor

Add module to generate KVM templates that proxmox can import.

Motivation for this change

Spinning up NixOS VMs on proxmox is a manual process at the moment. This module adds a way to generate VMA files that can be used as VM templates on proxmox.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Oct 31, 2021
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Oct 31, 2021
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/625

Copy link
Contributor

@rnhmjoj rnhmjoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't do much of a review because I've never used proxmox, but I left some comments regarding the Nix code.

nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
@illustris illustris force-pushed the pve branch 2 times, most recently from f53b67a to e689453 Compare November 2, 2021 14:56
@illustris
Copy link
Contributor Author

[nix-shell:~/src/nixpkgs]$ nixos-generate -I nixpkgs=/home/illustris/src/nixpkgs --format proxmox
these derivations will be built:
  /nix/store/7mk1007hlw0hlmyq7r1icxr9cj6yq4wd-nixos-version.drv
  /nix/store/xljddk6l1sxv2l5g9vscrj8vgqs0km9p-system-path.drv
.
.
.
copying path '/nix/store/h32aczyfk7ny9xwn896jrzf66pra082c-nixos-system-nixos-21.11.git.d41882c7b98M' to 'local'...
copying channel...
installation finished!
Automatic disk size...
.
.
.
copying staging root to image...
[    0.000000] Linux version 5.3.0 (nixbld@) (gcc version 10.3.0 (GCC)) #1 Sun Sep 26 23:47:23 UTC 2021
[    0.000000] memblock address range: 0x7fffe9c00000 - 0x7fffeffff000
.
.
.
Setting time filesystem last checked to Tue Nov  2 15:00:57 2021

[    2.879753] reboot: Power down
vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma : 26.02%   (2542638080 => 661603014 bytes, vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma.zst)
/nix/store/iac3ibazad7xahi6dw8z364907jxd734-proxmox-nixos-21.11.git.d41882c7b98M/vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma.zst

[nix-shell:~/src/nixpkgs]$ zstd -d /nix/store/iac3ibazad7xahi6dw8z364907jxd734-proxmox-nixos-21.11.git.d41882c7b98M/vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma.zst -o ./vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma

[nix-shell:~/src/nixpkgs]$ nix-shell -I nixpkgs=$(pwd) -p 'qemu.overrideAttrs ( super: {patches = super.patches ++ [ /home/illustris/src/proxmox/pve-qemu/debian/patches/pve/0025-PVE-Backup-add-vma-backup-format-code.patch ]; buildInputs = super.buildInputs ++ [ libuuid ];})'

[nix-shell:~/src/nixpkgs]$ vma list ./vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma
CFG: size: 285 name: qemu-server.conf
DEV: dev_id=1 size: 4107272192 devname: drive-virtio0
CTIME: Tue Nov  2 20:31:03 2021

[nix-shell:~/src/nixpkgs]$ rsync -avzh --progress /nix/store/iac3ibazad7xahi6dw8z364907jxd734-proxmox-nixos-21.11.git.d41882c7b98M/vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma.zst root@cube:/var/lib/vz/dump/
sending incremental file list
vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma.zst
        661.60M 100%  110.90MB/s    0:00:05 (xfr#1, to-chk=0/1)

sent 661.88M bytes  received 35 bytes  101.83M bytes/sec
total size is 661.60M  speedup is 1.00

[nix-shell:~/src/nixpkgs]$ ssh root@cube
.
.
root@cube:~# qmrestore /var/lib/vz/dump/vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma.zst 500 --unique true
restore vma archive: zstd -q -d -c /var/lib/vz/dump/vzdump-qemu-nixos-21.11.git.d41882c7b98M.vma.zst | vma extract -v -r /var/tmp/vzdumptmp17409.fifo - /var/tmp/vzdumptmp17409
CFG: size: 285 name: qemu-server.conf
DEV: dev_id=1 size: 4107272192 devname: drive-virtio0
CTIME: Tue Nov  2 20:31:03 2021
  Rounding up size to full physical extent <3.83 GiB
  WARNING: You have not turned on protection against thin pools running out of space.
  WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
  Logical volume "vm-500-disk-0" created.
  WARNING: Sum of all thin volume sizes (245.83 GiB) exceeds the size of thin pool pve/data and the size of whole volume group (232.38 GiB).
new volume ID is 'local-lvm:vm-500-disk-0'
map 'drive-virtio0' to '/dev/pve/vm-500-disk-0' (write zeros = 0)
progress 1% (read 41091072 bytes, duration 0 sec)
.
.
.
progress 100% (read 4107272192 bytes, duration 6 sec)
total bytes read 4107272192, sparse bytes 1565200384 (38.1%)
space reduction due to 4K zero blocks 0.637%
rescan volumes...
VM 500 (virtio0): size of disk 'local-lvm:vm-500-disk-0' updated from 0T to 3920M
root@cube:~# qm start 500; qm terminal 500
starting serial terminal on interface serial0 (press Ctrl+O to exit)

<<< NixOS Stage 1 >>>

loading module dm_mod...
running udev...
Starting version 249.4
.
.
.
[  OK  ] Reached target Multi-User System.


<<< Welcome to NixOS 21.11.git.d41882c7b98M (x86_64) - ttyS0 >>>

Run 'nixos-help' for the NixOS manual.

nixos login: root (automatic login)


[root@nixos:~]#

@illustris illustris requested a review from rnhmjoj November 2, 2021 16:08
Copy link
Contributor

@rnhmjoj rnhmjoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more nitpicks, sorry ;)

nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
Add module to generate KVM templates that proxmox can import
Copy link
Contributor

@rnhmjoj rnhmjoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a last thing, I'll ask you to wrap those couple of very long lines: there's no rule like 80 chars, but please limit it to at least something that doesn't overflow the github interface.

Otherwise the PR looks good to me, but I have no means of testing the image. Ideally someone else familiar with proxmox should review this.

@illustris
Copy link
Contributor Author

I don't know any PVE+Nix users that haven't already worked with me on this... I've asked for help on discourse, let's see if anyone shows up in the next few days.

Copy link
Member

@SuperSandro2000 SuperSandro2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like long lines but they should not overflow the GitHub UI.

nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/proxmox-image.nix Outdated Show resolved Hide resolved
@SuperSandro2000
Copy link
Member

I don't know any PVE+Nix users that haven't already worked with me on this... I've asked for help on discourse, let's see if anyone shows up in the next few days.

Eventually I and more likely @astro are going to try it with our spaces proxmox cluster but that could take a bit.

@SuperSandro2000 SuperSandro2000 merged commit 8d197bf into NixOS:master Nov 7, 2021
@illustris
Copy link
Contributor Author

I was travelling over the weekend, so I could only merge suggestions from the github interface. I was planning to fix the whitespace and update the PR today. Thanks!

@RaitoBezarius
Copy link
Member

Super nice, thanks @illustris !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants