From 35f74c36082027f6d02b9a0f907865e333cb47bb Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Thu, 22 Nov 2018 08:33:10 +0900 Subject: [PATCH] mininet: init at 2.3.0d4 (#41261) Mininet (https://github.com/mininet/mininet) is a popular network emulator that glues several components such as network namespaces, traffic control commands into a set of python bindings. It is then "easy" to describe a topology and run experiments on it. --- nixos/modules/module-list.nix | 1 + nixos/modules/programs/mininet.nix | 39 +++++++++++++++ pkgs/tools/virtualization/mininet/default.nix | 48 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + pkgs/top-level/python-packages.nix | 2 + 5 files changed, 92 insertions(+) create mode 100644 nixos/modules/programs/mininet.nix create mode 100644 pkgs/tools/virtualization/mininet/default.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 7327d4ac4dfd..ae5084ca2a2a 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -103,6 +103,7 @@ ./programs/less.nix ./programs/light.nix ./programs/mosh.nix + ./programs/mininet.nix ./programs/mtr.nix ./programs/nano.nix ./programs/npm.nix diff --git a/nixos/modules/programs/mininet.nix b/nixos/modules/programs/mininet.nix new file mode 100644 index 000000000000..ecc924325e6b --- /dev/null +++ b/nixos/modules/programs/mininet.nix @@ -0,0 +1,39 @@ +# Global configuration for mininet +# kernel must have NETNS/VETH/SCHED +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.mininet; + + generatedPath = with pkgs; makeSearchPath "bin" [ + iperf ethtool iproute socat + ]; + + pyEnv = pkgs.python.withPackages(ps: [ ps.mininet-python ]); + + mnexecWrapped = pkgs.runCommand "mnexec-wrapper" + { buildInputs = [ pkgs.makeWrapper pkgs.pythonPackages.wrapPython ]; } + '' + makeWrapper ${pkgs.mininet}/bin/mnexec \ + $out/bin/mnexec \ + --prefix PATH : "${generatedPath}" + + ln -s ${pyEnv}/bin/mn $out/bin/mn + + # mn errors out without a telnet binary + # pkgs.telnet brings an undesired ifconfig into PATH see #43105 + ln -s ${pkgs.telnet}/bin/telnet $out/bin/telnet + ''; +in +{ + options.programs.mininet.enable = mkEnableOption "Mininet"; + + config = mkIf cfg.enable { + + virtualisation.vswitch.enable = true; + + environment.systemPackages = [ mnexecWrapped ]; + }; +} diff --git a/pkgs/tools/virtualization/mininet/default.nix b/pkgs/tools/virtualization/mininet/default.nix new file mode 100644 index 000000000000..a2f4b1650876 --- /dev/null +++ b/pkgs/tools/virtualization/mininet/default.nix @@ -0,0 +1,48 @@ +{ stdenv, lib, fetchFromGitHub +, which +, python +, help2man +}: + +let + pyEnv = python.withPackages(ps: [ ps.setuptools ]); +in +stdenv.mkDerivation rec { + name = "mininet-${version}"; + version = "2.3.0d4"; + + outputs = [ "out" "py" ]; + + src = fetchFromGitHub { + owner = "mininet"; + repo = "mininet"; + rev = version; + sha256 = "02hsqa7r5ykj8m1ycl32xwn1agjrw78wkq87xif0dl2vkzln41i4"; + }; + + buildFlags = [ "mnexec" ]; + makeFlags = [ "PREFIX=$(out)" ]; + + pythonPath = [ python.pkgs.setuptools ]; + buildInputs = [ python which help2man ]; + + installTargets = [ "install-mnexec" "install-manpages" ]; + + preInstall = '' + mkdir -p $out $py + # without --root, install fails + ${pyEnv.interpreter} setup.py install --root="/" --prefix=$py + ''; + + doCheck = false; + + + meta = with lib; { + description = "Emulator for rapid prototyping of Software Defined Networks"; + license = { + fullName = "Mininet 2.3.0d4 License"; + }; + homepage = https://github.com/mininet/mininet; + maintainers = with maintainers; [ teto ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 507e250f6436..67cce126330f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -21734,6 +21734,8 @@ with pkgs; scotch = callPackage ../applications/science/math/scotch { }; + mininet = callPackage ../tools/virtualization/mininet { }; + msieve = callPackage ../applications/science/math/msieve { }; weka = callPackage ../applications/science/math/weka { }; diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 9019e28b724b..726c6f3b58b4 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -422,6 +422,8 @@ in { monty = callPackage ../development/python-modules/monty { }; + mininet-python = (toPythonModule (pkgs.mininet.override{ inherit python; })).py; + mpi4py = callPackage ../development/python-modules/mpi4py { mpi = pkgs.openmpi; };