Nvtop package for GNU Guix

I wrote this package definition for nvtop, for GNU Guix,

(define-module (nebula packages monitoring)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages xdisorg)
  #:use-module (gnu packages base)
  #:use-module (gnu packages elf)
  #:use-module (guix build-system cmake)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix gexp)
  #:use-module (guix utils)
  #:use-module ((guix licenses)
                #:prefix license:)

  #:use-module (nongnu packages nvidia))

(define-public nvtop
  (let ((commit "eb56ee86ae0836872ee182fa2a15b1f1434d8efe")
        (revision "0"))
    (package
      (name "nvtop")
      (version (git-version "3.0.2" revision commit))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/Syllo/nvtop")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "005h9vw3zbqdxfwbzf6d5jwcxvxzvijp89vznrg1vl1vhd2nf08b"))))
      (build-system cmake-build-system)
      (arguments
       (list
        #:configure-flags #~(list "-DNVIDIA_SUPPORT=ON"
                                  "-DAMDGPU_SUPPORT=ON"
                                  "-DINTEL_SUPPORT=ON"
                                  "-DMSM_SUPPORT=ON"
                                  "-DPANFROST_SUPPORT=ON"
                                  "-DASCEND_SUPPORT=ON"
                                  "-DUSE_LIBUDEV_OVER_LIBSYSTEMD=ON"
                                  "-DBUILD_TESTING=ON")
        #:build-type "Release"
        #:phases #~(modify-phases %standard-phases
                     (add-after 'install 'patch-nvtop-bin
                       (lambda* (#:key outputs #:allow-other-keys)
                         (let ((out (assoc-ref outputs "out")))
                           (system* "patchelf"
                                    "--set-interpreter"
                                    (string-append #$(this-package-input "glibc") "/lib/ld-linux.so.2")
                                    "--set-rpath"
                                    (string-append #$(this-package-input "ncurses") "/lib")
                                    (string-append #$(this-package-input "libdrm") "/lib")
                                    (string-append #$(this-package-input "eudev") "/lib")
                                    (string-append #$(this-package-input "nvidia-nvml") "/lib")
                                    (string-append out "/bin/nvtop"))))))
        #:tests? #t))
      (inputs (list ncurses
                    nvidia-nvml
                    libdrm
                    eudev))
      (native-inputs (list glibc
                           patchelf))
      (home-page "https://github.com/Syllo/nvtop")
      (synopsis "GPUs process monitoring for AMD, Intel and NVIDIA")
      (description "Nvtop stands for Neat Videocard TOP,
 a (h)top like task monitor for AMD, Intel and NVIDIA GPUs.
 It can handle multiple GPUs and print information
 about them in a htop familiar way.")
      (license license:gpl3))))

On my laptop when this package build and installs, I get No GPU to monitor error when I run it.

I found this issue on their repo, amd = "No GPU to monitor" · Issue #250 · Syllo/nvtop · GitHub, so maybe its not me, but a common issue with amd GPU’s?

If anybody has suggestions or feedback for this package, or if somebody wants to test it on their system with a different card, like intel or nvidia, there is even arm support I think.

I updated it today to latest commit,

  (let ((commit "0316ce19581c3d8543cf6aa312d1569c56ca754f")
        (revision "0"))
    (package
      (name "nvtop")
      (version (git-version "3.1.0" revision commit))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/Syllo/nvtop")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "1cdyk1ivc3gl3f7r99awwl8an07vp3inclrb6xjhaincfpwp130x"))))

Also had to comment out `

                                  ;; "-DASCEND_SUPPORT=ON"

as it errors out.

ATM I am getting this error,

[100%] Built target nvtop
make[1]: Leaving directory '/tmp/guix-build-nvtop-3.1.0-0.0316ce1.drv-0/build'
/gnu/store/gl26kr5v6ch5lc3ignly61kb224drijc-cmake-minimal-3.24.2/bin/cmake -E cmake_progress_start /tmp/guix-build-nvtop-3.1.0-0.0316ce1.drv-0/build/CMakeFiles 0
make  -f CMakeFiles/Makefile2 preinstall
make[1]: Entering directory '/tmp/guix-build-nvtop-3.1.0-0.0316ce1.drv-0/build'
make[1]: Nothing to be done for 'preinstall'.
make[1]: Leaving directory '/tmp/guix-build-nvtop-3.1.0-0.0316ce1.drv-0/build'
Install the project...
/gnu/store/gl26kr5v6ch5lc3ignly61kb224drijc-cmake-minimal-3.24.2/bin/cmake -P cmake_install.cmake
-- Install configuration: "Release"
-- Installing: /gnu/store/szbrhmxxyh5h7fgzd8q6v1wyr2pwrhjs-nvtop-3.1.0-0.0316ce1/bin/nvtop
-- Set runtime path of "/gnu/store/szbrhmxxyh5h7fgzd8q6v1wyr2pwrhjs-nvtop-3.1.0-0.0316ce1/bin/nvtop" to "/gnu/store/szbrhmxxyh5h7fgzd8q6v1wyr2pwrhjs-nvtop-3.1.0-0.0316ce1/lib"
-- Installing: /gnu/store/szbrhmxxyh5h7fgzd8q6v1wyr2pwrhjs-nvtop-3.1.0-0.0316ce1/share/man/man1/nvtop.1
-- Installing: /gnu/store/szbrhmxxyh5h7fgzd8q6v1wyr2pwrhjs-nvtop-3.1.0-0.0316ce1/share/icons/nvtop.svg
-- Installing: /gnu/store/szbrhmxxyh5h7fgzd8q6v1wyr2pwrhjs-nvtop-3.1.0-0.0316ce1/share/applications/nvtop.desktop
-- Installing: /gnu/store/szbrhmxxyh5h7fgzd8q6v1wyr2pwrhjs-nvtop-3.1.0-0.0316ce1/share/metainfo/nvtop.metainfo.xml
phase `install' succeeded after 0.1 seconds
starting phase `patch-nvtop-bin'
error: in phase 'patch-nvtop-bin': uncaught exception:
wrong-type-arg "string-append" "Wrong type (expecting ~A): ~S" ("string" #f) (#f) 
phase `patch-nvtop-bin' failed after 0.0 seconds
Backtrace:
           9 (primitive-load "/gnu/store/ns66kiwgiwqm7bg7m8832bdvi03…")
In guix/build/gnu-build-system.scm:
    908:2  8 (gnu-build #:source _ #:outputs _ #:inputs _ #:phases . #)
In ice-9/boot-9.scm:
  1752:10  7 (with-exception-handler _ _ #:unwind? _ # _)
In srfi/srfi-1.scm:
    634:9  6 (for-each #<procedure 7ffff5ee9000 at guix/build/gnu-b…> …)
In ice-9/boot-9.scm:
  1752:10  5 (with-exception-handler _ _ #:unwind? _ # _)
In guix/build/gnu-build-system.scm:
   929:23  4 (_)
In ice-9/eval.scm:
   173:55  3 (_ #(#(#(#<directory (guile-user) 7ffff77f7c80>) (#)) #))
In unknown file:
           2 (string-append #f "/lib/ld-linux.so.2")
In ice-9/boot-9.scm:
  1685:16  1 (raise-exception _ #:continuable? _)
  1685:16  0 (raise-exception _ #:continuable? _)

ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure string-append: Wrong type (expecting string): #f
builder for `/gnu/store/7cc0573bvc77ssfic0r7cyyn4j0b5zvq-nvtop-3.1.0-0.0316ce1.drv' failed with exit code 1
build of /gnu/store/7cc0573bvc77ssfic0r7cyyn4j0b5zvq-nvtop-3.1.0-0.0316ce1.drv failed

This particular error goes away when I change (string-append #$(this-package-input "glibc") "/lib/ld-linux.so.2") to (string-append #$(this-package-native-input "glibc") "/lib/ld-linux.so.2"), since glibc is listed as a native input, not an input.

This seems to work just fine with the earlier commit you posted :slight_smile:

I’m just trying to see if I get the same error when I run nvtop, because nvtop works just fine on my machine when installed through Archlinux.

Update: Running the nvtop installed through Guix provides the same result you see: “No GPU to monitor”. I have an AMD Radeon card though, so that might not be a surprise to you :slight_smile:

This particular error goes away when I change (string-append #$(this-package-input "glibc") "/lib/ld-linux.so.2") to (string-append #$(this-package-native-input "glibc") "/lib/ld-linux.so.2"), since glibc is listed as a native input, not an input.

Yes, this fixes the glibc error…

I’m just trying to see if I get the same error when I run nvtop, because nvtop works just fine on my machine when installed through Archlinux.

Yes, they probably use systemd libs rather than udev. And the issue is already mentioned here amd = "No GPU to monitor" · Issue #250 · Syllo/nvtop · GitHub so we are not alone I suppose.

Update: Running the nvtop installed through Guix provides the same result you see: “No GPU to monitor”. I have an AMD Radeon card though, so that might not be a surprise to you :slight_smile:

Yup… I guess we are not doing anything wrong now.