Commit 37cf6e3e authored by moni's avatar moni
Browse files

nvtopPackages: format

parent 84e9fd9d
Loading
Loading
Loading
Loading
+44 −27
Original line number Diff line number Diff line
{ 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 <drm.h>
  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";
  };
})
+21 −4
Original line number Diff line number Diff line
@@ -2,13 +2,25 @@
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
@@ -16,4 +28,9 @@ 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)
// builtins.listToAttrs (
  builtins.map (gpu: {
    name = gpu;
    value = (callPackage ./build-nvtop.nix { "${gpu}" = true; });
  }) defaultGPUFamilies
)