summary refs log tree commit diff
path: root/nixos/modules/programs/mininet.nix
blob: ecc924325e6b0613871fa105d5dd0c74f4d5f092 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 ];
  };
}