cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
4.22k stars 315 forks source link

autotools not finding each other #259

Open ankhers opened 1 year ago

ankhers commented 1 year ago

Describe the bug I have a project that I have just been using lorri for. I would like to migrate that project over to using devenv.

To Reproduce

The project is an Elixir/Erlang project that has some C code (a NIF in the BEAM world) that needs to be compiled. When using the following shell.nix file,

{ pkgs ? import <nixpkgs> { } }:

with pkgs;

mkShell {
  buildInputs = [
    elixir
    elixir_ls
    autoreconfHook
  ];
}

I am able to compile everything correctly. However when I try to switch to devenv and include autoreconfHook in my packages list, I get the following error when trying to compile.

autoreconf: export WARNINGS=
autoreconf: Entering directory '.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -Im4
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: configure.ac: not using Intltool
autoreconf: configure.ac: not using Gtkdoc
autoreconf: running: /nix/store/idc80c1893y1mbfg98v9kphc03rjd1in-autoconf-2.71/bin/autoconf --force
configure.ac:32: warning: The macro `AC_TRY_COMPILE' is obsolete.
configure.ac:32: You should run autoupdate.
./lib/autoconf/general.m4:2847: AC_TRY_COMPILE is expanded from...
lib/m4sugar/m4sh.m4:594: AS_CASE is expanded from...
lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
m4/ax_tls.m4:49: AX_TLS is expanded from...
configure.ac:32: the top level
autoreconf: running: /nix/store/idc80c1893y1mbfg98v9kphc03rjd1in-autoconf-2.71/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
src/Makefile.am:5: error: Libtool library used but 'LIBTOOL' is undefined
src/Makefile.am:5:   The usual way to define 'LIBTOOL' is to add 'LT_INIT'
src/Makefile.am:5:   to 'configure.ac' and run 'aclocal' and 'autoconf' again.
src/Makefile.am:5:   If 'LT_INIT' is in 'configure.ac', make sure
src/Makefile.am:5:   its definition is in aclocal's search path.
autoreconf: error: automake failed with exit status: 1
===> Hook for compile failed!

I am not super familiar with compiling C code, but I believe autoreconfHook is not being handled correctly for some reason. I have manually added the autoconf, automake and libtool packages.

You can find a failing example here

Version

devenv: 0.5

domenkozar commented 1 year ago

We don't support setup-hooks and instead ship with our own mechanism to provide environment variables.

The drawback is that we're not entirely compatible 1:1 with shell.nix, so that's something to be documented.

ankhers commented 1 year ago

Something else here. If I use nix-shell -p autoconf automake gettext libtool, I am able to build things correctly. If I take the same list of packages and place them in the packages list of my devenv.nix file, I am unable to build. I get the previously mentioned error. So it seems like I do not actually need autoreconfHook, which is good. But I am wondering why these packages no longer work with devenv?

My best guess is that autoreconf is unable to find libtool and thinks it is not installed.

Any chance anyone with more knowledge of autoreconf would be able to chime in?

domenkozar commented 1 year ago

@ankhers What commands do I need to run to reproduce this in your git repo example?

ankhers commented 1 year ago

Here is an even more minimal example.

  1. Clone https://github.com/tzvetkoff/hashids.c.git
  2. Init devenv and use the following devenv.nix
{ pkgs, ... }:

{
  # https://devenv.sh/basics/
  # env.GREET = "devenv";

  # https://devenv.sh/packages/
  packages = [ pkgs.autoconf pkgs.automake pkgs.gettext pkgs.libtool ];

  # https://devenv.sh/languages/
  languages.c.enable = true;
}
  1. Run either ./bootstrap or autoreconf -vfi (the bootstrap executable only runs that command anyways)
  2. See the failure that I originally mentioned

Now if we start over and use nix-shell instead,

  1. Clone the same repo
  2. Run nix-shell -p autoconf automake libtool
  3. Run either ./bootstrap or autoreconf -vfi
  4. See that it succeeds

As mentioned previously, for some reason libtool seems to not be found.

ankhers commented 1 year ago

adding

  env.ACLOCAL_PATH = "${pkgs.libtool}/share/aclocal";

to my devenv.nix file seems to fix this issue.

domenkozar commented 1 year ago

Should be added to https://github.com/cachix/devenv/blob/02cf4ceafb81a49918c97db723454334b1ebb7d1/src/modules/mkNakedShell.nix#L98

domenkozar commented 1 year ago

This should be fixed in #745

therealpxc commented 1 week ago

@ankhers does this still affect you?