Skip to content

Commit

Permalink
lm_sensors: fix build, split outputs, modernize and remove perl from …
Browse files Browse the repository at this point in the history
…library closure (#373242)
  • Loading branch information
r-vdp authored Jan 18, 2025
2 parents 7d0f11e + dcd56b1 commit 322147e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
7 changes: 3 additions & 4 deletions pkgs/by-name/fa/fan2go/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ 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
# possible under the sandbox.
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";
Expand Down
64 changes: 47 additions & 17 deletions pkgs/by-name/lm/lm_sensors/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,63 @@
lib,
stdenv,
fetchFromGitHub,
fetchpatch,
bash,
bison,
flex,
which,
perl,
rrdtool,
sensord ? false,
rrdtool ? null,
}:

assert sensord -> rrdtool != null;
let
version = "3.6.0";
tag = lib.replaceStrings [ "." ] [ "-" ] version;
in

stdenv.mkDerivation rec {
stdenv.mkDerivation {
pname = "lm-sensors";
version = "3.6.0";
dashedVersion = lib.replaceStrings [ "." ] [ "-" ] version;
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 = [
bison
flex
which
];

# bash is required for correctly replacing the shebangs in all tools for cross-compilation.
buildInputs = [
bash
Expand All @@ -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";
};
}
2 changes: 1 addition & 1 deletion pkgs/tools/system/htop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
'';

Expand Down

0 comments on commit 322147e

Please sign in to comment.