Files
2026-07-15 14:04:39 -04:00

97 lines
2.6 KiB
Nix

{
lib,
stdenv,
fetchFromGitHub,
rocmUpdateScript,
cmake,
pkg-config,
libdrm,
python,
wrapPython,
autoPatchelfHook,
}:
let
esmi_ib_src = fetchFromGitHub {
owner = "amd";
repo = "esmi_ib_library";
rev = "esmi_pkg_ver-4.2";
hash = "sha256-czF9ezkAO0PuDkXh8y639AcOZH+KVcWiXPX74H5W/nw=";
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "amdsmi";
version = "7.2.3";
src = fetchFromGitHub {
owner = "ROCm";
repo = "rocm-systems";
rev = "rocm-${finalAttrs.version}";
sparseCheckout = [
"projects/amdsmi"
"shared"
];
hash = "sha256-TFi+3txemvV6K827e8S3hZOd9jcj4Qzop6V9CdKrpLg=";
};
sourceRoot = "${finalAttrs.src.name}/projects/amdsmi";
postPatch = ''
substituteInPlace goamdsmi_shim/CMakeLists.txt \
--replace-fail "amd_smi)" ${"'"}''${AMD_SMI_TARGET})' \
--replace-fail 'target_link_libraries(''${GOAMDSMI_SHIM_TARGET} -L' '#'
substituteInPlace CMakeLists.txt \
--replace-fail "if(NOT latest_esmi_tag STREQUAL current_esmi_tag)" "if(OFF)"
# Manually unpack esmi_ib_src and add amd_hsmp.h so execute-process git clone doesn't run
cp -rf --no-preserve=mode ${esmi_ib_src} ./esmi_ib_library
mkdir -p ./esmi_ib_library/include/asm
cp ./include/amd_smi/impl/amd_hsmp.h ./esmi_ib_library/include/asm/amd_hsmp.h
'';
patches = [
# Fix error: redefinition of 'struct drm_color_ctm_3x4'
# https://github.com/ROCm/amdsmi/pull/165
./drm-struct-redefinition-fix.patch
];
nativeBuildInputs = [
cmake
pkg-config
wrapPython
autoPatchelfHook
];
buildInputs = [
libdrm
];
cmakeFlags = [
# Manually define CMAKE_INSTALL_<DIR>
# See: https://github.com/NixOS/nixpkgs/pull/197838
"-DCMAKE_INSTALL_BINDIR=bin"
"-DCMAKE_INSTALL_LIBDIR=lib"
"-DCMAKE_INSTALL_INCLUDEDIR=include"
];
postInstall = ''
mkdir -p $out/${python.sitePackages}
ln -s $out/share/amd_smi/amdsmi $out/${python.sitePackages}/amdsmi
makeWrapperArgs=(--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ libdrm ]})
wrapPythonProgramsIn $out
rm $out/bin/amd-smi
ln -sf $out/libexec/amdsmi_cli/amdsmi_cli.py $out/bin/amd-smi
'';
passthru.updateScript = rocmUpdateScript { inherit finalAttrs; };
meta = {
description = "System management interface for AMD GPUs supported by ROCm";
homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/amdsmi";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ lovesegfault ];
teams = [ lib.teams.rocm ];
platforms = [ "x86_64-linux" ];
mainProgram = "amd-smi";
};
})