summaryrefslogtreecommitdiff
path: root/os/srv
diff options
context:
space:
mode:
authoradikro <adikro@disroot.org>2026-05-09 21:06:23 +0200
committeradikro <adikro@disroot.org>2026-05-09 21:06:23 +0200
commitbaf1cf5664b481de17849c97dc683fa81ade1c2e (patch)
tree0836096c9104559d27341d7b99c7c032cf0743ef /os/srv
parent18e7f651ce33b1544178f444c6bd3fbaf44fc831 (diff)
laptop sync
Diffstat (limited to 'os/srv')
-rw-r--r--os/srv/default.nix2
-rw-r--r--os/srv/opnsense.nix102
2 files changed, 104 insertions, 0 deletions
diff --git a/os/srv/default.nix b/os/srv/default.nix
index 4f520a5..7f87cfd 100644
--- a/os/srv/default.nix
+++ b/os/srv/default.nix
@@ -18,5 +18,7 @@
./virtualization.nix
./vpn.nix
./yggdrasil.nix
+
+ ./opnsense.nix
];
}
diff --git a/os/srv/opnsense.nix b/os/srv/opnsense.nix
new file mode 100644
index 0000000..7855e46
--- /dev/null
+++ b/os/srv/opnsense.nix
@@ -0,0 +1,102 @@
+{
+ config,
+ lib,
+ inputs,
+ ...
+}:
+let
+ cfg = config.os.srv.opnsense;
+ makePciArgs =
+ ids:
+ builtins.concatLists (
+ map (id: [
+ "-device"
+ "vfio-pci,host=${id}"
+ ]) ids
+ );
+in
+{
+ imports = [ inputs.microvm.nixosModules.host ];
+ options.os.srv.opnsense = {
+ enable = lib.mkEnableOption "enables an opnsense microvm";
+ pciIDs = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ default = [ ];
+ example = [
+ "01:00.0"
+ "01:00.1"
+ "01:00.2"
+ "01:00.3"
+ ];
+ description = "List of PCI bus addresses to pass through to the VM.";
+ };
+ vendorIDs = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ default = [ ];
+ example = [ "8086:1521" ];
+ description = "List of Vendor:Device IDs to bind to the vfio-pci driver.";
+ };
+ imagePath = lib.mkOption {
+ type = lib.types.path;
+ default = /var/lib/microvm/images/opnsense.qcow2;
+ description = "Path to the OPNsense qcow2 image";
+ };
+ };
+ config = lib.mkIf cfg.enable {
+ networking = {
+ bridges."br-lan".interfaces = [ ];
+
+ # TODO configure this
+ interfaces."br-lan".ipv4.addresses = [
+ {
+ address = "10.0.0.2";
+ prefixLenght = 16;
+ }
+ ];
+ };
+ boot = {
+ kernelParams = [
+ "intel_iommu=on"
+ "iommu=pt"
+ ];
+ kernelModules = [
+ "vfio_pci"
+ "vfio"
+ "vfio_iommu_type1"
+ ];
+ extraModprobeConfig = ''
+ options vfio-pci ids=${lib.concatStringsSep "," cfg.vendorIDs}
+ '';
+ };
+ microvm.vms.opnsense = {
+ autostart = true;
+ config = {
+ imports = [ inputs.microvm.nixosModules.microvm ];
+
+ networking.hostName = "opnsense";
+
+ microvm = {
+ vcpu = 2;
+ mem = 4096;
+ hypervisor = "qemu";
+
+ interfaces = [
+ {
+ type = "bridge";
+ id = "vm-lan";
+ bridge = "br-lan";
+ }
+ ];
+
+ qemu.extraArgs = [
+ "-machine"
+ "q35,accel=kvm,kernel-irqchip=on"
+ "-cpu"
+ "host"
+ ]
+ ++ (makePciArgs cfg.pciIDs);
+ };
+ };
+ };
+ };
+}