Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gemset generation for Gem version including the platform requirement #67

Closed

Conversation

Morriar
Copy link

@Morriar Morriar commented Oct 9, 2019

Some gems like sorbet-static or sys-proctable (< 1.2) compose their version number by appending the platform cpu, os and version.

For example, the following Gemfile:

source 'https://rubygems.org' do
  gem 'sorbet', '= 0.4.4821'
end

Gives the following Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    sorbet (0.4.4821)
      sorbet-static (= 0.4.4821)
    sorbet-static (0.4.4821-universal-darwin-14)

PLATFORMS
  ruby

DEPENDENCIES
  sorbet (= 0.4.4821)!

BUNDLED WITH
   1.12.5

But will produce the following gemset.nix file with bundix:

{
  sorbet = {
    dependencies = ["sorbet-static"];
    groups = ["development" "test"];
    platforms = [];
    source = {
      remotes = ["https://rubygems.org"];
      sha256 = "099nvhim356rvg0rmx71lnr74fy0rbh6m51fzknwsb59dskn0nrg";
      type = "gem";
    };
    version = "0.4.4821";
  };
  sorbet-static = {
    groups = ["default" "development" "test"];
    platforms = [];
    source = {
      remotes = ["https://rubygems.org"];
      sha256 = "0v0ldhw7wqh9554l002lz7vzqjhkcqwhnr3k14c85fqwmrfixhxm";
      type = "gem";
    };
    version = "0.4.4821";
  };
}

Notice how the platform specified in the Gemfile.lock for sorbet-static is lost when the gemset.nix is generated. From 0.4.4821-universal-darwin-14 to 0.4.4821.

This is a problem since the package manager for NixOs only relies on the version attribute to download the required gem (code copied from https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/ruby-modules/gem/default.nix#L56-L62):

    if type == "gem" then
      fetchurl {
        urls = map (
          remote: "${remote}/gems/${gemName}-${version}.gem"
        ) (attrs.source.remotes or [ "https://rubygems.org" ]);
        inherit (attrs.source) sha256;
      }

This pull-request appends the platform to the compiled gemset.nix file so we get:

{
  sorbet-static = {
    groups = ["default" "development" "test"];
    platforms = [];
    source = {
      remotes = ["https://rubygems.org"];
      sha256 = "0v0ldhw7wqh9554l002lz7vzqjhkcqwhnr3k14c85fqwmrfixhxm";
      type = "gem";
    };
    version = "0.4.4834-universal-darwin-14";
  };
}

And the NixOS package manager is happy.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@@ -85,10 +85,19 @@ def platforms(spec, dep_cache)
{platforms: platforms}
end

def version(spec)
platform = spec.platform
if platform == Gem::Platform::RUBY || platform.nil?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Morriar
Copy link
Author

Morriar commented Oct 15, 2019

Closing this one in favor of #68 which handle the problem more gracefully.

@Morriar Morriar closed this Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant