···
cfg = config.virtualisation.vswitch;
16
-
virtualisation.vswitch.enable = mkOption {
12
+
options.virtualisation.vswitch = {
21
-
Enable Open vSwitch. A configuration
22
-
daemon (ovs-server) will be started.
17
+
Whether to enable Open vSwitch. A configuration daemon (ovs-server)
27
-
virtualisation.vswitch.package = mkOption {
22
+
package = mkOption {
default = pkgs.openvswitch;
Open vSwitch package to use.
34
+
Whether to start racoon service for openvswitch.
38
-
config = mkIf cfg.enable (let
39
+
config = mkIf cfg.enable (let
# Where the communication sockets live
runDir = "/var/run/openvswitch";
···
# Where the config database live (can't be in nix-store)
stateDir = "/var/db/openvswitch";
46
-
# The path to the an initialized version of the database
47
+
# The path to the an initialized version of the database
db = pkgs.stdenv.mkDerivation {
···
buildInputs = with pkgs; [
55
+
installPhase = "mkdir -p $out";
62
-
environment.systemPackages = [ cfg.package ];
60
+
environment.systemPackages = [ cfg.package pkgs.ipsecTools ];
boot.kernelModules = [ "tun" "openvswitch" ];
···
restartTriggers = [ db cfg.package ];
# Create the config database
mkdir -p /var/db/openvswitch
···
chmod -R +w /var/db/openvswitch
88
-
serviceConfig.ExecStart =
90
-
${cfg.package}/bin/ovsdb-server \
91
-
--remote=punix:${runDir}/db.sock \
92
-
--private-key=db:Open_vSwitch,SSL,private_key \
93
-
--certificate=db:Open_vSwitch,SSL,certificate \
94
-
--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
95
-
--unixctl=ovsdb.ctl.sock \
96
-
/var/db/openvswitch/conf.db
98
-
serviceConfig.Restart = "always";
99
-
serviceConfig.RestartSec = 3;
89
+
${cfg.package}/bin/ovsdb-server \
90
+
--remote=punix:${runDir}/db.sock \
91
+
--private-key=db:Open_vSwitch,SSL,private_key \
92
+
--certificate=db:Open_vSwitch,SSL,certificate \
93
+
--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
94
+
--unixctl=ovsdb.ctl.sock \
95
+
--pidfile=/var/run/openvswitch/ovsdb.pid \
97
+
/var/db/openvswitch/conf.db
101
+
PIDFile = "/var/run/openvswitch/ovsdb.pid";
${cfg.package}/bin/ovs-vsctl --timeout 3 --retry --no-wait init
systemd.services.vswitchd = {
···
bindsTo = [ "ovsdb.service" ];
after = [ "ovsdb.service" ];
112
-
serviceConfig.ExecStart = ''${cfg.package}/bin/ovs-vswitchd'';
116
+
${cfg.package}/bin/ovs-vswitchd \
117
+
--pidfile=/var/run/openvswitch/ovs-vswitchd.pid \
120
+
PIDFile = "/var/run/openvswitch/ovs-vswitchd.pid";
127
+
services.racoon.enable = true;
128
+
services.racoon.configPath = "${runDir}/ipsec/etc/racoon/racoon.conf";
130
+
networking.firewall.extraCommands = ''
131
+
iptables -I INPUT -t mangle -p esp -j MARK --set-mark 1/1
132
+
iptables -I INPUT -t mangle -p udp --dport 4500 -j MARK --set-mark 1/1
135
+
systemd.services.ovs-monitor-ipsec = {
136
+
description = "Open_vSwitch Ipsec Daemon";
137
+
wantedBy = [ "multi-user.target" ];
138
+
requires = [ "racoon.service" ];
139
+
after = [ "vswitchd.service" ];
140
+
environment.UNIXCTLPATH = "/tmp/ovsdb.ctl.sock";
143
+
${cfg.package}/bin/ovs-monitor-ipsec \
144
+
--root-prefix ${runDir}/ipsec \
145
+
--pidfile /var/run/openvswitch/ovs-monitor-ipsec.pid \
146
+
--monitor --detach \
147
+
unix:/var/run/openvswitch/db.sock
149
+
PIDFile = "/var/run/openvswitch/ovs-monitor-ipsec.pid";
154
+
rm -r ${runDir}/ipsec/etc/racoon/certs || true
155
+
mkdir -p ${runDir}/ipsec/{etc/racoon,etc/init.d/,usr/sbin/}
156
+
ln -fs ${pkgs.ipsecTools}/bin/setkey ${runDir}/ipsec/usr/sbin/setkey
157
+
ln -fs ${pkgs.writeScript "racoon-restart" ''
158
+
#!${pkgs.stdenv.shell}
159
+
/var/run/current-system/sw/bin/systemctl $1 racoon
160
+
''} ${runDir}/ipsec/etc/init.d/racoon