CMake and Corrosion couldn't resolve host name

I have a project that is c++ that I’m porting parts to rust and am using cxx and cxx-qt to use some rust over c++. I can build this project just fine in my nix develop shell. However, once I try to run nix build. It fails by saying it couldn’t resolve host name to download dependecies for building with cargo. I’m running cargo through corrosion. That’s a cmake component to build rust projects with cargo. Here is my nix log.

@nix { "action": "setPhase", "phase": "qtPreHook" }
qtPreHook
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/knzjkk9a1b3j387pb79a1i452kix1fb5-p99mk8hvd6310s11l1sj2jwx64848f06-source
source root is p99mk8hvd6310s11l1sj2jwx64848f06-source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
fixing cmake files...
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/doc/presenter -DCMAKE_INSTALL_INFODIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/include -DCMAKE_INSTALL_SBINDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/k04h29hz6qs45pn0mzaqbyca63lrz2s0-gcc-wrapper-11.3.0/bin/strip -DCMAKE_RANLIB=/nix/store/k04h29hz6qs45pn0mzaqbyca63lrz2s0-gcc-wrapper-11.3.0/bin/ranlib -DCMAKE_AR=/nix/store/k04h29hz6qs45pn0mzaqbyca63lrz2s0-gcc-wrapper-11.3.0/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter  -DKDE_INSTALL_EXECROOTDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter -DKDE_INSTALL_BINDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/bin -DKDE_INSTALL_SBINDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/sbin -DKDE_INSTALL_LIBDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/lib -DKDE_INSTALL_LIBEXECDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/libexec -DKDE_INSTALL_CMAKEPACKAGEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/lib/cmake -DKDE_INSTALL_INCLUDEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/include -DKDE_INSTALL_LOCALSTATEDIR=/var -DKDE_INSTALL_DATAROOTDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share -DKDE_INSTALL_DATADIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share -DKDE_INSTALL_DOCBUNDLEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/doc/HTML -DKDE_INSTALL_KCFGDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/config.kcfg -DKDE_INSTALL_KCONFUPDATEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/kconf_update -DKDE_INSTALL_KSERVICES5DIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/kservices5 -DKDE_INSTALL_KSERVICETYPES5DIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/kservicetypes5 -DKDE_INSTALL_KXMLGUI5DIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/kxmlgui5 -DKDE_INSTALL_KNOTIFY5RCDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/knotifications5 -DKDE_INSTALL_ICONDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/icons -DKDE_INSTALL_LOCALEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/locale -DKDE_INSTALL_SOUNDDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/sounds -DKDE_INSTALL_TEMPLATEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/templates -DKDE_INSTALL_WALLPAPERDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/wallpapers -DKDE_INSTALL_APPDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/applications -DKDE_INSTALL_DESKTOPDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/desktop-directories -DKDE_INSTALL_MIMEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/mime/packages -DKDE_INSTALL_METAINFODIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/appdata -DKDE_INSTALL_MANDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/man -DKDE_INSTALL_INFODIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/info -DKDE_INSTALL_DBUSDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/dbus-1 -DKDE_INSTALL_DBUSINTERFACEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/dbus-1/interfaces -DKDE_INSTALL_DBUSSERVICEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/dbus-1/services -DKDE_INSTALL_DBUSSYSTEMSERVICEDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/share/dbus-1/system-services -DKDE_INSTALL_SYSCONFDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/etc -DKDE_INSTALL_CONFDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/etc/xdg -DKDE_INSTALL_AUTOSTARTDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/etc/xdg/autostart -DKDE_INSTALL_QTPLUGINDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/lib/qt-5.15.7/plugins -DKDE_INSTALL_PLUGINDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/lib/qt-5.15.7/plugins -DKDE_INSTALL_QMLDIR=/nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter/lib/qt-5.15.7/qml 
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/k04h29hz6qs45pn0mzaqbyca63lrz2s0-gcc-wrapper-11.3.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/k04h29hz6qs45pn0mzaqbyca63lrz2s0-gcc-wrapper-11.3.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
e[0mInstalling in /nix/store/c5nln85v7z2lmyck0ckskvnl523pa2wr-Libre-Presenter. Run /build/p99mk8hvd6310s11l1sj2jwx64848f06-source/build/prefix.sh to set the environment for presenter.e[0m
-- Looking for __GLIBC__
-- Looking for __GLIBC__ - found
-- Performing Test _OFFT_IS_64BIT
-- Performing Test _OFFT_IS_64BIT - Success
-- Performing Test HAVE_DATE_TIME
-- Performing Test HAVE_DATE_TIME - Success
-- Found KF5Kirigami2: /nix/store/4slana8xxhdbazvdgfj3z7hkk7lsrs4w-kirigami2-5.100.0-dev/lib/cmake/KF5Kirigami2/KF5Kirigami2Config.cmake (found version "5.100.0") 
-- Found Gettext: /nix/store/sa6z32f4qlvncxfll1d8a10gx3sxnvng-gettext-0.21/bin/msgmerge (found version "0.21") 
-- Found KF5I18n: /nix/store/0zxj49w6bv7znm9l0v5cfb2s1fjz8yl6-ki18n-5.100.0-dev/lib/cmake/KF5I18n/KF5I18nConfig.cmake (found version "5.100.0") 
-- Found KF5Archive: /nix/store/a0ir57ipfysrrjyb76llyvp8xn71d7jc-karchive-5.100.0-dev/lib/cmake/KF5Archive/KF5ArchiveConfig.cmake (found version "5.100.0") 
-- Found KF5CoreAddons: /nix/store/4nf725ihn0lw46d5za7yq81sphv7cvas-kcoreaddons-5.100.0-dev/lib/cmake/KF5CoreAddons/KF5CoreAddonsConfig.cmake (found version "5.100.0") 
-- Found KF5: success (found version "5.100.0") found components: Kirigami2 I18n Archive CoreAddons 
Package wayland-client was not found in the pkg-config search path.
Perhaps you should add the directory containing `wayland-client.pc'
to the PKG_CONFIG_PATH environment variable
Package 'wayland-client', required by 'mpv', not found
Package wayland-client was not found in the pkg-config search path.
Perhaps you should add the directory containing `wayland-client.pc'
to the PKG_CONFIG_PATH environment variable
Package 'wayland-client', required by 'mpv', not found
Package wayland-client was not found in the pkg-config search path.
Perhaps you should add the directory containing `wayland-client.pc'
to the PKG_CONFIG_PATH environment variable
Package 'wayland-client', required by 'mpv', not found
Package wayland-client was not found in the pkg-config search path.
Perhaps you should add the directory containing `wayland-client.pc'
to the PKG_CONFIG_PATH environment variable
Package 'wayland-client', required by 'mpv', not found
-- Found Libmpv: /nix/store/hcgb0yc33bzyfwibx1vn2637xf7w8fl9-mpv-with-scripts-0.35.0/lib/libmpv.so (found version "2.0.0") 
e[0mpodofo/podofo.h: /nix/store/qa7bgwmg6axkljm4faxr5rv90by71s9w-podofo-0.9.8-dev/includee[0m
e[0mpodofo lib: /nix/store/rgz4fhfg3kkkhpf5wx4kcngcxf09w12l-podofo-0.9.8-lib/lib/libpodofo.soe[0m
e[0mPoDoFo cflags: e[0m
-- Rust Target: x86_64-unknown-linux-gnu
-- Found Rust: /nix/store/f9b9jfn5qr9h2mg7jadl1dmm3b0ahc3w-rustc-1.65.0/bin/rustc (found version "1.65.0") 
-- Using Corrosion as a subdirectory
    Updating crates.io index
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
error: failed to get `cxx` as a dependency of package `qml-minimal v0.1.0 (/build/p99mk8hvd6310s11l1sj2jwx64848f06-source/src/rust)`

Caused by:
  failed to load source for dependency `cxx`

Caused by:
  Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
e[31mCMake Error at /nix/store/n9hjxcinslrhhdmi2cxjvq1z1kzmcq12-corrosion-0.3.0/share/cmake/CorrosionGenerator.cmake:10 (execute_process):
  execute_process failed command indexes:

    1: "Child return code: 101"

Call Stack (most recent call first):
  /nix/store/n9hjxcinslrhhdmi2cxjvq1z1kzmcq12-corrosion-0.3.0/share/cmake/CorrosionGenerator.cmake:171 (_cargo_metadata)
  /nix/store/n9hjxcinslrhhdmi2cxjvq1z1kzmcq12-corrosion-0.3.0/share/cmake/Corrosion.cmake:1111 (_generator_add_cargo_targets)
  CMakeLists.txt:78 (corrosion_import_crate)

e[0m
-- Configuring incomplete, errors occurred!
See also "/build/p99mk8hvd6310s11l1sj2jwx64848f06-source/build/CMakeFiles/CMakeOutput.log".

Does anyone have any idea what’s happening here? I am calling this package with libsForQt5.callPackage. Could that be why apparently cargo can’t touch the net? I’m just lost.

There is no network connectivity in the build sandbox. This is by design, for reproducibility. You’ll need to isolate the downloads that need to be done, do them with separate fetchers, and provide them to the build system in such a way that it doesn’t try to access the network.

Ah! Ok, well, that gives me a direction, thank you! I don’t know why or how I didn’t know that! So, is this why folks use things like cargo2nix for rust development? Or is there a way I can do that?

Yes, that’s one of the primary reasons various ‘2nix’ tools exist. The problem of how to do that kind of thing can often be solved at a per-ecosystem level. You’d have to ask someone else to know what’s the right such tool to use in the rust ecosystem, though, as I don’t really deal with it.

Well, thank you very much for the insight! I’ll dig into those tools and see what I can come up with!