summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Schyska <paul@schyska.net>2021-05-14 02:08:41 +0200
committerPaul Schyska <paul@schyska.net>2021-05-16 18:22:03 +0200
commit327dcea4ccc8e5e2562c277bd35198751ecc4930 (patch)
treebbd9567d758508ce7b387307ad25484cfafb24bc
parent2703a7999adeee8e3c880fa539bdede43c0c22a4 (diff)
downloadnixpkgs-327dcea4ccc8e5e2562c277bd35198751ecc4930.tar
nixpkgs-327dcea4ccc8e5e2562c277bd35198751ecc4930.tar.gz
nixpkgs-327dcea4ccc8e5e2562c277bd35198751ecc4930.tar.bz2
nixpkgs-327dcea4ccc8e5e2562c277bd35198751ecc4930.tar.lz
nixpkgs-327dcea4ccc8e5e2562c277bd35198751ecc4930.tar.xz
nixpkgs-327dcea4ccc8e5e2562c277bd35198751ecc4930.tar.zst
nixpkgs-327dcea4ccc8e5e2562c277bd35198751ecc4930.zip
atop: fix packaging .service files, add option to build with atopgpu
-rw-r--r--pkgs/os-specific/linux/atop/atop-pm.sh.patch13
-rw-r--r--pkgs/os-specific/linux/atop/atop-rotate.service.patch7
-rw-r--r--pkgs/os-specific/linux/atop/atop.service.patch14
-rw-r--r--pkgs/os-specific/linux/atop/atopacct.service.patch11
-rw-r--r--pkgs/os-specific/linux/atop/atopgpu.service.patch9
-rw-r--r--pkgs/os-specific/linux/atop/default.nix59
-rw-r--r--pkgs/os-specific/linux/netatop/netatop.service.patch14
7 files changed, 113 insertions, 14 deletions
diff --git a/pkgs/os-specific/linux/atop/atop-pm.sh.patch b/pkgs/os-specific/linux/atop/atop-pm.sh.patch
new file mode 100644
index 00000000000..9b66b260992
--- /dev/null
+++ b/pkgs/os-specific/linux/atop/atop-pm.sh.patch
@@ -0,0 +1,13 @@
+--- a/atop-pm.sh
++++ b/atop-pm.sh
+@@ -2,8 +2,8 @@
+
+ case "$1" in
+-	pre)	/usr/bin/systemctl stop atop
++	pre)	@systemd@/bin/systemctl stop atop
+ 		exit 0
+ 		;;
+-	post)	/usr/bin/systemctl start atop
++	post)	@systemd@/bin/systemctl start atop
+ 		exit 0
+ 		;;
diff --git a/pkgs/os-specific/linux/atop/atop-rotate.service.patch b/pkgs/os-specific/linux/atop/atop-rotate.service.patch
new file mode 100644
index 00000000000..951a3c8c837
--- /dev/null
+++ b/pkgs/os-specific/linux/atop/atop-rotate.service.patch
@@ -0,0 +1,7 @@
+--- a/atop-rotate.service
++++ b/atop-rotate.service
+@@ -4,3 +4,3 @@
+ [Service]
+ Type=oneshot
+-ExecStart=/usr/bin/systemctl try-restart atop.service
++ExecStart=@systemd@/bin/systemctl try-restart atop.service
diff --git a/pkgs/os-specific/linux/atop/atop.service.patch b/pkgs/os-specific/linux/atop/atop.service.patch
new file mode 100644
index 00000000000..5467b512229
--- /dev/null
+++ b/pkgs/os-specific/linux/atop/atop.service.patch
@@ -0,0 +1,14 @@
+--- a/atop.service
++++ b/atop.service
+@@ -9,7 +9,8 @@
+ Environment=LOGPATH=/var/log/atop
+-EnvironmentFile=/etc/default/atop
++EnvironmentFile=-/etc/default/atop
+ ExecStartPre=/bin/sh -c 'test -n "$LOGINTERVAL" -a "$LOGINTERVAL" -eq "$LOGINTERVAL"'
+ ExecStartPre=/bin/sh -c 'test -n "$LOGGENERATIONS" -a "$LOGGENERATIONS" -eq "$LOGGENERATIONS"'
+-ExecStart=/bin/sh -c 'exec /usr/bin/atop ${LOGOPTS} -w "${LOGPATH}/atop_$(date +%%Y%%m%%d)" ${LOGINTERVAL}'
+-ExecStartPost=/usr/bin/find "${LOGPATH}" -name "atop_*" -mtime +${LOGGENERATIONS} -exec rm -v {} \;
++ExecStartPre=/bin/sh -c 'mkdir -p "${LOGPATH}"'
++ExecStart=/bin/sh -c 'exec @out@/bin/atop ${LOGOPTS} -w "${LOGPATH}/atop_$(date +%%Y%%m%%d)" ${LOGINTERVAL}'
++ExecStartPost=@findutils@/bin/find "${LOGPATH}" -name "atop_*" -mtime +${LOGGENERATIONS} -exec rm -v {} \;
+ KillSignal=SIGUSR2
diff --git a/pkgs/os-specific/linux/atop/atopacct.service.patch b/pkgs/os-specific/linux/atop/atopacct.service.patch
new file mode 100644
index 00000000000..cbecbef90ec
--- /dev/null
+++ b/pkgs/os-specific/linux/atop/atopacct.service.patch
@@ -0,0 +1,11 @@
+--- a/atopacct.service
++++ b/atopacct.service
+@@ -8,6 +8,6 @@
+ [Service]
+ Type=forking
+-PIDFile=/var/run/atopacctd.pid
+-ExecStart=/usr/sbin/atopacctd
++PIDFile=/run/atopacctd.pid
++ExecStart=@out@/bin/atopacctd
+
+ [Install]
diff --git a/pkgs/os-specific/linux/atop/atopgpu.service.patch b/pkgs/os-specific/linux/atop/atopgpu.service.patch
new file mode 100644
index 00000000000..30c38b67cad
--- /dev/null
+++ b/pkgs/os-specific/linux/atop/atopgpu.service.patch
@@ -0,0 +1,9 @@
+--- a/atopgpu.service
++++ b/atopgpu.service
+@@ -6,5 +6,5 @@
+
+ [Service]
+-ExecStart=/usr/sbin/atopgpud
++ExecStart=@out@/bin/atopgpud
+ Type=oneshot
+ RemainAfterExit=yes
diff --git a/pkgs/os-specific/linux/atop/default.nix b/pkgs/os-specific/linux/atop/default.nix
index e1b64c0a4b5..00510c91a74 100644
--- a/pkgs/os-specific/linux/atop/default.nix
+++ b/pkgs/os-specific/linux/atop/default.nix
@@ -1,4 +1,14 @@
-{lib, stdenv, fetchurl, zlib, ncurses}:
+{ lib
+, stdenv
+, fetchurl
+, zlib
+, ncurses
+, findutils
+, systemd
+, python3
+  # makes the package unfree via pynvml
+, withAtopgpu ? false
+}:
 
 stdenv.mkDerivation rec {
   pname = "atop";
@@ -9,31 +19,52 @@ stdenv.mkDerivation rec {
     sha256 = "nsLKOlcWkvfvqglfmaUQZDK8txzCLNbElZfvBIEFj3I=";
   };
 
-  buildInputs = [zlib ncurses];
+  nativeBuildInputs = if withAtopgpu then [ python3.pkgs.wrapPython ] else [ ];
+  buildInputs = [ zlib ncurses ] ++ (if withAtopgpu then [ python3 ] else [ ]);
+  pythonPath = if withAtopgpu then [ python3.pkgs.pynvml ] else [ ];
 
   makeFlags = [
-    "SCRPATH=$out/etc/atop"
-    "LOGPATH=/var/log/atop"
-    "INIPATH=$out/etc/rc.d/init.d"
-    "SYSDPATH=$out/lib/systemd/system"
-    "CRNPATH=$out/etc/cron.d"
-    "DEFPATH=$out/etc/default"
-    "ROTPATH=$out/etc/logrotate.d"
+    "DESTDIR=$(out)"
+    "BINPATH=/bin"
+    "SBINPATH=/bin"
+    "MAN1PATH=/share/man/man1"
+    "MAN5PATH=/share/man/man5"
+    "MAN8PATH=/share/man/man8"
+    "SYSDPATH=/lib/systemd/system"
+    "PMPATHD=/lib/systemd/system-sleep"
   ];
 
+  patches = [
+    ./atop-pm.sh.patch
+    ./atop-rotate.service.patch
+    ./atop.service.patch
+    ./atopacct.service.patch
+  ] ++ (if withAtopgpu then [ ./atopgpu.service.patch ] else [ ]);
+
   preConfigure = ''
-    sed -e "s@/usr/@$out/@g" -i $(find . -type f )
-    sed -e "/mkdir.*LOGPATH/s@mkdir@echo missing dir @" -i Makefile
-    sed -e "/touch.*LOGPATH/s@touch@echo should have created @" -i Makefile
+    for f in *.{sh,service}; do
+      findutils=${findutils} systemd=${systemd} substituteAllInPlace "$f"
+    done
+
     sed -e 's/chown/true/g' -i Makefile
-    sed -e '/chkconfig/d' -i Makefile
     sed -e 's/chmod 04711/chmod 0711/g' -i Makefile
   '';
 
   installTargets = [ "systemdinstall" ];
   preInstall = ''
-    mkdir -p "$out"/{bin,sbin}
+    mkdir -p $out/bin
   '';
+  postInstall = ''
+    # remove extra files we don't need
+    rm -rf $out/{var,etc}
+    rm -rf $out/bin/atop{sar,}-${version}
+  '' + (if withAtopgpu then ''
+    wrapPythonPrograms
+  '' else ''
+    rm $out/lib/systemd/system/atopgpu.service
+    rm $out/bin/atopgpud
+    rm $out/share/man/man8/atopgpud.8
+  '');
 
   meta = with lib; {
     platforms = platforms.linux;
diff --git a/pkgs/os-specific/linux/netatop/netatop.service.patch b/pkgs/os-specific/linux/netatop/netatop.service.patch
new file mode 100644
index 00000000000..b7fae336be9
--- /dev/null
+++ b/pkgs/os-specific/linux/netatop/netatop.service.patch
@@ -0,0 +1,14 @@
+--- a/netatop.service
++++ b/netatop.service
+@@ -7,8 +7,8 @@
+ [Service]
+ Type=oneshot
+-ExecStartPre=/sbin/modprobe netatop
+-ExecStart=/usr/sbin/netatopd
+-ExecStopPost=/sbin/rmmod netatop
+-PIDFile=/var/run/netatop.pid
++ExecStartPre=@kmod@/bin/modprobe netatop
++ExecStart=@out@/bin/netatopd
++ExecStopPost=@kmod@/bin/rmmod netatop
++PIDFile=/run/netatop.pid
+ RemainAfterExit=yes