Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to declaratively configure visible bridges #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Below is a fragment of a NixOS configuration that enables Proxmox VE.

To get internet in your VMs, you need to add a network device to the VM, connected to a bridge. To get this working, follow this 2 steps:

1. Create the bridge in `System->Network->Create->Linux Bridge`. This operation has no effect on your system and is just a quirk for Proxmox to know the existence of your bridge.
1. Set the list of bridges in `services.proxmox-ve.bridges` option. This is the list of bridges that will be visible in Proxmox web interface. Note that this option doesn't affect your OS level network config in any way.
2. Configure your networking through NixOS configuration so that the bridge you created in the Proxmox web interface actually exists!

### Example NixOS networking configurations
Expand All @@ -104,6 +104,10 @@ Any kind of advanced networking configuration is possible through the usual NixO
#### With `systemd-networkd`

```nix
# Make vmbr0 bridge visible in Proxmox web interface
services.proxmox-ve.bridges = [ "vmbr0" ];

# Actually set up the vmbr0 bridge
systemd.network.networks."10-lan" = {
matchConfig.Name = [ "ens18" ];
networkConfig = {
Expand Down Expand Up @@ -131,6 +135,10 @@ systemd.network.networks."10-lan-bridge" = {
### With scripted networking

```nix
# Make vmbr0 bridge visible in Proxmox web interface
services.proxmox-ve.bridges = [ "vmbr0" ];

# Actually set up the vmbr0 bridge
networking.bridges.vmbr0.interfaces = [ "ens18" ];
networking.interfaces.vmbr0.useDHCP = lib.mkDefault true;
```
Expand Down
26 changes: 26 additions & 0 deletions modules/proxmox-ve/bridges.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
config,
lib,
...
}:
let
cfg = config.services.proxmox-ve.bridges;
in
{
options.services.proxmox-ve.bridges = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "List of Linux or OVS bridges visible in Proxmox web interface. This option has no effect on OS level network config.";
};

config = lib.mkIf (builtins.length cfg > 0) {
environment.etc."network/interfaces" = {
mode = "0644";
text = lib.concatMapStringsSep "\n" (br: ''
auto ${br}
iface ${br} inet static
bridge_ports none
'') cfg;
};
};
}
1 change: 1 addition & 0 deletions modules/proxmox-ve/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ in
];

imports = [
./bridges.nix
./cluster.nix
# ./firewall.nix
# ./ha-manager.nix
Expand Down