Skip to content

Commit

Permalink
mininet, nixos/mininet: Wrap executables in the package, not the module
Browse files Browse the repository at this point in the history
Also move the `mn` executable from the Python module to the main package.
  • Loading branch information
hexclover authored and teto committed Dec 22, 2023
1 parent ea8bb2d commit 66bda59
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
35 changes: 1 addition & 34 deletions nixos/modules/programs/mininet.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,6 @@ with lib;

let
cfg = config.programs.mininet;

telnet = pkgs.runCommand "inetutils-telnet"
{ }
''
mkdir -p $out/bin
ln -s ${pkgs.inetutils}/bin/telnet $out/bin
'';

generatedPath = with pkgs; makeSearchPath "bin" [
iperf
ethtool
iproute2
socat
# mn errors out without a telnet binary
# pkgs.inetutils brings an undesired ifconfig into PATH see #43105
nettools
telnet
];

pyEnv = pkgs.python3.withPackages (ps: [ ps.mininet-python ]);

mnexecWrapped = pkgs.runCommand "mnexec-wrapper"
{ nativeBuildInputs = [ pkgs.makeWrapper pkgs.python3Packages.wrapPython ]; }
''
makeWrapper ${pkgs.mininet}/bin/mnexec \
$out/bin/mnexec \
--prefix PATH : "${generatedPath}"
makeWrapper ${pyEnv}/bin/mn \
$out/bin/mn \
--prefix PYTHONPATH : "${pyEnv}/${pyEnv.sitePackages}" \
--prefix PATH : "${generatedPath}"
'';
in
{
options.programs.mininet.enable = mkEnableOption (lib.mdDoc "Mininet");
Expand All @@ -47,6 +14,6 @@ in

virtualisation.vswitch.enable = true;

environment.systemPackages = [ mnexecWrapped ];
environment.systemPackages = [ pkgs.mininet ];
};
}
42 changes: 40 additions & 2 deletions pkgs/tools/virtualization/mininet/default.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
{ stdenv, lib, fetchFromGitHub
, runCommand
, which
, python3
, help2man
, makeWrapper
, ethtool
, inetutils
, iperf
, iproute2
, nettools
, socat
}:

let
pyEnv = python3.withPackages(ps: [ ps.setuptools ]);

telnet = runCommand "inetutils-telnet"
{ }
''
mkdir -p "$out/bin"
ln -s "${inetutils}"/bin/telnet "$out/bin"
'';

generatedPath = lib.makeSearchPath "bin" [
iperf
ethtool
iproute2
socat
# mn errors out without a telnet binary
# pkgs.inetutils brings an undesired ifconfig into PATH see #43105
nettools
telnet
];

in
stdenv.mkDerivation rec {
pname = "mininet";
Expand All @@ -24,7 +51,7 @@ stdenv.mkDerivation rec {
makeFlags = [ "PREFIX=$(out)" ];

pythonPath = [ python3.pkgs.setuptools ];
nativeBuildInputs = [ help2man ];
nativeBuildInputs = [ help2man makeWrapper python3.pkgs.wrapPython ];

propagatedBuildInputs = [ python3 which ];

Expand All @@ -33,7 +60,18 @@ stdenv.mkDerivation rec {
preInstall = ''
mkdir -p $out $py
# without --root, install fails
${pyEnv.interpreter} setup.py install --root="/" --prefix=$py
"${pyEnv.interpreter}" setup.py install \
--root="/" \
--prefix="$py" \
--install-scripts="$out/bin"
'';

postFixup = ''
wrapPythonProgramsIn "$out/bin" "$py $pythonPath"
wrapProgram "$out/bin/mnexec" \
--prefix PATH : "${generatedPath}"
wrapProgram "$out/bin/mn" \
--prefix PATH : "${generatedPath}"
'';

doCheck = false;
Expand Down

0 comments on commit 66bda59

Please sign in to comment.