about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhexclover <47456195+hexclover@users.noreply.github.com>2023-12-07 15:19:00 +0800
committerMatthieu Coudron <886074+teto@users.noreply.github.com>2023-12-22 19:15:14 +0100
commit66bda599f409f9834c6fd6abc602e452a5c16b61 (patch)
tree914a7eafeb56f074a6012ce0059f34a68273eaa0
parentea8bb2df93b9b8db2619328e690da962eaf99862 (diff)
mininet, nixos/mininet: Wrap executables in the package, not the module
Also move the `mn` executable from the Python module to the main package.
-rw-r--r--nixos/modules/programs/mininet.nix35
-rw-r--r--pkgs/tools/virtualization/mininet/default.nix42
2 files changed, 41 insertions, 36 deletions
diff --git a/nixos/modules/programs/mininet.nix b/nixos/modules/programs/mininet.nix
index 01ffd811e70e2..3568736854d8e 100644
--- a/nixos/modules/programs/mininet.nix
+++ b/nixos/modules/programs/mininet.nix
@@ -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 ];
   };
 }
diff --git a/pkgs/tools/virtualization/mininet/default.nix b/pkgs/tools/virtualization/mininet/default.nix
index c33389861dd0a..3d7339bf56b63 100644
--- a/pkgs/tools/virtualization/mininet/default.nix
+++ b/pkgs/tools/virtualization/mininet/default.nix
@@ -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;