Packaging a software that needs g++ and ocaml at _runtime_

Hello there!
I’ve been trying to package a project of mine that\s a kind of compiler, that uses various other compilers at runtime (ocaml, gcc, g++).
As a newbie it’s been quite challenging, and so far I’m still struggling.

Would you know of any package with similar runtime dependencies, that I could look into for inspiration?

Hello, welcome to the Nix world :wink:

To achieve this, you first have to know how Nix handles runtime dependencies. After building your derivation, Nix automatically checks it for references to /nix/store/… and all store paths referenced in your derivation output are automatically marked as runtime dependencies.

There are multiple ways to make sure the store paths of g++/ocaml/… are referenced in your derivation. You can either make sure that your application references the absolute path, or you can build a wrapper script, which sets the PATH variable to include your runtime dependencies (and thus references them).

Example:

{ stdenv, makeWrapper, gcc, ocaml }:

stdenv.mkDerivation {
  pname = "foo";
  version = "0.1.0";
  src = ./.;

  fixupPhase = ''
    wrapProgram $out/bin/foo --set PATH ${stdenv.lib.makeBinPath [
      gcc
      ocaml
    ]}
  '';
}

You can decide to use --set or --prefix when calling wrapProgram, depending on if you want the application to have access to things in the user’s environment or if you want to specify all dependencies cleanly.