From b80d0435e49f3c5b7c15e978208fb77781ce7ad6 Mon Sep 17 00:00:00 2001 From: moni Date: Sat, 16 Nov 2024 09:46:30 +0800 Subject: [PATCH 1/4] nvtopPackages.apple: darwin support --- pkgs/tools/system/nvtop/build-nvtop.nix | 9 ++++++--- pkgs/tools/system/nvtop/default.nix | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkgs/tools/system/nvtop/build-nvtop.nix b/pkgs/tools/system/nvtop/build-nvtop.nix index f1f855b25383..55927ae56b35 100644 --- a/pkgs/tools/system/nvtop/build-nvtop.nix +++ b/pkgs/tools/system/nvtop/build-nvtop.nix @@ -8,6 +8,7 @@ , ncurses , testers , udev +, apple-sdk_12 , addDriverRunpath , amd ? false , intel ? false @@ -53,7 +54,9 @@ stdenv.mkDerivation (finalAttrs: { ]; nativeBuildInputs = [ cmake gtest ] ++ lib.optional nvidia addDriverRunpath; - buildInputs = [ ncurses udev ] + buildInputs = [ ncurses ] + ++ lib.optional stdenv.isLinux udev + ++ lib.optional stdenv.isDarwin apple-sdk_12 ++ lib.optional nvidia cudatoolkit ++ lib.optional needDrm libdrm ; @@ -83,8 +86,8 @@ stdenv.mkDerivation (finalAttrs: { homepage = "https://github.com/Syllo/nvtop"; changelog = "https://github.com/Syllo/nvtop/releases/tag/${finalAttrs.version}"; license = licenses.gpl3Only; - platforms = platforms.linux; - maintainers = with maintainers; [ willibutz gbtb anthonyroussel ]; + platforms = platforms.linux ++ platforms.darwin; + maintainers = with maintainers; [ willibutz gbtb anthonyroussel moni ]; mainProgram = "nvtop"; }; }) diff --git a/pkgs/tools/system/nvtop/default.nix b/pkgs/tools/system/nvtop/default.nix index f6e679b6ffef..02cb9b7531a1 100644 --- a/pkgs/tools/system/nvtop/default.nix +++ b/pkgs/tools/system/nvtop/default.nix @@ -2,10 +2,10 @@ let # this GPU families are supported "by-default" upstream (see https://github.com/Syllo/nvtop/blob/3a69c2d060298cd6f92cb09db944eded98be1c23/CMakeLists.txt#L81) # coincidentally, these families are also easy to build in nixpkgs at the moment - defaultGPUFamilies = [ "amd" "intel" "msm" "nvidia" "panfrost" "panthor" ]; + defaultGPUFamilies = [ "amd" "apple" "intel" "msm" "nvidia" "panfrost" "panthor" ]; # these GPU families are partially supported upstream, they are also tricky to build in nixpkgs # volunteers with specific hardware needed to build and test these package variants - additionalGPUFamilies = [ "apple" "ascend" ]; + additionalGPUFamilies = [ "ascend" ]; defaultSupport = builtins.listToAttrs (builtins.map (gpu: { name = gpu; value = true; }) defaultGPUFamilies); in { From 84e9fd9db5a9da04bde71b08e4553e96ea5c067d Mon Sep 17 00:00:00 2001 From: moni Date: Sat, 16 Nov 2024 10:05:14 +0800 Subject: [PATCH 2/4] nvtopPackages.full: mutually exclude gpus for darwin and linux --- pkgs/tools/system/nvtop/default.nix | 11 ++++++----- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkgs/tools/system/nvtop/default.nix b/pkgs/tools/system/nvtop/default.nix index 02cb9b7531a1..648f0f25482b 100644 --- a/pkgs/tools/system/nvtop/default.nix +++ b/pkgs/tools/system/nvtop/default.nix @@ -1,4 +1,4 @@ -{ callPackage }: +{ callPackage, stdenv }: let # this GPU families are supported "by-default" upstream (see https://github.com/Syllo/nvtop/blob/3a69c2d060298cd6f92cb09db944eded98be1c23/CMakeLists.txt#L81) # coincidentally, these families are also easy to build in nixpkgs at the moment @@ -6,13 +6,14 @@ let # these GPU families are partially supported upstream, they are also tricky to build in nixpkgs # volunteers with specific hardware needed to build and test these package variants additionalGPUFamilies = [ "ascend" ]; - defaultSupport = builtins.listToAttrs (builtins.map (gpu: { name = gpu; value = true; }) defaultGPUFamilies); + defaultSupport = builtins.listToAttrs ( + # apple can only build on darwin, and it can't build everything else, and vice versa + builtins.map (gpu: { name = gpu; value = (gpu == "apple" && stdenv.buildPlatform.isDarwin && stdenv.hostPlatform == stdenv.buildPlatform) || (gpu != "apple" && stdenv.buildPlatform.isLinux); + }) defaultGPUFamilies + ); in { full = callPackage ./build-nvtop.nix defaultSupport; #this package supports all default GPU families } # additional packages with only one specific GPU family support // builtins.listToAttrs (builtins.map (gpu: { name = gpu; value = (callPackage ./build-nvtop.nix { "${gpu}" = true; }); }) defaultGPUFamilies) - - - diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index beb25b36d18a..9771864e750e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -10541,7 +10541,7 @@ with pkgs; nvidia-system-monitor-qt = libsForQt5.callPackage ../tools/system/nvidia-system-monitor-qt { }; - nvtopPackages = recurseIntoAttrs (import ../tools/system/nvtop { inherit callPackage; }); + nvtopPackages = recurseIntoAttrs (import ../tools/system/nvtop { inherit callPackage stdenv; }); inherit (callPackages ../development/libraries/ogre { }) ogre_13 ogre_14; From 37cf6e3ee61db025a21da52aa9121a1249b3153c Mon Sep 17 00:00:00 2001 From: moni Date: Sat, 16 Nov 2024 10:09:33 +0800 Subject: [PATCH 3/4] nvtopPackages: format --- pkgs/tools/system/nvtop/build-nvtop.nix | 71 +++++++++++++++---------- pkgs/tools/system/nvtop/default.nix | 25 +++++++-- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/pkgs/tools/system/nvtop/build-nvtop.nix b/pkgs/tools/system/nvtop/build-nvtop.nix index 55927ae56b35..7d5e2cd79949 100644 --- a/pkgs/tools/system/nvtop/build-nvtop.nix +++ b/pkgs/tools/system/nvtop/build-nvtop.nix @@ -1,30 +1,37 @@ -{ lib -, stdenv -, fetchFromGitHub -, cmake -, gtest -, cudatoolkit -, libdrm -, ncurses -, testers -, udev -, apple-sdk_12 -, addDriverRunpath -, amd ? false -, intel ? false -, msm ? false -, nvidia ? false -, apple ? false -, panfrost ? false -, panthor ? false -, ascend ? false +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + gtest, + cudatoolkit, + libdrm, + ncurses, + testers, + udev, + apple-sdk_12, + addDriverRunpath, + amd ? false, + intel ? false, + msm ? false, + nvidia ? false, + apple ? false, + panfrost ? false, + panthor ? false, + ascend ? false, }: let drm-postFixup = '' patchelf \ --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ - --set-rpath "${lib.makeLibraryPath [ libdrm ncurses udev ]}" \ + --set-rpath "${ + lib.makeLibraryPath [ + libdrm + ncurses + udev + ] + }" \ $out/bin/nvtop ''; needDrm = (amd || msm || panfrost || panthor); @@ -52,20 +59,25 @@ stdenv.mkDerivation (finalAttrs: { (cmakeBool "PANTHOR_SUPPORT" panthor) (cmakeBool "ASCEND_SUPPORT" ascend) ]; - nativeBuildInputs = [ cmake gtest ] ++ lib.optional nvidia addDriverRunpath; + nativeBuildInputs = [ + cmake + gtest + ] ++ lib.optional nvidia addDriverRunpath; - buildInputs = [ ncurses ] + buildInputs = + [ ncurses ] ++ lib.optional stdenv.isLinux udev ++ lib.optional stdenv.isDarwin apple-sdk_12 ++ lib.optional nvidia cudatoolkit - ++ lib.optional needDrm libdrm - ; + ++ lib.optional needDrm libdrm; # this helps cmake to find env.NIX_CFLAGS_COMPILE = lib.optionalString needDrm "-isystem ${lib.getDev libdrm}/include/libdrm"; # ordering of fixups is important - postFixup = (lib.optionalString needDrm drm-postFixup) + (lib.optionalString nvidia "addDriverRunpath $out/bin/nvtop"); + postFixup = + (lib.optionalString needDrm drm-postFixup) + + (lib.optionalString nvidia "addDriverRunpath $out/bin/nvtop"); doCheck = true; @@ -87,7 +99,12 @@ stdenv.mkDerivation (finalAttrs: { changelog = "https://github.com/Syllo/nvtop/releases/tag/${finalAttrs.version}"; license = licenses.gpl3Only; platforms = platforms.linux ++ platforms.darwin; - maintainers = with maintainers; [ willibutz gbtb anthonyroussel moni ]; + maintainers = with maintainers; [ + willibutz + gbtb + anthonyroussel + moni + ]; mainProgram = "nvtop"; }; }) diff --git a/pkgs/tools/system/nvtop/default.nix b/pkgs/tools/system/nvtop/default.nix index 648f0f25482b..7e9653102bef 100644 --- a/pkgs/tools/system/nvtop/default.nix +++ b/pkgs/tools/system/nvtop/default.nix @@ -2,18 +2,35 @@ let # this GPU families are supported "by-default" upstream (see https://github.com/Syllo/nvtop/blob/3a69c2d060298cd6f92cb09db944eded98be1c23/CMakeLists.txt#L81) # coincidentally, these families are also easy to build in nixpkgs at the moment - defaultGPUFamilies = [ "amd" "apple" "intel" "msm" "nvidia" "panfrost" "panthor" ]; + defaultGPUFamilies = [ + "amd" + "apple" + "intel" + "msm" + "nvidia" + "panfrost" + "panthor" + ]; # these GPU families are partially supported upstream, they are also tricky to build in nixpkgs # volunteers with specific hardware needed to build and test these package variants additionalGPUFamilies = [ "ascend" ]; defaultSupport = builtins.listToAttrs ( # apple can only build on darwin, and it can't build everything else, and vice versa - builtins.map (gpu: { name = gpu; value = (gpu == "apple" && stdenv.buildPlatform.isDarwin && stdenv.hostPlatform == stdenv.buildPlatform) || (gpu != "apple" && stdenv.buildPlatform.isLinux); + builtins.map (gpu: { + name = gpu; + value = + (gpu == "apple" && stdenv.buildPlatform.isDarwin && stdenv.hostPlatform == stdenv.buildPlatform) + || (gpu != "apple" && stdenv.buildPlatform.isLinux); }) defaultGPUFamilies ); in { - full = callPackage ./build-nvtop.nix defaultSupport; #this package supports all default GPU families + full = callPackage ./build-nvtop.nix defaultSupport; # this package supports all default GPU families } # additional packages with only one specific GPU family support -// builtins.listToAttrs (builtins.map (gpu: { name = gpu; value = (callPackage ./build-nvtop.nix { "${gpu}" = true; }); }) defaultGPUFamilies) +// builtins.listToAttrs ( + builtins.map (gpu: { + name = gpu; + value = (callPackage ./build-nvtop.nix { "${gpu}" = true; }); + }) defaultGPUFamilies +) From 088ac6b39eae37775b5b6c34516017949ec8e756 Mon Sep 17 00:00:00 2001 From: moni Date: Thu, 21 Nov 2024 00:12:37 +0800 Subject: [PATCH 4/4] nvtopPackages: set platform accordingly --- pkgs/tools/system/nvtop/build-nvtop.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/system/nvtop/build-nvtop.nix b/pkgs/tools/system/nvtop/build-nvtop.nix index 7d5e2cd79949..953565150765 100644 --- a/pkgs/tools/system/nvtop/build-nvtop.nix +++ b/pkgs/tools/system/nvtop/build-nvtop.nix @@ -98,7 +98,7 @@ stdenv.mkDerivation (finalAttrs: { homepage = "https://github.com/Syllo/nvtop"; changelog = "https://github.com/Syllo/nvtop/releases/tag/${finalAttrs.version}"; license = licenses.gpl3Only; - platforms = platforms.linux ++ platforms.darwin; + platforms = lib.optional (!apple) platforms.linux ++ lib.optional apple platforms.darwin; maintainers = with maintainers; [ willibutz gbtb