feat: Some vm stuff and rsyncd

This commit is contained in:
uttarayan21
2025-02-21 15:11:38 +05:30
parent 7b243d810d
commit a10ca460df
7 changed files with 55 additions and 103 deletions

View File

@@ -54,11 +54,11 @@
extra-experimental-features = "nix-command flakes auto-allocate-uids"; extra-experimental-features = "nix-command flakes auto-allocate-uids";
trusted-users = ["root" "servius"]; trusted-users = ["root" "servius"];
substituters = [ substituters = [
"https://nix-community.cachix.org" # "https://nix-community.cachix.org"
# "https://sh.darksailor.dev" # "https://sh.darksailor.dev"
]; ];
trusted-public-keys = [ trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" # "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
# "mirai:bcVPoFGBZ0i7JAKMXIqLj2GY3CulLC4kP7rQyqes1RM=" # "mirai:bcVPoFGBZ0i7JAKMXIqLj2GY3CulLC4kP7rQyqes1RM="
]; ];
}; };
@@ -241,6 +241,7 @@
# Allow unfree packages # Allow unfree packages
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;
nixpkgs.config.cudaSupport = true;
fonts.fontconfig.enable = true; fonts.fontconfig.enable = true;
fonts.fontDir.enable = true; fonts.fontDir.enable = true;
@@ -253,6 +254,7 @@
winetricks winetricks
wineWowPackages.waylandFull wineWowPackages.waylandFull
virt-manager
gparted gparted
nvtopPackages.nvidia nvtopPackages.nvidia
quickemu quickemu

View File

@@ -3,6 +3,7 @@
./samba.nix ./samba.nix
./sunshine.nix ./sunshine.nix
./ollama.nix ./ollama.nix
./rsyncd.nix
]; ];
services = { services = {
hardware.openrgb.enable = true; hardware.openrgb.enable = true;

View File

@@ -5,8 +5,7 @@
host = "127.0.0.1"; host = "127.0.0.1";
loadModels = ["deepseek-r1:7b" "deepseek-r1:14b"]; loadModels = ["deepseek-r1:7b" "deepseek-r1:14b"];
port = 11434; port = 11434;
package = pkgs.ollama-cuda; acceleration = "cuda";
# acceleration = "cuda";
}; };
open-webui = { open-webui = {
enable = false; enable = false;

View File

@@ -0,0 +1,19 @@
{...}: {
services.rsyncd = {
enable = false;
# openFirewall = true;
settings = {
media = {
path = "/media";
comment = "Media";
"read only" = true;
# "use chroot" = "no";
list = true;
uid = "root";
gid = "root";
};
};
};
networking.firewall.allowedTCPPorts = [873];
networking.firewall.allowedUDPPorts = [873];
}

View File

@@ -1,6 +1,5 @@
{ {
imports = [ imports = [
# ./vfio.nix
./win11.nix ./win11.nix
]; ];
} }

View File

View File

@@ -1,31 +1,34 @@
{ config, pkgs, lib, ... }:
{ {
config,
pkgs,
lib,
...
}: {
virtualisation.libvirtd.enable = true; virtualisation.libvirtd.enable = true;
virtualisation.libvirtd.qemu.ovmf.enable = true; virtualisation.libvirtd.qemu.ovmf.enable = true;
virtualisation.libvirtd.qemu.swtpm.enable = true; virtualisation.libvirtd.qemu.swtpm.enable = true;
# IOMMU and VFIO settings # IOMMU and VFIO settings
boot.kernelParams = [ # boot.kernelParams = [
"amd_iommu=on" # Use "intel_iommu=on" for Intel CPUs # "amd_iommu=on" # Use "intel_iommu=on" for Intel CPUs
"iommu=pt" # "iommu=pt"
"vfio-pci.ids=10de:2504,10de:228e" # Replace with your GPU's vendor:device IDs # "vfio-pci.ids=10de:2504,10de:228e" # Replace with your GPU's vendor:device IDs
]; # ];
boot.kernelModules = [ # boot.kernelModules = [
"vfio_pci" # "vfio_pci"
"vfio" # "vfio"
"vfio_iommu_type1" # "vfio_iommu_type1"
"vfio_virqfd" # "vfio_virqfd"
]; # ];
#
# Early loading of VFIO # # Early loading of VFIO
boot.initrd.kernelModules = [ # boot.initrd.kernelModules = [
"vfio_pci" # "vfio_pci"
"vfio" # "vfio"
"vfio_iommu_type1" # "vfio_iommu_type1"
"vfio_virqfd" # "vfio_virqfd"
]; # ];
# Define the Windows 11 VM # Define the Windows 11 VM
virtualisation.libvirtd.qemu.verbatimConfig = '' virtualisation.libvirtd.qemu.verbatimConfig = ''
@@ -52,79 +55,7 @@
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
RemainAfterExit = "yes"; RemainAfterExit = "yes";
ExecStart = let ExecStart = "${pkgs.libvirt}/bin/virsh define ${./windows.xml} && ${pkgs.libvirt}/bin/virsh start win11";
win11xml = pkgs.writeText "win11.xml" ''
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>win11</name>
<memory unit='GiB'>16</memory>
<vcpu placement='static'>8</vcpu>
<cpu mode='host-passthrough' check='none'>
<topology sockets='1' dies='1' cores='4' threads='2'/>
<feature policy='require' name='topoext'/>
</cpu>
<os>
<type arch='x86_64' machine='pc-q35-8.0'>hvm</type>
<loader readonly='yes' type='pflash'>/run/libvirt/nix-ovmf/OVMF_CODE.fd</loader>
<nvram>/var/lib/libvirt/qemu/nvram/win11_VARS.fd</nvram>
<boot dev='hd'/>
<boot dev='cdrom'/>
</os>
<features>
<acpi/>
<apic/>
<hyperv mode='custom'>
<relaxed state='on'/>
<vapic state='on'/>
<spinlocks state='on' retries='8191'/>
<vendor_id state='on' value='123456789123'/>
</hyperv>
<vmport state='off'/>
</features>
<devices>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' discard='unmap'/>
<source file='/var/lib/libvirt/images/win11.qcow2'/>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/Win11.iso'/>
<target dev='sda' bus='sata'/>
<readonly/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/virtio-win.iso'/>
<target dev='sdb' bus='sata'/>
<readonly/>
</disk>
<interface type='bridge'>
<source bridge='virbr0'/>
<model type='virtio'/>
</interface>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</source>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x01' slot='0x00' function='0x1'/>
</source>
</hostdev>
<memballoon model='virtio'/>
</devices>
<qemu:commandline>
<qemu:arg value='-cpu'/>
<qemu:arg value='host,hv_time,kvm=off,hv_vendor_id=null'/>
<qemu:arg value='-device'/>
<qemu:arg value='ivshmem-plain,memdev=looking-glass'/>
<qemu:arg value='-object'/>
<qemu:arg value='memory-backend-file,id=looking-glass,share=on,mem-path=/dev/shm/looking-glass,size=32M'/>
</qemu:commandline>
</domain>
'';
in "${pkgs.libvirt}/bin/virsh define ${win11xml} && ${pkgs.libvirt}/bin/virsh start win11";
ExecStop = "${pkgs.libvirt}/bin/virsh shutdown win11"; ExecStop = "${pkgs.libvirt}/bin/virsh shutdown win11";
}; };
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
@@ -152,3 +83,4 @@
# Optional: Enable looking glass for low-latency VM display # Optional: Enable looking glass for low-latency VM display
} }