1 # Systemd services for openvswitch
3 { config, lib, pkgs, ... }:
8 cfg = config.virtualisation.vswitch;
12 options.virtualisation.vswitch = {
17 Whether to enable Open vSwitch. A configuration daemon (ovs-server)
22 resetOnStart = mkOption {
26 Whether to reset the Open vSwitch configuration database to a default
27 configuration on every start of the systemd `ovsdb.service`.
31 package = mkPackageOption pkgs "openvswitch" { };
34 config = mkIf cfg.enable (let
36 # Where the communication sockets live
37 runDir = "/run/openvswitch";
39 # The path to the an initialized version of the database
40 db = pkgs.stdenv.mkDerivation {
44 buildInputs = with pkgs; [
47 installPhase = "mkdir -p $out";
51 environment.systemPackages = [ cfg.package ];
52 boot.kernelModules = [ "tun" "openvswitch" ];
54 boot.extraModulePackages = [ cfg.package ];
56 systemd.services.ovsdb = {
57 description = "Open_vSwitch Database Server";
58 wantedBy = [ "multi-user.target" ];
59 after = [ "systemd-udev-settle.service" ];
60 path = [ cfg.package ];
61 restartTriggers = [ db cfg.package ];
62 # Create the config database
66 mkdir -p /var/db/openvswitch
67 chmod +w /var/db/openvswitch
68 ${optionalString cfg.resetOnStart "rm -f /var/db/openvswitch/conf.db"}
69 if [[ ! -e /var/db/openvswitch/conf.db ]]; then
70 ${cfg.package}/bin/ovsdb-tool create \
71 "/var/db/openvswitch/conf.db" \
72 "${cfg.package}/share/openvswitch/vswitch.ovsschema"
74 chmod -R +w /var/db/openvswitch
75 if ${cfg.package}/bin/ovsdb-tool needs-conversion /var/db/openvswitch/conf.db | grep -q "yes"
77 echo "Performing database upgrade"
78 ${cfg.package}/bin/ovsdb-tool convert /var/db/openvswitch/conf.db
80 echo "Database already up to date"
86 ${cfg.package}/bin/ovsdb-server \
87 --remote=punix:${runDir}/db.sock \
88 --private-key=db:Open_vSwitch,SSL,private_key \
89 --certificate=db:Open_vSwitch,SSL,certificate \
90 --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
91 --unixctl=ovsdb.ctl.sock \
92 --pidfile=/run/openvswitch/ovsdb.pid \
94 /var/db/openvswitch/conf.db
98 PIDFile = "/run/openvswitch/ovsdb.pid";
99 # Use service type 'forking' to correctly determine when ovsdb-server is ready.
103 ${cfg.package}/bin/ovs-vsctl --timeout 3 --retry --no-wait init
107 systemd.services.ovs-vswitchd = {
108 description = "Open_vSwitch Daemon";
109 wantedBy = [ "multi-user.target" ];
110 bindsTo = [ "ovsdb.service" ];
111 after = [ "ovsdb.service" ];
112 path = [ cfg.package ];
115 ${cfg.package}/bin/ovs-vswitchd \
116 --pidfile=/run/openvswitch/ovs-vswitchd.pid \
119 PIDFile = "/run/openvswitch/ovs-vswitchd.pid";
120 # Use service type 'forking' to correctly determine when vswitchd is ready.
130 (mkRemovedOptionModule [ "virtualisation" "vswitch" "ipsec" ] ''
131 OpenVSwitch IPSec functionality has been removed, because it depended on racoon,
132 which was removed from nixpkgs, because it was abanoded upstream.
136 meta.maintainers = with maintainers; [ netixx ];