Building imag with nix remote builds

This is mostly a reminder for myself how to do it, because the documentation non the nix side is pretty sparse.

What I want to do is to build imag on a remote server using nix 2.0 features - nix remote builds.

Here are the steps I did for achieving that goal:

  1. build the Cargo.lock file with cargo generate-lock for the imag workspace
  2. generate a build.nix file using carnix --standalone --src . --output build.nix Cargo.lock
  3. monkey-patching the generated nix file because carnix generates wrong pathes for the file in the nix expressions. I did that with a simple substitude pattern in vim: %s/"\.\.\/\.\.\/\.\.\/build\.rs"/.\/
  4. ensure the remote machine has nix 2.0
  5. use NIX_REMOTE=ssh-ng://user@host nix build -f ./build.nix imag_0_7_0 to build imag on the remote machine.

Unfortunately, because the generated expressions do not use cargo but execute the rustc compiler directly, the build fails because I need the CARGO_BUILD_VERSION and CARGO_PKG_VERSION environment variables which are set by cargo during the build.

I hope carnix gets support for automatically adding those variables to the build soonish, so I can build imag completely remote.

tags: #imag #nix #rust