collectd: fix build and modernize derivation slightly

1. I experienced intermittent connection failures to <https://collectd.org> and I suspect it's hosted on hobbyist equipment.
   This made the `src` derivation flaky, so I switched to the upstream GitHub repository.
   It seems better to use the actual source instead of a prepared tarball from the release process anyway.

2. When building out of the source instead of the release tarball, we need to run Bison and Flex to generate the parser and lexer, and we need Perl for `pod2man`.

3. As the [build error on Hydra](https://hydra.nixos.org/build/300269816) notes, `src/virt.c` makes use of some token `ATTRIBUTE_UNUSED` but it's not defined anywhere. Define it.

4. Switch all hashes to use the SRI style.

5. Switch to `finalAttrs` fixpoint style for better overriding.

6. Reduce the scope of `with lib;` in the `meta` section.

Bit of a smörgåsbord but not too bad.
This commit is contained in:
Philip Taron 2025-06-19 12:44:29 -07:00 committed by Bjørn Forsman
parent 18975e6da3
commit 97734f4a9a

View File

@ -1,33 +1,40 @@
{
lib,
stdenv,
fetchurl,
fetchFromGitHub,
fetchpatch,
callPackage,
autoreconfHook,
pkg-config,
libtool,
bison,
flex,
perl,
nixosTests,
...
}@args:
let
plugins = callPackage ./plugins.nix args;
in
stdenv.mkDerivation rec {
version = "5.12.0";
stdenv.mkDerivation (finalAttrs: {
pname = "collectd";
version = "5.12.0";
src = fetchurl {
url = "https://collectd.org/files/${pname}-${version}.tar.bz2";
sha256 = "1mh97afgq6qgmpvpr84zngh58m0sl1b4wimqgvvk376188q09bjv";
src = fetchFromGitHub {
owner = "collectd";
repo = "collectd";
tag = "collectd-${finalAttrs.version}";
hash = "sha256-UTlCY1GPRpbdQFLFUDjNr1PgEdGv4WNtjr8TYbxHK5A=";
};
# All of these are going to be included in the next release
patches = [
# fix -t never printing syntax errors
# should be included in next release
(fetchpatch {
name = "fix-broken-dash-t-option.patch";
url = "https://github.com/collectd/collectd/commit/3f575419e7ccb37a3b10ecc82adb2e83ff2826e1.patch";
sha256 = "0jwjdlfl0dp7mlbwygp6h0rsbaqfbgfm5z07lr5l26z6hhng2h2y";
hash = "sha256-XkDxLITmG0FLpgf8Ut1bDqulM4DmPs8Xrec2QB1tkks=";
})
(fetchpatch {
name = "no_include_longintrepr.patch";
@ -39,7 +46,11 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [
pkg-config
autoreconfHook
bison
flex
perl # for pod2man
];
buildInputs = [
libtool
] ++ plugins.buildInputs;
@ -52,9 +63,12 @@ stdenv.mkDerivation rec {
++ plugins.configureFlags
++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ "--with-fp-layout=nothing" ];
# Used in `src/virt.c`
env.NIX_CFLAGS_COMPILE = "-DATTRIBUTE_UNUSED=__attribute__((unused))";
# do not create directories in /var during installPhase
postConfigure = ''
substituteInPlace Makefile --replace '$(mkinstalldirs) $(DESTDIR)$(localstatedir)/' '#'
substituteInPlace Makefile --replace-fail '$(mkinstalldirs) $(DESTDIR)$(localstatedir)/' '#'
'';
postInstall = ''
@ -69,11 +83,11 @@ stdenv.mkDerivation rec {
inherit (nixosTests) collectd;
};
meta = with lib; {
meta = {
description = "Daemon which collects system performance statistics periodically";
homepage = "https://collectd.org";
license = licenses.gpl2Plus;
platforms = platforms.unix;
maintainers = with maintainers; [ bjornfor ];
license = lib.licenses.gpl2Plus;
platforms = lib.platforms.unix;
maintainers = with lib.maintainers; [ bjornfor ];
};
}
})