Compiling macaulay2: issue with git submodules

Hello! I’m fairly new to Nix, and I’m trying to write a derivation that will compile macaulay2, but I’ve run into an issue. If I’m understanding what’s going on correctly, it seems like it fails in the very beginning of the build phase, when it tries to git submodule update one of its dependencies.

Here’s the last 25 lines of the log:

configurePhase completed in 51 seconds
Running phase: buildPhase
make: Entering directory '/build/source/M2/BUILD/build'
: "checking for strings that look like undefined configure variables in all *.in files..."
: creating or removing symbolic link to common staging area, if necessary,
: based on comparison of these directories:
:                      pre_prefix : /build/source/M2/BUILD/build/usr-dist/common
: abs_builddir/usr-dist/common : /build/source/M2/BUILD/build/usr-dist/common
rm -f srcdir .link-test
echo "../../" >srcdir
rm -f M2
(echo '#! /bin/sh'; echo 'exec /build/source/M2/BUILD/build/usr-dist/x86_64-Linux-nixos/bin/M2 "$@"') >M2
chmod a+x M2
make -C libraries all
make[1]: Entering directory '/build/source/M2/BUILD/build/libraries'
make -C gc fetch
make[2]: Entering directory '/build/source/M2/BUILD/build/libraries/gc'
git submodule update --init /build/source/M2/BUILD/build/../../submodules/bdwgc
error: pathspec '/build/source/M2/BUILD/build/../../submodules/bdwgc' did not match any file(s) known to git
make[2]: *** [../Makefile.library:137: update-submodule] Error 1
make[2]: Leaving directory '/build/source/M2/BUILD/build/libraries/gc'
make[1]: *** [Makefile:7: fetch-in-gc] Error 2
make[1]: Leaving directory '/build/source/M2/BUILD/build/libraries'
make: *** [Makefile:57: all-in-libraries] Error 2
make: Leaving directory '/build/source/M2/BUILD/build'

And this is the contents of the derivation:

{ pkgs, ... }: (let
    boost-static = (pkgs.boost.override {
        enableShared = false;
        enableStatic = true;
    });
in (pkgs.stdenv.mkDerivation rec {
    pname = "macaulay2";
    version = "1.25.06";

    # cf. [[https://github.com/NixOS/nixpkgs/issues/195117#issuecomment-1410398050]]
    src = ((pkgs.fetchFromGitHub {
        owner = "Macaulay2";
        repo = "M2";
        rev = "2cb101f52dfdd3abe788f2d5e1d0248adeb10b32";
        fetchSubmodules = true;
        leaveDotGit = true;
        hash = "sha256-BU01garuNkyH7Z8AOD4EjgkggqJpMqANFdDUmJmwxm8=";
    }).overrideAttrs (old-attrs: {
        env = old-attrs.env or {} // {
            GIT_CONFIG_COUNT = 1;
            GIT_CONFIG_KEY_0 = "url.https://github.com/.insteadOf";
            GIT_CONFIG_VALUE_0 = "git@github.com:";
        };
    }));

    buildInputs = with pkgs; [
        autoconf
        automake
        bison
        boost-static
        cddlib
        cmake
        eigen
        fflas-ffpack
        flex
        flint
        gcc
        gfortran
        gfan
        git
        givaro
        glpk
        gtest
        icu
        libffi
        libtool
        libxml2
        libz
        lrs
        mpfi
        nauty
        ncurses
        normaliz
        ntl
        openblas
        patch
        pkg-config
        python3
        singular
        texinfo
        time
        wget
        which
        xz
    ];

    configurePhase = ''
        cd M2/BUILD/build
        ../../autogen.sh
        ../../configure --enable-shared --enable-download --with-issue='nixos' \
            --with-boost-libdir=${boost-static.out}/lib
    '';
    buildPhase = ''
        make
    '';
    installPhase = ''
        mkdir -p $out/bin
        mv M2 $out/bin
    '';
}))

(Sorry if there are any formatting issues; this is my first post here!)

you can try turning GIT_SUBMODULE off via cmake flags M2/M2/cmake/configure.cmake at a12b1079a5374d0c8e6c174f83a24d88aeaaa697 · Macaulay2/M2 · GitHub

if that doesn’t work create a patch removing the submodule update logic.

nix doesn’t allow accessing the network when building, it only allows fixed output derivations to access the network, usually they have a hash specified (under the hood gets set as outputHash), in this case only when fetching the src network access is allowed.

That makes sense, thank you! I’ve tried adding the attribute

cmakeFlags = [
    (lib.strings.cmakeBool "GIT_SUBMODULE" false)
];

to the arguments of mkDerivation, but I’m still getting the same error. Is this not the correct way to unset the option, or will I have to dig around in the source code?

1 Like