bobvanderlinden / nixpkgs-ruby

A Nix repository with all Ruby versions being kept up-to-date automatically
130 stars 26 forks source link

jemallocSupport with gems #118

Open emptyflask opened 7 months ago

emptyflask commented 7 months ago

I'm attempting to enable jemalloc with ruby, which appears to work fine, but it isn't available to gems. I thought that maybe since it was in ruby's propagatedBuildInputs, the gems would have it, but no.

        pkgs = import nixpkgs {
          inherit system;
          overlays = [ bob-ruby.overlays.default ];
        };
        rubyNix = ruby-nix.lib pkgs;
        gemset = if builtins.pathExists ./gemset.nix then import ./gemset.nix else { };
        rubyVersion = nixpkgs.lib.fileContents ./.ruby-version;

        ruby = pkgs."${rubyVersion}".override {
          jemallocSupport = true;
          yjitSupport = true;
        };

I wrote a function to add it to each gem's buildInputs, but merging that with defaultGemConfig replaces the existing builtInputs, so perhaps a "deep merge" is needed instead:

        jemallocGemConfig = builtins.listToAttrs (map (name: {
          inherit name;
          value = attrs: attrs // { buildInputs = (attrs.buildInputs or []) ++ [ pkgs.jemalloc ]; };
        }) (builtins.attrNames gemset));
      in rec {
        inherit (rubyNix {
          inherit gemset ruby;
          name = "chronos";
          gemConfig = pkgs.defaultGemConfig // jemallocGemConfig;
        }) env;
        devShells = rec {
          dev = pkgs.mkShell { buildInputs = [ env ] };
          default = dev;
        };
      };

But I'm probably thinking about this the wrong way. Surely there's some better/simpler way to use jemalloc with gems. I can try posting this to the bundix repo as well if that makes more sense.

bobvanderlinden commented 5 months ago

I'm not fully aware of how ruby-nix should work, but from the code it seems the ruby package that is supplied isn't really being used.

See the unused deconstructed attribute ruby in https://github.com/inscapist/ruby-nix/blob/a9a0f7d7605abca80e40fa3627b7e9cb9e639441/modules/gems/default.nix#L3C3-L3C7. ruby needs to be supplied to buildRubyGem.

It doesn't seem to have to do with nixpkgs-ruby.

inscapist commented 3 months ago

hey @bobvanderlinden thanks for pointing out the unused ruby. And sorry for being late to the scene.

This has been fixed in https://github.com/inscapist/ruby-nix/pull/41

Also, it would not work out of the box until jemalloc is added to propagatedBuildInputs, it is currently added to buildInputs, I have filed another PR for that