Building fence-agents (confusion with automake/autoreconf/cmake)

Hey Guys

I want to build Fence Agents and took some help from the debian package.

This is the derivation I currently have:

{
  #fetchFromGitHub, stdenv, autoconf, automake
  #, python3, git, perl, iputils, glib, nspr, nss, libtool,
  #time, libxslt, xml2, perl534Packages
  pkgs ? import <nixpkgs> {}
}:
let
  pythonWithPackages = pkgs.python3.withPackages(ps: with ps; [
    boto3
    google-api-python-client
    oauth2client
    pexpect
    pycurl
    requests
    # The following pkg is broken. Let's hope we don't depend on it...
    #python3Packages.suds-jurko
    # For fence_azure_arm
    adal
    azure-core
    # For fene_openstack
    keystoneauth1
    python-keystoneclient
    python-novaclient
  ]);
in
pkgs.stdenv.mkDerivation rec {
  pname = "fence-agents";
  version = "v4.11.0";

  src = pkgs.fetchFromGitHub {
    owner = "ClusterLabs";
    repo = "fence-agents";
    rev = version;
    sha256 = "sha256-yy/ONp4PzitF9Vet5dWmMJaoGaQhsqms9EbmQtawCvA=";
  };

  nativeBuildInputs = with pkgs; [
    autoreconfHook
    bison
  ];
  buildInputs = with pkgs; [
    git
    perl
    iputils
    #libglibutil
    glib
    nspr
    nss
    nssTools
    libtool
    time
    libxslt
    #xml2 # In debian libxml2-utils -> xmllint
    libxml2
    perl534Packages.NetTelnet
  ];

  propagatedBuildInputs = [
    pythonWithPackages
  ];

  preConfigure = ''
    echo 4.11.0 > .tarball-version
  '';
  installPhase = ''
    mkdir -p "$out/usr/{libexec,sbin,share}"
    cp -r usrl/libexec/fence-agents/fence_kdump_send $out/usrl/libexec/fence-agents/
    cp -r usr/share/* $out/usr/share
    cp usr/sbin/fence* $outusr/sbin/
  '';
}

But when I try to nix-build default.nix I get the following error:

./configure: line 20832: syntax error near unexpected token `nss,'
./configure: line 20832: `                      PKG_CHECK_MODULES(nss, nss)'
error: builder for '/nix/store/5r8d6gcfav9i85lslh84d8j195kvyw78-fence-agents-v4.11.0.drv' failed with exit code 2;
       last 10 log lines:
       > checking for select... yes
       > checking for socket... yes
       > checking for strcasecmp... yes
       > checking for strchr... yes
       > checking for strdup... yes
       > checking for strerror... yes
       > checking for strtol... yes
       > checking for gettimeofday... yes
       > ./configure: line 20832: syntax error near unexpected token `nss,'
       > ./configure: line 20832: `                        PKG_CHECK_MODULES(nss, nss)'
       For full logs, run 'nix log /nix/store/5r8d6gcfav9i85lslh84d8j195kvyw78-fence-agents-v4.11.0.drv'.

I guess somehow the preConfigure misses something, or that the autoreconfHook is the wrong tool, but I have no idea how these tools work and googling didn’t seem to help me much. I figured that when I add cmake to the nativeBuildInputs the error changes to the following:

CMake Error: The source directory "/build/source" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
error: builder for '/nix/store/ndfi6bvnf1823qa74mp2imcpvc10cl43-fence-agents-v4.11.0.drv' failed with exit code 1;
       last 10 log lines:
       > configure.ac:53: installing './config.sub'
       > configure.ac:17: installing './install-sh'
       > configure.ac:17: installing './missing'
       > agents/Makefile.am: installing './depcomp'
       > autoreconf: Leaving directory '.'
       > configuring
       > fixing cmake files...
       > cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/share/doc/fence-agents -DCMAKE_INSTALL_INFODIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/include -DCMAKE_INSTALL_SBINDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/k0np19xv7wjc1grhrb2y6r85qiv1cikd-gcc-wrapper-11.2.0/bin/strip -DCMAKE_RANLIB=/nix/store/vzsqcldzq3y8cwj0mr8pbc6x9w1jmfj1-binutils-2.38/bin/ranlib -DCMAKE_AR=/nix/store/vzsqcldzq3y8cwj0mr8pbc6x9w1jmfj1-binutils-2.38/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/cy3vdld1lvddb5rjzbpfbawjp6l9rdpf-fence-agents-v4.11.0
       > CMake Error: The source directory "/build/source" does not appear to contain CMakeLists.txt.
       > Specify --help for usage, or press the help button on the CMake GUI.
       For full logs, run 'nix log /nix/store/ndfi6bvnf1823qa74mp2imcpvc10cl43-fence-agents-v4.11.0.drv'.

AFAIU adding cmake only adds something to the configurePhase which fails even earlier and doesn’t really add anything, but I’m really very new to these build tools and combined with the NixOS magic it’s a bit confusing…

So am I right, is cmake unnecessary and just moves the error somewhere else?
And do I miss something else in the preConfigure or nativeBuildInputs?

(I’m also open to any suggestion for making this derivation better. My intention is to add this package to nixpkgs :slight_smile: )

I think you are missing pkg-config in nativeBuildInputs and some suggestion to make updating easier.

pkgs.stdenv.mkDerivation rec {
  pname = "fence-agents";
  version = "4.11.0";
...
    repo = "fence-agents";
    rev = "v${version}";
    sha256 = "sha256-yy/ONp4PzitF9Vet5dWmMJaoGaQhsqms9EbmQtawCvA=";
  };
...
  preConfigure = ''
    echo ${version} > .tarball-version
  '';
1 Like