Ruby gem with Nix

I have a small problem with using Ruby flow for Nix. I started off with flox init to initialize Ruby project, fixing the paths to be like this:

gems = bundlerEnv {
    name = "my-env";
    ruby = ruby_3_0;
    gemfile = ../../Gemfile;
    lockfile = ../../Gemfile.lock;
    gemset = ../../gemset.nix;
  };

and even if it built the binary was not functional as technically I installed all dependencies but gem itself was missing.

After some hard search through the nixpkgs I found that there is also buildRubyGem that builds the gem itself.

 myGem = buildRubyGem {
    gemName = "my";
    version = "0.1.0";
    src = self;
    ruby = ruby_3_0;
  };

So I added it and made corrections to wrapper script to extend it with both paths:

in
  stdenv.mkDerivation rec {
    pname = "my";
    version = "0.1.0-${lib.flox-floxpkgs.getRev self}";
    src = self; # + "/src";
    buildInputs = [gems myGem ruby_3_0 makeWrapper];
    installPhase = ''
      mkdir -p $out/bin
      cp ${myGem}/bin/my $out/bin/my
      bin=$out/bin/my

      wrapProgram $bin \
        --prefix GEM_HOME : "${gems}/${ruby_3_0.gemPath}:${myGem}/${ruby_3_0.gemPath}"\
        --prefix GEM_PATH : "${gems}/${ruby_3_0.gemPath}:${myGem}/${ruby_3_0.gemPath}"\
        --prefix PATH : "${lib.makeBinPath [ ruby_3_0 ]}"

      chmod +x $out/bin/my
    '';
    meta.description = "my packaged in Flox";
    meta.mainProgram = "my";
  }

After this, package installed correctly and wrapper knows about bundler-env and built gem itself, but is there something I am doing wrong? I thought that bundlerEnv is supposed to create everything. There is also bundlerApp but it does seem to be more towards developers not package distributors.

Is there some working example of Nix with Ruby with proper gem done and not a just ruby script installed?

The best place to get some help on this one would definitely be Nixpkgs man in their section about Ruby.

I feel your pain though, I’m not a Ruby developer myself but have frequently bumped into pain points trying to package Ruby programs with buildRubyGem and bundlerEnv.