# Ruby gem with Nix

**URL:** <https://discourse.flox.dev/t/ruby-gem-with-nix/745>\
**Category:** Nix\
**Created:** [May 19, 2023, 12:39pm UTC](https://discourse.flox.dev/t/ruby-gem-with-nix/745 "2023-05-19T12:39:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon59756714](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon59756714](https://discourse.flox.dev/u/anon59756714)\
**Post date:** [May 19, 2023, 12:39pm UTC](https://discourse.flox.dev/t/ruby-gem-with-nix/745/1 "2023-05-19T12:39:19Z")

</div>

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:

```auto
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.

```auto
 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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![aameen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.flox.dev/aameen/32/564_2.png) [@aameen](https://discourse.flox.dev/u/aameen)\
**Post date:** [September 15, 2023, 2:40pm UTC](https://discourse.flox.dev/t/ruby-gem-with-nix/745/2 "2023-09-15T14:40:31Z")

</div>

The best place to get some help on this one would definitely be [Nixpkgs man](https://nixos.org/manual/nixpkgs/stable/) 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`.
