How to get install prefix correct with autotools?

I noticed i3blocks is very outdated, the last release is from 4 year ago, but the project is still making active progress, so I thought I would update the nix script.

The project has changed quite a lot. One particular change is using autotools to build the project. I have gotten this far with just modifying the old build script:

{ fetchFromGitHub, stdenv, autoconf, automake
, iproute, acpi, sysstat, xset, playerctl
, cmus, openvpn, lm_sensors, alsaUtils
}:

with stdenv.lib;

stdenv.mkDerivation rec {
  name = "i3blocks-${version}";
  version = "1.4";

  src = fetchFromGitHub {
    owner = "vivien";
    repo = "i3blocks";
    rev = "ec050e79ad8489a6f8deb37d4c20ab10729c25c3";
    sha256 = "1fx4230lmqa5rpzph68dwnpcjfaaqv5gfkradcr85hd1z8d1qp1b";
  };

  configurePhase = ''
    ./autogen.sh
    ./configure
  '';

  nativeBuildInputs = [ autoconf automake ];

  buildFlags = "SYSCONFDIR=/etc all";
  installFlags = "PREFIX=${placeholder "out"} VERSION=${version}";

  meta = {
    description = "A flexible scheduler for your i3bar blocks";
    homepage = https://github.com/vivien/i3blocks;
    license = licenses.gpl3;
    platforms = with platforms; freebsd ++ linux;
  };
}

This results in the following error:

installing
install flags: SHELL=/nix/store/cinw572b38aln37glr0zb8lxwrgaffl4-bash-4.4-p23/bin/bash PREFIX=/nix/store/cf5f1md6ic1ppnr6daz77knix1szkcm5-i3blocks-1.4 VERSION=1.4 install
make[1]: Entering directory '/build/source'
 /nix/store/d9s1kq1bnwqgxwcvv4zrc36ysnxg8gv7-coreutils-8.30/bin/mkdir -p '/usr/local/bin'
/nix/store/d9s1kq1bnwqgxwcvv4zrc36ysnxg8gv7-coreutils-8.30/bin/mkdir: cannot create directory '/usr': Permission denied

I am confused, since the PREFIX flag in install flags is correctly pointing to the right directory, but still the builder is trying to install it to /usr/local/bin. I already found this topic: Generic builder: minimal autoconf example? and fixed my prefix flag with its help. Maybe I’m setting the wrong flag?

This works here:

{ fetchFromGitHub, stdenv, autoconf, automake
, iproute, acpi, sysstat, xset, playerctl
, cmus, openvpn, lm_sensors, alsaUtils
}:

with stdenv.lib;

stdenv.mkDerivation rec {
  name = "i3blocks-${version}";
  version = "1.4";

  src = fetchFromGitHub {
    owner = "vivien";
    repo = "i3blocks";
    rev = "ec050e79ad8489a6f8deb37d4c20ab10729c25c3";
    sha256 = "1fx4230lmqa5rpzph68dwnpcjfaaqv5gfkradcr85hd1z8d1qp1b";
  };

  preConfigure = ''
    ./autogen.sh
  '';

  nativeBuildInputs = [ autoconf automake ];

  meta = {
    description = "A flexible scheduler for your i3bar blocks";
    homepage = https://github.com/vivien/i3blocks;
    license = licenses.gpl3;
    platforms = with platforms; freebsd ++ linux;
  };
}
2 Likes

While @manveru has provided a solution already, a little explanation might help:
The stdenv.mkDerivation does a lot of things automatically, including setting several flags for ./configure.
If you override the configurePhase, then you loose all that magic and would have to reinvent the wheel by setting all those flags yourself.
The preConfigure phase is available for the occasions where you have to do something before you can run the configure script.
More details about the phases can be found here: Nixpkgs 23.11 manual | Nix & NixOS

2 Likes

Or use this that does it for you automatically:

nativeBuildInputs = [ autoreconfHook ];

Then you can get rid of the preConfigure bit.

6 Likes

Thank you all for your input!

I made the suggested edits (especially the part with autoreconfHook was something I couldn’t have come up with by myself) and the corresponding pull request is now merged! i3blocks: 1.4 -> unstable-2019-02-07 by ilikeavocadoes · Pull Request #59099 · NixOS/nixpkgs · GitHub