mininet, nixos/mininet: Wrap executables in the package, not the module

Also move the `mn` executable from the Python module to the main package.
This commit is contained in:
hexclover 2023-12-07 15:19:00 +08:00 committed by Matthieu Coudron
parent ea8bb2df93
commit 66bda599f4
2 changed files with 41 additions and 36 deletions

View File

@ -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");
@ -47,6 +14,6 @@ in
virtualisation.vswitch.enable = true;
environment.systemPackages = [ mnexecWrapped ];
environment.systemPackages = [ pkgs.mininet ];
};
}

View File

@ -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";
@ -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 ];
@ -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;