mirror of
https://github.com/Death916/nixconfig.git
synced 2026-04-10 02:54:39 -07:00
haos nix service
This commit is contained in:
parent
d6f2e4553c
commit
c0b2a038f2
16 changed files with 53 additions and 1313 deletions
|
|
@ -1,31 +0,0 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
environment.systemPackages = [
|
||||
(pkgs.writeShellScriptBin "haos" ''
|
||||
VM_NAME="homeassistant"
|
||||
case "$1" in
|
||||
start) virsh start "$VM_NAME" ;;
|
||||
stop) virsh shutdown "$VM_NAME" ;;
|
||||
status) virsh list --all | grep "$VM_NAME" ;;
|
||||
ip) virsh domifaddr "$VM_NAME" | awk '/ipv4/ {print $4}' | cut -d/ -f1 ;;
|
||||
console) virsh console "$VM_NAME" ;;
|
||||
destroy)
|
||||
echo "This will permanently delete the VM. Are you sure? (y/N)"
|
||||
read -r confirmation
|
||||
if [[ "$confirmation" =~ ^[Yy]$ ]]; then
|
||||
virsh destroy "$VM_NAME" || true
|
||||
virsh undefine "$VM_NAME" --remove-all-storage || true
|
||||
echo "VM destroyed."
|
||||
else
|
||||
echo "Destruction cancelled."
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: haos {start|stop|status|ip|console|destroy}"
|
||||
;;
|
||||
esac
|
||||
'')
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.services.homeassistant-vm;
|
||||
in
|
||||
{
|
||||
environment.systemPackages = [
|
||||
(pkgs.writeShellScriptBin "deploy-haos" ''
|
||||
set -e
|
||||
IMAGE="${cfg.imagePath}"
|
||||
VM_NAME="homeassistant"
|
||||
BRIDGE="${cfg.bridge}"
|
||||
MEM_MB="${toString cfg.memory}"
|
||||
VCPUS="${toString cfg.vcpus}"
|
||||
|
||||
if [ ! -f "$IMAGE" ]; then
|
||||
echo "Error: HAOS image not found at $IMAGE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if virsh list --all | grep -q " $VM_NAME "; then
|
||||
echo "VM $VM_NAME already exists"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
virt-install \
|
||||
--name "$VM_NAME" \
|
||||
--memory "$MEM_MB" \
|
||||
--vcpus "$VCPUS" \
|
||||
--import \
|
||||
--disk path="$IMAGE",format=qcow2,bus=virtio \
|
||||
--network bridge="$BRIDGE",model=virtio \
|
||||
--os-variant generic \
|
||||
--graphics none \
|
||||
--noautoconsole \
|
||||
--boot uefi
|
||||
|
||||
echo "Home Assistant VM deployed!"
|
||||
echo "Get IP with: haos ip"
|
||||
'')
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
|
||||
# /home/death916/nixconfig/modules/vms/haos-vm.nix
|
||||
#
|
||||
# Declarative Home Assistant VM configuration using NixVirt.
|
||||
# This is the permanent, declarative solution to managing your VM.
|
||||
#
|
||||
# To use this, you must:
|
||||
# 1. Add NixVirt to your flake.nix inputs.
|
||||
# inputs.nixvirt = {
|
||||
# url = "github:NixOS/nixvirt";
|
||||
# inputs.nixpkgs.follows = "nixpkgs";
|
||||
# };
|
||||
# 2. Import this file and the nixvirt module in your main NixOS configuration:
|
||||
# imports = [
|
||||
# ./modules/vms/haos-vm.nix
|
||||
# inputs.nixvirt.nixosModules.default # Provides the options below
|
||||
# ];
|
||||
# 3. Remove the old `services.homeassistant-vm` block from your configuration.
|
||||
# 4. Ensure `virtualisation.libvirtd.qemu.ovmf.enable = true;` is set.
|
||||
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
# Parameters for your VM, taken from your existing configuration.
|
||||
haosImagePath = "/var/lib/libvirt/images/haos.qcow2";
|
||||
haosMemory = 6096; # In MiB, from your services.nix
|
||||
haosVcpus = 4; # From your services.nix
|
||||
haosBridge = "br0";
|
||||
in
|
||||
{
|
||||
# This defines the Libvirt domain (VM) using NixVirt's options.
|
||||
# It assumes you are using the default libvirt connection.
|
||||
virtualisation.libvirt.connections.default.domains = {
|
||||
homeassistant = {
|
||||
autostart = true;
|
||||
# The domain configuration, which maps closely to Libvirt's XML structure.
|
||||
domain = {
|
||||
type = "kvm"; # Use KVM for hardware acceleration
|
||||
name = "homeassistant";
|
||||
memory = {
|
||||
value = haosMemory;
|
||||
unit = "MiB";
|
||||
};
|
||||
vcpu = {
|
||||
placement = "static";
|
||||
value = haosVcpus;
|
||||
};
|
||||
|
||||
# OS boot configuration
|
||||
os = {
|
||||
type = {
|
||||
arch = "x86_64";
|
||||
machine = "pc-q35-8.0"; # Modern machine type, good default
|
||||
value = "hvm";
|
||||
};
|
||||
# This ensures the VM boots with UEFI.
|
||||
# The path is managed by NixOS when `ovmf.enable = true` is set.
|
||||
loader = {
|
||||
readonly = "yes";
|
||||
type = "pflash";
|
||||
path = "${pkgs.OVMF.fd}/FV/OVMF.fd";
|
||||
};
|
||||
# NVRAM storage for UEFI settings.
|
||||
nvram.template = "${pkgs.OVMF.fd}/FV/OVMF_VARS.fd";
|
||||
boot.dev = "hd";
|
||||
};
|
||||
|
||||
# CPU configuration
|
||||
cpu.mode = "host-passthrough";
|
||||
|
||||
# Devices configuration
|
||||
devices = {
|
||||
emulator = "${pkgs.qemu_kvm}/bin/qemu-system-x86_64";
|
||||
disks = [{
|
||||
type = "file";
|
||||
device = "disk";
|
||||
driver = {
|
||||
name = "qemu";
|
||||
type = "qcow2";
|
||||
};
|
||||
source.file = haosImagePath;
|
||||
target = {
|
||||
dev = "vda";
|
||||
bus = "virtio";
|
||||
};
|
||||
}];
|
||||
interfaces = [{
|
||||
type = "bridge";
|
||||
source.bridge = haosBridge;
|
||||
model.type = "virtio";
|
||||
}];
|
||||
# Headless setup
|
||||
consoles = [{ type = "pty"; }];
|
||||
graphics = [{ type = "none"; }];
|
||||
# Virtio balloon for memory management
|
||||
memballoon.model = "virtio";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
# You would define these variables based on your actual configuration
|
||||
# or pass them in from the homeassistant-vm.nix module if you keep it
|
||||
haosImagePath = "/var/lib/libvirt/images/haos.qcow2";
|
||||
haosMemory = 4096; # MB
|
||||
haosVcpus = 2;
|
||||
haosBridge = "br0";
|
||||
in
|
||||
{
|
||||
services = {
|
||||
libvirtd = {
|
||||
enable = true;
|
||||
qemu = {
|
||||
enable = true;
|
||||
swtpm.enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
virtualisation = {
|
||||
libvirt = {
|
||||
qemu = {
|
||||
# This enables the QEMU driver for Libvirt
|
||||
enable = true;
|
||||
|
||||
# Define your Home Assistant VM here
|
||||
machines.homeassistant = {
|
||||
# Enable autostart for this VM
|
||||
autostart = true;
|
||||
|
||||
# Memory in MiB
|
||||
memory = haosMemory;
|
||||
|
||||
# Number of virtual CPUs
|
||||
vcpu = haosVcpus;
|
||||
|
||||
# Disk configuration
|
||||
disks = [
|
||||
{
|
||||
file = haosImagePath;
|
||||
format = "qcow2";
|
||||
# Use virtio for better performance
|
||||
driver = "qemu"; # Or "raw" if not qcow2
|
||||
device = "disk"; # Or "cdrom" for ISO
|
||||
bus = "virtio";
|
||||
}
|
||||
];
|
||||
|
||||
# Network configuration
|
||||
networks = [
|
||||
{
|
||||
type = "bridge";
|
||||
source = haosBridge;
|
||||
model = "virtio"; # Use virtio for better performance
|
||||
}
|
||||
];
|
||||
|
||||
# OS type and variant (generic is often fine for appliances)
|
||||
os = {
|
||||
type = "hvm"; # Hardware Virtual Machine
|
||||
variant = "generic";
|
||||
};
|
||||
|
||||
# No graphical output (headless VM)
|
||||
graphics = {
|
||||
type = "none";
|
||||
};
|
||||
|
||||
# Boot from UEFI
|
||||
boot = {
|
||||
uefi = true;
|
||||
};
|
||||
|
||||
# Optional: Console for debugging
|
||||
console = {
|
||||
type = "pty";
|
||||
targetType = "serial";
|
||||
targetPort = 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -22,14 +22,11 @@ in
|
|||
name = "bulk-pool";
|
||||
driver = "dir";
|
||||
config = {
|
||||
# This path points to your larger storage mount.
|
||||
# Ensure this directory exists before rebuilding.
|
||||
source = "/storage/incus-data";
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
# Update the default profile to use the new pools.
|
||||
profiles = [
|
||||
{
|
||||
name = "default";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue