lm_sensors: fix build, split outputs, modernize and remove perl from library closure (#373242)

This commit is contained in:
Ramses
2025-01-19 00:28:50 +01:00
committed by GitHub
3 changed files with 52 additions and 23 deletions
+3 -4
View File
@@ -18,9 +18,11 @@ buildGo123Module rec {
vendorHash = "sha256-ad0e/cxbcU/KfPDOdD46KdCcvns83dgGDAyLLQiGyiA=";
buildInputs = [ lm_sensors ];
postConfigure = ''
substituteInPlace vendor/github.com/md14454/gosensors/gosensors.go \
--replace-fail '"/etc/sensors3.conf"' '"${lm_sensors}/etc/sensors3.conf"'
--replace-fail '"/etc/sensors3.conf"' '"${lib.getLib lm_sensors}/etc/sensors3.conf"'
# Uses /usr/bin/echo, and even if we patch that, it refuses to execute any
# binary without being able to confirm that it's owned by root, which isn't
@@ -28,9 +30,6 @@ buildGo123Module rec {
rm internal/fans/cmd_test.go
'';
CGO_CFLAGS = "-I ${lm_sensors}/include";
CGO_LDFLAGS = "-L ${lm_sensors}/lib";
meta = with lib; {
description = "Simple daemon providing dynamic fan speed control based on temperature sensors";
mainProgram = "fan2go";
+48 -18
View File
@@ -2,34 +2,55 @@
lib,
stdenv,
fetchFromGitHub,
fetchpatch,
bash,
bison,
flex,
which,
perl,
rrdtool,
sensord ? false,
rrdtool ? null,
}:
assert sensord -> rrdtool != null;
stdenv.mkDerivation rec {
pname = "lm-sensors";
let
version = "3.6.0";
dashedVersion = lib.replaceStrings [ "." ] [ "-" ] version;
tag = lib.replaceStrings [ "." ] [ "-" ] version;
in
stdenv.mkDerivation {
pname = "lm-sensors";
inherit version;
src = fetchFromGitHub {
owner = "lm-sensors";
repo = "lm-sensors";
rev = "V${dashedVersion}";
inherit tag;
hash = "sha256-9lfHCcODlS7sZMjQhK0yQcCBEoGyZOChx/oM0CU37sY=";
};
patches = [
# Fix compile failure on GCC 14 with `sensord` enabled.
# From: https://github.com/lm-sensors/lm-sensors/pull/483
(fetchpatch {
url = "https://github.com/lm-sensors/lm-sensors/pull/483/commits/7a6170f07d05cc6601b4668f211e9389f2e75286.patch";
hash = "sha256-Q49quv3eXeMvY3jgZFs/F7Rljbq4YyehIDIlsgmloBQ=";
})
];
outputs = [
"bin"
"out"
"dev"
"man"
"doc"
];
# Upstream build system have knob to enable and disable building of static
# library, shared library is built unconditionally.
postPatch = lib.optionalString stdenv.hostPlatform.isStatic ''
sed -i 'lib/Module.mk' -e '/LIBTARGETS :=/,+1d; /-m 755/ d'
substituteInPlace prog/sensors/Module.mk --replace 'lib/$(LIBSHBASENAME)' ""
substituteInPlace prog/sensors/Module.mk \
--replace-fail 'lib/$(LIBSHBASENAME)' ""
'';
nativeBuildInputs = [
@@ -37,6 +58,7 @@ stdenv.mkDerivation rec {
flex
which
];
# bash is required for correctly replacing the shebangs in all tools for cross-compilation.
buildInputs = [
bash
@@ -45,35 +67,43 @@ stdenv.mkDerivation rec {
makeFlags = [
"PREFIX=${placeholder "out"}"
"BINDIR=${placeholder "bin"}/bin"
"SBINDIR=${placeholder "bin"}/bin"
"INCLUDEDIR=${placeholder "dev"}/include"
"MANDIR=${placeholder "man"}/share/man"
# This is a dependency of the library.
"ETCDIR=${placeholder "out"}/etc"
"CC=${stdenv.cc.targetPrefix}cc"
"AR=${stdenv.cc.targetPrefix}ar"
] ++ lib.optional sensord "PROG_EXTRA=sensord";
installFlags = [
"ETCDIR=${placeholder "out"}/etc"
];
enableParallelBuilding = true;
# Making regexp to patch-out installing of .so symlinks from Makefile is
# complicated, it is easier to remove them post-install.
postInstall =
''
mkdir -p $out/share/doc/${pname}
cp -r configs doc/* $out/share/doc/${pname}
mkdir -p $doc/share/doc/lm_sensors
cp -r configs doc/* $doc/share/doc/lm_sensors
''
+ lib.optionalString stdenv.hostPlatform.isStatic ''
rm $out/lib/*.so*
'';
meta = with lib; {
meta = {
homepage = "https://hwmon.wiki.kernel.org/lm_sensors";
changelog = "https://raw.githubusercontent.com/lm-sensors/lm-sensors/V${dashedVersion}/CHANGES";
changelog = "https://raw.githubusercontent.com/lm-sensors/lm-sensors/${tag}/CHANGES";
description = "Tools for reading hardware sensors";
license = with licenses; [
license = with lib.licenses; [
lgpl21Plus
gpl2Plus
];
maintainers = with maintainers; [ pmy ];
platforms = platforms.linux;
maintainers = with lib.maintainers; [
pmy
oxalica
];
platforms = lib.platforms.linux;
mainProgram = "sensors";
};
}
+1 -1
View File
@@ -67,7 +67,7 @@ stdenv.mkDerivation rec {
optionalPatch = pred: so: lib.optionalString pred "patchelf --add-needed ${so} $out/bin/htop";
in
lib.optionalString (!stdenv.hostPlatform.isStatic) ''
${optionalPatch sensorsSupport "${lm_sensors}/lib/libsensors.so"}
${optionalPatch sensorsSupport "${lib.getLib lm_sensors}/lib/libsensors.so"}
${optionalPatch systemdSupport "${systemd}/lib/libsystemd.so"}
'';