Created
May 24, 2019 10:42
-
-
Save alyssais/2443fe14b4afdbb2d9a7729fadc34f54 to your computer and use it in GitHub Desktop.
nix-gemspec
This file contains hidden or 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
{ stdenv, lib, makeWrapper, bundler, bundix, ruby }: | |
stdenv.mkDerivation { | |
name = "nix-gemspec"; | |
src = ./.; | |
buildInputs = [ makeWrapper ruby ]; | |
installPhase = '' | |
install -D -m755 nix-gemspec.rb $out/bin/nix-gemspec | |
patchShebangs $out/bin/nix-gemspec | |
wrapProgram $out/bin/nix-gemspec \ | |
--prefix PATH : ${lib.makeBinPath [ bundler bundix ]} | |
''; | |
} |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "shellwords" | |
def sh(*args) | |
$stderr.puts args.shelljoin | |
system *args or fail "exit #{$?}" | |
end | |
sh "bundle", "lock" | |
require "fileutils" | |
p $: | |
require "bundler" | |
lockfile = Bundler::LockfileParser.new(File.read("Gemfile.lock")) | |
gems = lockfile.specs.select { |spec| | |
case spec.source | |
when Bundler::Source::Rubygems, Bundler::Source::Git then true | |
end | |
} | |
FileUtils.mkdir_p "nix/gem" | |
Dir.chdir "nix/gem" do | |
File.open("Gemfile", "w") do |gemfile| | |
gems.group_by(&:name).each do |name, gems| | |
gem = gems.sort_by { |gem| gem.platform.to_s }.first | |
version = gem.version.to_s | |
platform = Bundler::Dependency::REVERSE_PLATFORM_MAP[gem.platform]&.fetch(0) | |
options = gem.source.options.transform_keys(&:to_sym) | |
if uri = options.delete(:uri) then options[:git] = uri end | |
if revision = options.delete(:revision) then options[:ref] = revision end | |
if remote = options.delete(:remotes)&.first then options[:source] = remote end | |
options[:platform] = platform if platform | |
puts "gem #{name.inspect}, #{version.inspect}, #{options}" | |
gemfile.puts "gem #{name.inspect}, #{version.inspect}, #{options}" | |
end | |
end | |
sh "bundle", "lock", "--update" | |
sh "bundix" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment