diff options
author | Chris Farmiloe <chrisfarms@gmail.com> | 2014-06-12 15:16:38 +0200 |
---|---|---|
committer | Michael Raskin <7c6f434c@mail.ru> | 2014-09-02 01:48:50 +0400 |
commit | 8ef11bb0ee4567826d9a7509ea2c8f1e226bcebf (patch) | |
tree | b9fa9a04a636b9c5f4d6c17d42fbc6ce7b4792b7 /nixos | |
parent | 9deb7f8aae431ed7725cfaa13edf8645d19d91f2 (diff) | |
download | nixlib-8ef11bb0ee4567826d9a7509ea2c8f1e226bcebf.tar nixlib-8ef11bb0ee4567826d9a7509ea2c8f1e226bcebf.tar.gz nixlib-8ef11bb0ee4567826d9a7509ea2c8f1e226bcebf.tar.bz2 nixlib-8ef11bb0ee4567826d9a7509ea2c8f1e226bcebf.tar.lz nixlib-8ef11bb0ee4567826d9a7509ea2c8f1e226bcebf.tar.xz nixlib-8ef11bb0ee4567826d9a7509ea2c8f1e226bcebf.tar.zst nixlib-8ef11bb0ee4567826d9a7509ea2c8f1e226bcebf.zip |
add openvswitch package + basic nixos module to enable it
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/virtualisation/libvirtd.nix | 11 | ||||
-rw-r--r-- | nixos/modules/virtualisation/openvswitch.nix | 120 |
3 files changed, 129 insertions, 3 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 045eb469de94..76d1ed8a9d43 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -365,6 +365,7 @@ ./virtualisation/docker.nix ./virtualisation/libvirtd.nix #./virtualisation/nova.nix + ./virtualisation/openvswitch.nix ./virtualisation/virtualbox-guest.nix #./virtualisation/xen-dom0.nix ] diff --git a/nixos/modules/virtualisation/libvirtd.nix b/nixos/modules/virtualisation/libvirtd.nix index d7d700d88412..ed157bba8821 100644 --- a/nixos/modules/virtualisation/libvirtd.nix +++ b/nixos/modules/virtualisation/libvirtd.nix @@ -7,6 +7,7 @@ with lib; let cfg = config.virtualisation.libvirtd; + vswitch = config.virtualisation.vswitch; configFile = pkgs.writeText "libvirtd.conf" '' unix_sock_group = "libvirtd" unix_sock_rw_perms = "0770" @@ -75,10 +76,14 @@ in wantedBy = [ "multi-user.target" ]; after = [ "systemd-udev-settle.service" ]; - path = - [ pkgs.bridge_utils pkgs.dmidecode pkgs.dnsmasq + path = [ + pkgs.bridge_utils + pkgs.dmidecode + pkgs.dnsmasq pkgs.ebtables - ] ++ optional cfg.enableKVM pkgs.qemu_kvm; + ] + ++ optional cfg.enableKVM pkgs.qemu_kvm + ++ optional vswitch.enable vswitch.package; preStart = '' diff --git a/nixos/modules/virtualisation/openvswitch.nix b/nixos/modules/virtualisation/openvswitch.nix new file mode 100644 index 000000000000..2070dd0f7839 --- /dev/null +++ b/nixos/modules/virtualisation/openvswitch.nix @@ -0,0 +1,120 @@ +# Systemd services for openvswitch + +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.virtualisation.vswitch; + +in + +{ + # ------------------------------------------------------------ + + options = { + + virtualisation.vswitch.enable = mkOption { + type = types.bool; + default = false; + description = + '' + Enable Open vSwitch. A configuration + daemon (ovs-server) will be started. + ''; + }; + + + virtualisation.vswitch.package = mkOption { + type = types.package; + default = pkgs.openvswitch; + description = + '' + Open vSwitch package to use. + ''; + }; + + }; + + # ------------------------------------------------------------ + + 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"; + + # The path to the an initialized version of the database + db = pkgs.stdenv.mkDerivation { + name = "vswitch.db"; + unpackPhase = "true"; + buildPhase = "true"; + buildInputs = with pkgs; [ + cfg.package + ]; + installPhase = + '' + ensureDir $out/ + ''; + }; + + in { + + environment.systemPackages = [ cfg.package ]; + + boot.kernelModules = [ "tun" "openvswitch" ]; + + boot.extraModulePackages = [ cfg.package ]; + + systemd.services.ovsdb = { + description = "Open_vSwitch Database Server"; + wantedBy = [ "multi-user.target" ]; + after = [ "systemd-udev-settle.service" ]; + wants = [ "vswitchd.service" ]; + path = [ cfg.package ]; + restartTriggers = [ db cfg.package ]; + # Create the config database + preStart = + '' + mkdir -p ${runDir} + mkdir -p /var/db/openvswitch + chmod +w /var/db/openvswitch + if [[ ! -e /var/db/openvswitch/conf.db ]]; then + ${cfg.package}/bin/ovsdb-tool create \ + "/var/db/openvswitch/conf.db" \ + "${cfg.package}/share/openvswitch/vswitch.ovsschema" + fi + chmod -R +w /var/db/openvswitch + ''; + serviceConfig.ExecStart = + '' + ${cfg.package}/bin/ovsdb-server \ + --remote=punix:${runDir}/db.sock \ + --private-key=db:Open_vSwitch,SSL,private_key \ + --certificate=db:Open_vSwitch,SSL,certificate \ + --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \ + --unixctl=ovsdb.ctl.sock \ + /var/db/openvswitch/conf.db + ''; + serviceConfig.Restart = "always"; + serviceConfig.RestartSec = 3; + postStart = + '' + ${cfg.package}/bin/ovs-vsctl --timeout 3 --retry --no-wait init + ''; + + }; + + systemd.services.vswitchd = { + description = "Open_vSwitch Daemon"; + bindsTo = [ "ovsdb.service" ]; + after = [ "ovsdb.service" ]; + path = [ cfg.package ]; + serviceConfig.ExecStart = ''${cfg.package}/bin/ovs-vswitchd''; + }; + + }); + +} |