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
52
modules/containers/haos.nix
Normal file
52
modules/containers/haos.nix
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{ config, pkgs, unstablePkgs, ... }:
|
||||
|
||||
{
|
||||
users.users.death916.extraGroups = [ "home-assistant" ];
|
||||
|
||||
services.home-assistant = {
|
||||
enable = true;
|
||||
package = unstablePkgs.home-assistant;
|
||||
extraComponents = [
|
||||
"analytics"
|
||||
"google_translate"
|
||||
"met"
|
||||
"radio_browser"
|
||||
"shopping_list"
|
||||
"isal"
|
||||
"wled"
|
||||
];
|
||||
extraPackages =
|
||||
python3Packages: with python3Packages; [
|
||||
pip
|
||||
];
|
||||
|
||||
config = {
|
||||
default_config = { };
|
||||
http = {
|
||||
use_x_forwarded_for = true;
|
||||
trusted_proxies = [
|
||||
"127.0.0.1"
|
||||
"::1"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
services.mosquitto = {
|
||||
enable = true;
|
||||
listeners = [
|
||||
{
|
||||
acl = [ "pattern readwrite #" ];
|
||||
settings.allow_anonymous = true;
|
||||
address = "0.0.0.0";
|
||||
port = 1883;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = [
|
||||
8123 # Home Assistant Web UI
|
||||
1883 # MQTT Broker
|
||||
];
|
||||
|
||||
}
|
||||
|
|
@ -11,8 +11,8 @@
|
|||
./restic.nix
|
||||
./monitoring.nix
|
||||
../../c2cscrape.nix
|
||||
# ../../containers/docker/immich.nix # Import the new Immich Docker container config
|
||||
../../../modules/containers/docker/dispatcharr/docker-compose.nix
|
||||
../../../modules/containers/haos.nix
|
||||
];
|
||||
arrSuite.enable = true;
|
||||
services.samba.shares.Media.path = "/media/storage/media";
|
||||
|
|
@ -52,11 +52,8 @@
|
|||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
|
||||
"d /storage/services/qbittorrent 0755 qbittorrent media_services - -"
|
||||
|
||||
"d /storage/services/qbittorrent/config 0755 qbittorrent media_services - -"
|
||||
|
||||
"d /media/storage/media/books/audio/podcasts/C2C 0777 c2c media_services - -"
|
||||
"d /storage/services/immich 0770 immich media_services -"
|
||||
"d /storage/services/immich/upload 0770 immich media_services -"
|
||||
|
|
@ -66,7 +63,6 @@
|
|||
"d /storage/services/immich/upload/profile 0770 immich media_services -"
|
||||
"d /storage/services/immich/upload/upload 0770 immich media_services -"
|
||||
"d /storage/services/immich/upload/backup 0770 immich media_services -"
|
||||
|
||||
"f /storage/services/immich/upload/library/.immich 0660 immich media_services -"
|
||||
"f /storage/services/immich/upload/thumbs/.immich 0660 immich media_services -"
|
||||
"f /storage/services/immich/upload/encoded-video/.immich 0660 immich media_services -"
|
||||
|
|
@ -99,19 +95,6 @@
|
|||
"-A"
|
||||
];
|
||||
};
|
||||
# c2c-scraper = {
|
||||
# image = "death916/c2cscrape:latest";
|
||||
# volumes = [
|
||||
# "/media/storage/media/books/audio/podcasts/C2C:/downloads"
|
||||
# "/media/storage/media/docker/volumes/c2cscrape:/app/data"
|
||||
# ];
|
||||
# user = "${toString config.users.users.c2c.uid}:${toString config.users.groups.media_services.gid}";
|
||||
# environment = {
|
||||
# TZ = "America/Los_Angeles";
|
||||
# };
|
||||
# autoStart = true;
|
||||
# extraOptions = [ "--dns=8.8.8.8" ];
|
||||
# };
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -134,14 +117,6 @@
|
|||
};
|
||||
};
|
||||
|
||||
services.homeassistant-vm = {
|
||||
enable = true;
|
||||
imagePath = "/var/lib/libvirt/images/haos.qcow2";
|
||||
memory = 6096;
|
||||
vcpus = 4;
|
||||
bridge = "br0";
|
||||
};
|
||||
|
||||
programs.nh = {
|
||||
enable = true;
|
||||
clean.enable = true;
|
||||
|
|
|
|||
|
|
@ -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