Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoconf improvements, fixing Ubuntu 16.04 build and probably many more #2979

merged 13 commits into from Jul 3, 2019


Copy link

@nh2 nh2 commented Jul 3, 2019

I've put in a lot of effort in the last 2 days to make nix build well from the source repo with a bootstrap build (not depending on nix).

This should greatly improve the situation for Linux distribution packagers, as well as of people who want to quickly contribute to nix (e.g. by improving the manual) without having to have a full nix setup first.

This should fix at least the following long-standing issues, and probably many more:


  • Many possible build failures now result in clear upfront error messages by ./configure (e.g. when C++17 isn't supported or boost or editline libraries are missing or too old).
  • The docbook-without-Internet-and-missing-xsl-files problem is fixed; it now complains upfront what the user can do about it.
  • CXXFLAGS, LDFLAGS etc can now be correctly overridden from outside, as is expected from autoconf projects.
  • It's now detected whether we're in a release tarball, allowing for clearer autoconf logic on what steps we can skip in that case.

Includes the commit from (and thus subsumes) PR #1201.

I recommend to review the changes commit-by-commit, as I've taken care to write useful commit messages.


nh2 and others added 13 commits July 3, 2019 04:32
The unbalanced single-quotes cause many editor syntax highlighters
to interpret the rest of the file as a string literal, making it easier
to make syntax mistakes in absence of proper highlighting.
This turns previous compiler errors complaining about missing files
into proper ./configure time errors telling the user which version
of boost is required.
And probably other Linux distributions with long-term support releases.

Also update manual stating what version is needed;
I checked that 1.14 is the oldest version with which current nix compiles,
and added autoconf feature checks for some functions added in that release
that nix uses.
And probably many other distributions.

Until now, ./configure would fail silently printing a warning

    ./configure: line 4621: AX_CXX_COMPILE_STDCXX_17: command not found

and then continuing, later failing with a C++ #error saying that some C++11
feature isn't supported (it didn't even get to the C++17 features).

This is because older distributions don't come with the
`AX_CXX_COMPILE_STDCXX_17` m4 macro.

This commit vendors that macro accordingly.

Now ./configure complains correctly:

    configure: error: *** A compiler with support for C++17 language features is required.

On Ubuntu 16.04, ./configure completes if a newer compiler is used, e.g. with
gcc-7 from

    ./configure CXX=g++-7 --disable-doc-gen --with-boost=$(nix-build --no-link '<nixpkgs>' -A
autotools-based systems usually allow user to
append own LDFLAGS like
    LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu"
at ./configure stage

This change plumbs LDFLAGS through similar to existing CXXFLAGS variable.

Signed-off-by: Sergei Trofimovich <>
That was incorrect, because checking the dirent type already requires
a working compiler.

It had the effect that setting e.g. `: ${CFLAGS=""}` before `AC_PROG_CC`
as per `AC_PROG_CC`'s documentation would have no effect, because
`AC_STRUCT_DIRENT_D_TYPE` would automatically set CFLASGS.

(In a followup commit `: ${CFLAGS=""}` will be used, so it's important
to get this working first.)
As is normal for autoconf-based projects.

For example, it is a common use case to do

    ./configure CXXFLAGS=-O0

This did not work for nix until now, because the `CXXFLAGS=` declaration
would unconditionally erase what the user had specified.

The custom `OPTIMIZE` flag is removed, but the default `-O3` is retained;
autoconf would default to `-g -O2` by default otherwise as documented on:
It was forgotten to be removed with
commit c5f23f1
and so it until now stayed unsubstituted as `HAVE_READLINE = @HAVE_READLINE@`
in Makefile.config.
For example, Ubuntu 16.04 and many similar long-term-support distros
have older versions.
Our use of boost::coroutine2 depends on -lboost_context,
which in turn depends on `-lboost_thread`, which in turn depends
on `-lboost_system`.

I suspect that this builds on nix only because of low-level hacks

This commit passes the proper linker flags, thus fixing bootstrap
builds on non-nix distributions like Ubuntu 16.04.

With these changes, I can build Nix on Ubuntu 16.04 using:

    ./configure --prefix=$HOME/editline-prefix \
      --disable-doc-gen \
      CXX=g++-7 \
      --with-boost=$HOME/boost-prefix \
      EDITLINE_CFLAGS=-I$HOME/editline-prefix/include \
      EDITLINE_LIBS=-leditline \


* g++-7 comes from gcc-7 from,
* editline 1.14 from
	was installed into `$HOME/editline-prefix`
  (because Ubuntu 16.04's `editline` is too old to have the function nix uses),
* boost 1.66 from
	was installed into $HOME/boost-prefix (because Ubuntu 16.04 only has 1.58)
Also give a helpful error message on what package the user likely
has to install to make it work.
This is to avoid confusion as in commit
This should finally allow us to address all cases of build errors due to
differences between release tarballs and building from git.

See also NixOS#506 (comment)
Copy link

edolstra commented Jul 3, 2019


Copy link

edolstra commented Jul 4, 2019

I had to revert a few commits because they broke the tarball job (e486d8d), looks like there is something going wrong with detecting whether we're building from Git.

Copy link

This pull request has been mentioned on Nix community. There might be relevant details there:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

4 participants