forked from nix-community/bundix
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change format of generate
gemset.nix
files
This commit is an attempt to make Bundix more "platform-aware." Every rubygem has a "platform" field which names the ruby-platform that it can run on. For the vast majority of gems, this will be `"ruby"`, indicating that it's a gem written entirely in ruby and should be able to run on any ruby interpreter; however, there are some gems that rely on native extensions that might only work on certain systems. The previous `gemset.nix` format is generated exactly from the contents of the inputted `Gemfile.lock`. So if the `Gemfile.lock` included a reference to `nokogiri (1.14.2)`, Bundix would render a `gemset.nix` that included the sha256 hash for the ruby-platform version of that gem. The trouble with this behaviour is that both RubyGems and Bundler, at install time, will want to install the platform-specific version of the gem most suitable for the host system. So even though the `Gemfile.lock` references `nokogiri (1.14.2)`, if your host system's platform were `x86_64-linux`, they will try to install `nokogiri (1.14.2-x86-linux)` instead. This leads to issues like [1] and [2]. The new format of `gemfile.nix` is: ```nix { dependencies = ["list" "of" "top-level" "dependencies"]; platforms = { ruby = { gem-name = { dependencies = ["list" "of" 'transitive" "dependencies"] groups = [ ... ]; version = "..."; source = { # attrs describing the git, path, or RubyGems source }; }; }; other-platform = { gem-name = { ... }; }; }; } ``` The gemset's `dependencies` entry copies the `DEPENDENCIES` section of the `Gemfile.lock` and names all the top-level gem dependencies from the `Gemfile`. The gemset's `platforms` entry is an attrset where every key is a ruby-platform and its value is an attrset of the gems particular to that platform. This last attrset is essentially the same as the previous `gemset.nix` format. This commit also introduces a new nix function: `bundixEnv` (like `bundlerEnv`, but for Bundix). This function accepts the same arguments as `bundlerEnv`, with the addition of a `platform`. `bundixEnv` then converts the given gemset into a format suitable for `bundlerEnv` by selecting the gems appropriate for the given `platform`. Finally, it delegates to `bundlerEnv`, with the platform-specific gemset. `bundix --init` will generate an example `flake.nix` with an example package that demonstrates how `bundixEnv` works. See `gem help platforms` for more info about ruby platforms. The Bundler Guide [3] provides a few examples of rubygems that support multiple platforms. [1] nix-community#71 [2] https://discourse.nixos.org/t/issues-with-nix-reproducibility-on-macos-trying-to-build-nokogiri-ruby-error-unknown-warning-option/22019 [3] https://guides.rubygems.org/gems-with-extensions/
- Loading branch information
Showing
29 changed files
with
782 additions
and
273 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/cli' | ||
require 'bundler/cli/lock' | ||
|
||
module Bundix | ||
module BundlerProxy | ||
# This service ensures a git source is cloned within {#cache_dir}. | ||
class CloneGit < Base | ||
attr_reader :ignore_config, :original_source | ||
|
||
# @param original_source [Bundler::Source::Git] | ||
def initialize(original_source, ignore_config: false, **kwargs) | ||
super(pipe_result: true, **kwargs) | ||
|
||
@original_source = original_source | ||
@ignore_config = ignore_config | ||
end | ||
|
||
protected | ||
|
||
def bundler_process | ||
dup_source(original_source).tap do |source| | ||
git_proxy(source).checkout unless source.cache_path.exist? | ||
end | ||
end | ||
|
||
def env | ||
{ | ||
# TODO: 'BUNDLE_FROZEN' => nil, | ||
'BUNDLE_PATH' => cache_dir, | ||
'BUNDLE_IGNORE_CONFIG' => (ignore_config ? 'true' : nil) | ||
} | ||
end | ||
|
||
private | ||
|
||
# We must dup the source inside #{with_bundler_env}, so its paths are | ||
# inside {#cache_dir}. | ||
def dup_source(source) | ||
Bundler::Source::Git.new(source.options).tap do |new_source| | ||
new_source.cache_path # memoize path inside {#cache_dir} | ||
new_source.install_path # memoize path inside {#cache_dir} | ||
new_source.remote! # allow repo to be cloned | ||
end | ||
end | ||
|
||
def git_proxy(source) | ||
@git_proxy ||= Bundler::Source::Git::GitProxy.new( | ||
source.cache_path, | ||
source.uri, | ||
source.options, | ||
source.options['revision'], | ||
source | ||
) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.