From 8bab910423dc3f4971c9ab2c46460a8be2ebc459 Mon Sep 17 00:00:00 2001 From: Stephen Quoll Date: Thu, 12 Sep 2024 01:12:41 +1000 Subject: [PATCH 1/2] Adding config for pve, qemu and vmware --- Makefile | 16 ++++++++++++++-- nix/pve-builder.nix | 41 ++++++++++++++++++++++++++++++++++++++++ nix/pve.nix | 11 +++++++++++ nix/qemu-builder.nix | 41 ++++++++++++++++++++++++++++++++++++++++ nix/qemu.nix | 20 ++++++++++++++++++++ nix/vmware-builder.nix | 43 ++++++++++++++++++++++++++++++++++++++++++ nix/vmware.nix | 26 +++++++++++++++++++++++++ 7 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 nix/pve-builder.nix create mode 100644 nix/pve.nix create mode 100644 nix/qemu-builder.nix create mode 100644 nix/qemu.nix create mode 100644 nix/vmware-builder.nix create mode 100644 nix/vmware.nix diff --git a/Makefile b/Makefile index 88e2bff..9bd6a1e 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,15 @@ VM_NAME = dogebox-$(shell date +%s) pve: @echo "Generating Proxmox LXC..." - @nixos-generate -c nix/default-builder.nix -f proxmox-lxc + @nixos-generate -c nix/pve-builder.nix -f proxmox-lxc + +qemu: + @echo "Generating QEMU qcow2..." + @nixos-generate -c nix/qemu-builder.nix -f qcow + +raw: + @echo "Generating raw image..." + @nixos-generate -c nix/default-builder.nix -f raw virtualbox: @echo "Generating VirtualBox OVA..." @@ -17,4 +25,8 @@ virtualbox-launch: virtualbox VBoxManage modifyvm "$(VM_NAME)" --nic1 bridged --bridgeadapter1 $$BRIDGE_ADAPTER && \ VBoxManage startvm "$(VM_NAME)" -.PHONY: pve qcow virtualbox virtualbox-launch +vmware: + @echo "Generating VMWare VMDK..." + @nixos-generate -c nix/vmware-builder.nix -f vmware + +.PHONY: pve qemu raw virtualbox virtualbox-launch vmware diff --git a/nix/pve-builder.nix b/nix/pve-builder.nix new file mode 100644 index 0000000..e21c2fa --- /dev/null +++ b/nix/pve-builder.nix @@ -0,0 +1,41 @@ +{ pkgs, ... }: + +let + pveFile = pkgs.writeTextFile { + name = "pve.nix"; + text = builtins.readFile ./pve.nix; + }; + + baseFile = pkgs.writeTextFile { + name = "base.nix"; + text = builtins.readFile ./base.nix; + }; + + dogeboxFile = pkgs.writeTextFile { + name = "dogebox.nix"; + text = builtins.readFile ./dogebox.nix; + }; + + dogeboxdFile = pkgs.writeTextFile { + name = "dogeboxd.nix"; + text = builtins.readFile ./dogeboxd.nix; + }; + + dkmFile = pkgs.writeTextFile { + name = "dkm.nix"; + text = builtins.readFile ./dkm.nix; + }; +in +{ + imports = [ ./pve.nix ]; + + system.activationScripts.copyFiles = '' + mkdir -p /opt/nixos + echo "pve" >> /opt/build-type + cp ${pveFile} /etc/nixos/configuration.nix + cp ${baseFile} /etc/nixos/base.nix + cp ${dogeboxFile} /etc/nixos/dogebox.nix + cp ${dogeboxdFile} /etc/nixos/dogeboxd.nix + cp ${dkmFile} /etc/nixos/dkm.nix + ''; +} diff --git a/nix/pve.nix b/nix/pve.nix new file mode 100644 index 0000000..aba601c --- /dev/null +++ b/nix/pve.nix @@ -0,0 +1,11 @@ +{ modulesPath, ... }: + +{ + imports = + [ + (modulesPath + "/virtualisation/proxmox-lxc.nix") + ./base.nix + ] + ; + +} diff --git a/nix/qemu-builder.nix b/nix/qemu-builder.nix new file mode 100644 index 0000000..9d12ff7 --- /dev/null +++ b/nix/qemu-builder.nix @@ -0,0 +1,41 @@ +{ pkgs, ... }: + +let + qemuFile = pkgs.writeTextFile { + name = "qemu.nix"; + text = builtins.readFile ./qemu.nix; + }; + + baseFile = pkgs.writeTextFile { + name = "base.nix"; + text = builtins.readFile ./base.nix; + }; + + dogeboxFile = pkgs.writeTextFile { + name = "dogebox.nix"; + text = builtins.readFile ./dogebox.nix; + }; + + dogeboxdFile = pkgs.writeTextFile { + name = "dogeboxd.nix"; + text = builtins.readFile ./dogeboxd.nix; + }; + + dkmFile = pkgs.writeTextFile { + name = "dkm.nix"; + text = builtins.readFile ./dkm.nix; + }; +in +{ + imports = [ ./qemu.nix ]; + + system.activationScripts.copyFiles = '' + mkdir -p /opt/nixos + echo "qemu" >> /opt/build-type + cp ${qemuFile} /etc/nixos/configuration.nix + cp ${baseFile} /etc/nixos/base.nix + cp ${dogeboxFile} /etc/nixos/dogebox.nix + cp ${dogeboxdFile} /etc/nixos/dogeboxd.nix + cp ${dkmFile} /etc/nixos/dkm.nix + ''; +} diff --git a/nix/qemu.nix b/nix/qemu.nix new file mode 100644 index 0000000..e4dc632 --- /dev/null +++ b/nix/qemu.nix @@ -0,0 +1,20 @@ +{ + imports = [ ./base.nix ]; + + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + autoResize = true; + fsType = "ext4"; + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-label/ESP"; + fsType = "vfat"; + }; + + boot.growPartition = true; + + boot.loader.grub.device = "/dev/sda"; + + services.qemuGuest.enable = true; +} diff --git a/nix/vmware-builder.nix b/nix/vmware-builder.nix new file mode 100644 index 0000000..c3addb5 --- /dev/null +++ b/nix/vmware-builder.nix @@ -0,0 +1,43 @@ +{ pkgs, ... }: + +let + vmwareFile = pkgs.writeTextFile { + name = "vmware.nix"; + text = builtins.readFile ./vmware.nix; + }; + + baseFile = pkgs.writeTextFile { + name = "base.nix"; + text = builtins.readFile ./base.nix; + }; + + dogeboxFile = pkgs.writeTextFile { + name = "dogebox.nix"; + text = builtins.readFile ./dogebox.nix; + }; + + dogeboxdFile = pkgs.writeTextFile { + name = "dogeboxd.nix"; + text = builtins.readFile ./dogeboxd.nix; + }; + + dkmFile = pkgs.writeTextFile { + name = "dkm.nix"; + text = builtins.readFile ./dkm.nix; + }; +in +{ + imports = [ ./vmware.nix ]; + + vmware.baseImageSize = 6144; + + system.activationScripts.copyFiles = '' + mkdir -p /opt/nixos + echo "vmware" >> /opt/build-type + cp ${vmwareFile} /etc/nixos/configuration.nix + cp ${baseFile} /etc/nixos/base.nix + cp ${dogeboxFile} /etc/nixos/dogebox.nix + cp ${dogeboxdFile} /etc/nixos/dogeboxd.nix + cp ${dkmFile} /etc/nixos/dkm.nix + ''; +} diff --git a/nix/vmware.nix b/nix/vmware.nix new file mode 100644 index 0000000..c824fc9 --- /dev/null +++ b/nix/vmware.nix @@ -0,0 +1,26 @@ +{ + imports = [ ./base.nix ]; + + /* Below copied from ${nixpkgs}/nixos/modules/virtualization/vmware-image.nix */ + + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + autoResize = true; + fsType = "ext4"; + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-label/ESP"; + fsType = "vfat"; + }; + + boot.growPartition = true; + + boot.loader.grub = { + device = "nodev"; + efiSupport = true; + efiInstallAsRemovable = true; + }; + + virtualisation.vmware.guest.enable = true; +} From b1c8c9e5117f9d545365444b614c86e4648bbf22 Mon Sep 17 00:00:00 2001 From: Stephen Quoll Date: Fri, 13 Sep 2024 12:14:36 +1000 Subject: [PATCH 2/2] Adding guest profile to qemu --- nix/pve.nix | 10 ++++------ nix/qemu.nix | 7 ++++++- shell.nix | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/nix/pve.nix b/nix/pve.nix index aba601c..7b2f71a 100644 --- a/nix/pve.nix +++ b/nix/pve.nix @@ -1,11 +1,9 @@ { modulesPath, ... }: { - imports = - [ - (modulesPath + "/virtualisation/proxmox-lxc.nix") - ./base.nix - ] - ; + imports = [ + (modulesPath + "/virtualisation/proxmox-lxc.nix") + ./base.nix + ]; } diff --git a/nix/qemu.nix b/nix/qemu.nix index e4dc632..758e192 100644 --- a/nix/qemu.nix +++ b/nix/qemu.nix @@ -1,5 +1,10 @@ +{ modulesPath, ... }: + { - imports = [ ./base.nix ]; + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ./base.nix + ]; fileSystems."/" = { device = "/dev/disk/by-label/nixos"; diff --git a/shell.nix b/shell.nix index 0a81e84..bb5b4fc 100644 --- a/shell.nix +++ b/shell.nix @@ -2,6 +2,7 @@ pkgs.mkShell { buildInputs = [ + pkgs.gnumake pkgs.nixos-generators ]; }