Nix how to simulate exact environment when a derivation is being built?

Viewed 191

So I'm doing a simple thing in my rust project which is updating a dependency on git2 from 0.13.25 to 0.14.2. I want to then make a complete build with Nix. When I do a nix-build nix-build nix/ci -A actions.packages.alerting -K (alerting is my project).

I get among other things output:

Building build.rs (libgit2_sys)
Running rustc --crate-name build_script_build build.rs --crate-type bin -C debuginfo=2 -C embed-bitcode=no --edition 2018 --cfg feature="default" --cfg feature="https" --cfg feature="libssh2-sys" --cfg feature="openssl-sys" --cfg feature="ssh" --cfg feature="ssh_key_from_memory" --out-dir target/build/libgit2-sys --emit=dep-info,link -L dependency=target/buildDeps --extern cc=/nix/store/v311xp5vhjymxn9zk855cwihcwi0nj7z-rust_cc-1.0.72-lib/lib/libcc-8cc528ba2b.rlib --extern pkg_config=/nix/store/23mr9d754vngcrkphj9623pv3zchk3sk-rust_pkg-config-0.3.20-lib/lib/libpkg_config-39ea50320b.rlib --cap-lints allow --color always


error occurred: Command "gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/build/libgit2-sys-0.13.2+1.4.2/target/build/libgit2-sys.out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-I" "/nix/store/pny40lfk2s01n2p7w5q8srg4nd5v3w6g-openssl-1.1.1m-dev/include" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/build/libgit2-sys-0.13.2+1.4.2/target/build/libgit2-sys.out/build/libgit2/src/transports/ssh.o" "-c" "libgit2/src/transports/ssh.c" with args "gcc" did not execute successfully (status code exit status: 1).


note: keeping build directory '/tmp/nix-build-rust_libgit2-sys-0.13.2+1.4.2.drv-2'
builder for '/nix/store/ibipalg67ism9cwj4hdcj7ifdqzb2k8f-rust_libgit2-sys-0.13.2+1.4.2.drv' failed with exit code 1
cannot build derivation '/nix/store/0zk6spayh52pappfw0xk6vny9ylmp7kj-rust_alerting-1.10.10-test.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/6364p4kmgangzqqzwgxrmlk260mv45kl-rust_alerting-1.10.10.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/555c1nrvqlzjz71qzyi3s8gjyf7xrxg8-rust_alerting-1.10.10-linked.drv': 1 dependencies couldn't be built
error: build of '/nix/store/555c1nrvqlzjz71qzyi3s8gjyf7xrxg8-rust_alerting-1.10.10-linked.drv' failed

I want to know why this gcc invocation is failing. What I tried doing is going to this kept folder '/tmp/nix-build-rust_libgit2-sys-0.13.2+1.4.2.drv-2', running . env-vars and running "gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/build/libgit2-sys-0.13.2+1.4.2/target/build/libgit2-sys.out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-I" "/nix/store/pny40lfk2s01n2p7w5q8srg4nd5v3w6g-openssl-1.1.1m-dev/include" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/build/libgit2-sys-0.13.2+1.4.2/target/build/libgit2-sys.out/build/libgit2/src/transports/ssh.o" "-c" "libgit2/src/transports/ssh.c" there.

The output I get is In file included from libgit2/src/transports/ssh.h:10, from libgit2/src/transports/ssh.c:8: libgit2/src/common.h:11:11: fatal error: git2/sys/features.h: No such file or directory 11 | # include "git2/sys/features.h" | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated.

I believe this is not the same output I was getting when running nix-build.

Am I missing some step? I want to know the exact output of the gcc compilation so that I can report it to git2-rs repo or if there's a problem in our Nix infra to fix it somehow. I apologize if my question is poor quality; I'm really struggling with debugging nix builds and I've read stuff like https://nixos.wiki/wiki/Nixpkgs/Create_and_debug_packages#Using_nix-shell_for_package_development but it's not helping

1 Answers

I hope the following snippet from my cheat sheet is a good starting point for you:

nix-build --builders '' -K -A package
# path to the kept build directory under /tmp is shown
export out=/tmp/nix-build-package-1.0.0.drv-0
# the following might be required if you run into permission issues
sudo chown $USER:$USER -R $out
nix-shell -E --pure 'with import ./. { }; package'
bash --rcfile $out/env-vars
cd $out/
export TMP=$PWD TMPDIR=$PWD
# start debugging
buildPhase
...
Related