about summary refs log tree commit diff
path: root/pkgs/applications/networking/cluster
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-19 19:19:40 +0200
committerGitHub <noreply@github.com>2023-12-19 19:19:40 +0200
commitb6cad0fd94a9f6ce19a11e33910fa3a89a7ad38c (patch)
treed414def9ea701a0f50a93b3c9b4bf3c83b610ffa /pkgs/applications/networking/cluster
parentcf3205c5ef7813e2de3ffda8f25584106964403e (diff)
parentf12915c4e0c143774d3139d6accb7a66df252fb9 (diff)
Merge pull request #274220 from flokli/waagent-cleanups
waagent: cleanups
Diffstat (limited to 'pkgs/applications/networking/cluster')
-rw-r--r--pkgs/applications/networking/cluster/waagent/default.nix91
1 files changed, 47 insertions, 44 deletions
diff --git a/pkgs/applications/networking/cluster/waagent/default.nix b/pkgs/applications/networking/cluster/waagent/default.nix
index d71e9fb7fb7d4..45fc40384763a 100644
--- a/pkgs/applications/networking/cluster/waagent/default.nix
+++ b/pkgs/applications/networking/cluster/waagent/default.nix
@@ -1,25 +1,18 @@
-{ fetchFromGitHub,
-  findutils,
-  gnugrep,
-  gnused,
-  iproute2,
-  iptables,
-  lib,
-  nettools, # for hostname
-  openssh,
-  openssl,
-  parted,
-  procps, # for pidof,
-  python39, # the latest python version that waagent test against according to https://github.com/Azure/WALinuxAgent/blob/28345a55f9b21dae89472111635fd6e41809d958/.github/workflows/ci_pr.yml#L75
-  shadow, # for useradd, usermod
-  util-linux, # for (u)mount, fdisk, sfdisk, mkswap
+{ bash
+, coreutils
+, fetchFromGitHub
+, lib
+, python39
+, substituteAll
 }:
 
 let
   inherit (lib) makeBinPath;
+  # the latest python version that waagent test against according to https://github.com/Azure/WALinuxAgent/blob/28345a55f9b21dae89472111635fd6e41809d958/.github/workflows/ci_pr.yml#L75
+  python = python39;
 
 in
-python39.pkgs.buildPythonPackage rec {
+python.pkgs.buildPythonApplication rec {
   pname = "waagent";
   version = "2.8.0.11";
   src = fetchFromGitHub {
@@ -29,44 +22,54 @@ python39.pkgs.buildPythonPackage rec {
     sha256 = "0fvjanvsz1zyzhbjr2alq5fnld43mdd776r2qid5jy5glzv0xbhf";
   };
   patches = [
-    # Suppress the following error when waagent try to configure sshd:
+    # Suppress the following error when waagent tries to configure sshd:
     # Read-only file system: '/etc/ssh/sshd_config'
     ./dont-configure-sshd.patch
   ];
   doCheck = false;
 
-  buildInputs = with python39.pkgs; [ distro ];
-  runtimeDeps = [
-    findutils
-    gnugrep
-    gnused
-    iproute2
-    iptables
-    nettools # for hostname
-    openssh
-    openssl
-    parted
-    procps # for pidof
-    shadow # for useradd, usermod
-    util-linux # for (u)mount, fdisk, sfdisk, mkswap
-  ];
+  # azure-product-uuid chmod rule invokes chmod to change the mode of
+  # product_uuid (which is not a device itself).
+  # Replace this with an absolute path.
+  postPatch = ''
+    substituteInPlace config/99-azure-product-uuid.rules \
+      --replace "/bin/chmod" "${coreutils}/bin/chmod"
+  '';
+
+  propagatedBuildInputs = [ python.pkgs.distro ];
+
+  # The udev rules are placed to the wrong place.
+  # Move them to their default location.
+  # Keep $out/${python.sitePackages}/usr/sbin/waagent where it is.
+  # waagent re-executes itself in UpdateHandler.run_latest, even if autoupdate
+  # is disabled, manually spawning a python interprever with argv0.
+  # We can't use the default python program wrapping mechanism, as it uses
+  # wrapProgram which doesn't support --argv0.
+  # So instead we make our own wrapper in $out/bin/waagent, setting PATH and
+  # PYTHONPATH.
+  # PATH contains our PYTHON, and PYTHONPATH stays set, so this should somewhat
+  # still work.
+  preFixup = ''
+    mv $out/${python.sitePackages}/etc $out/
 
-  fixupPhase = ''
-     mkdir -p $out/bin/
-     WAAGENT=$(find $out -name waagent | grep sbin)
-     cp $WAAGENT $out/bin/waagent
-     wrapProgram "$out/bin/waagent" \
-         --prefix PYTHONPATH : $PYTHONPATH \
-         --prefix PATH : "${makeBinPath runtimeDeps}"
-     patchShebangs --build "$out/bin/"
+    buildPythonPath
+
+    mkdir -p $out/bin
+    makeWrapper $out/${python.sitePackages}/usr/sbin/waagent $out/bin/waagent \
+      --set PYTHONPATH $PYTHONPATH \
+      --prefix PATH : $program_PATH \
+      --argv0 $out/${python.sitePackages}/usr/sbin/waagent
   '';
 
+  dontWrapPythonPrograms = false;
+
   meta = {
-    description = "The Microsoft Azure Linux Agent (waagent)
-                   manages Linux provisioning and VM interaction with the Azure
-                   Fabric Controller";
+    description = "The Microsoft Azure Linux Agent (waagent)";
+    longDescription = ''
+      The Microsoft Azure Linux Agent (waagent)
+      manages Linux provisioning and VM interaction with the Azure
+      Fabric Controller'';
     homepage = "https://github.com/Azure/WALinuxAgent";
     license = with lib.licenses; [ asl20 ];
   };
-
 }