Merge remote-tracking branch 'upstream/master' into hardened-stdenv

This commit is contained in:
Robin Gloster
2016-03-28 15:16:29 +00:00
628 changed files with 60034 additions and 8180 deletions
@@ -1,212 +0,0 @@
# This builds gems in a way that is compatible with bundler.
#
# Bundler installs gems from git sources _very_ differently from how RubyGems
# installes gem packages, though they both install gem packages similarly.
#
# We monkey-patch Bundler to remove any impurities and then drive its internals
# to install git gems.
#
# For the sake of simplicity, gem packages are installed with the standard `gem`
# program.
#
# Note that bundler does not support multiple prefixes; it assumes that all
# gems are installed in a common prefix, and has no support for specifying
# otherwise. Therefore, if you want to be able to use the resulting derivations
# with bundler, you need to create a symlink forrest first, which is what
# `bundlerEnv` does for you.
#
# Normal gem packages can be used outside of bundler; a binstub is created in
# $out/bin.
{ lib, ruby, rubygems, bundler, fetchurl, fetchgit, makeWrapper, git,
buildRubyGem, darwin
} @ defs:
lib.makeOverridable (
{ name ? null
, gemName
, version ? null
, type ? "gem"
, document ? [] # e.g. [ "ri" "rdoc" ]
, platform ? "ruby"
, ruby ? defs.ruby
, stdenv ? ruby.stdenv
, namePrefix ? (let
rubyName = builtins.parseDrvName ruby.name;
in "${rubyName.name}${rubyName.version}-")
, buildInputs ? []
, doCheck ? false
, meta ? {}
, patches ? []
, gemPath ? []
, dontStrip ? true
, remotes ? ["https://rubygems.org"]
# Assume we don't have to build unless strictly necessary (e.g. the source is a
# git checkout).
# If you need to apply patches, make sure to set `dontBuild = false`;
, dontBuild ? true
, propagatedBuildInputs ? []
, propagatedUserEnvPkgs ? []
, buildFlags ? null
, passthru ? {}
, ...} @ attrs:
let
shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'";
rubygems = (attrs.rubygems or defs.rubygems).override {
inherit ruby;
};
src = attrs.src or (
if type == "gem" then
fetchurl {
urls = map (remote: "${remote}/gems/${gemName}-${version}.gem") remotes;
inherit (attrs) sha256;
}
else if type == "git" then
fetchgit {
inherit (attrs) url rev sha256 fetchSubmodules;
leaveDotGit = true;
}
else
throw "buildRubyGem: don't know how to build a gem of type \"${type}\""
);
documentFlag =
if document == []
then "-N"
else "--document ${lib.concatStringsSep "," document}";
in
stdenv.mkDerivation (attrs // {
inherit ruby rubygems;
inherit doCheck;
inherit dontBuild;
inherit dontStrip;
inherit type;
buildInputs = [
ruby rubygems makeWrapper
] ++ lib.optionals (type == "git") [ git bundler ]
++ lib.optional stdenv.isDarwin darwin.libobjc
++ buildInputs;
name = attrs.name or "${namePrefix}${gemName}-${version}";
inherit src;
phases = attrs.phases or [ "unpackPhase" "patchPhase" "buildPhase" "installPhase" "fixupPhase" ];
unpackPhase = attrs.unpackPhase or ''
runHook preUnpack
if [[ -f $src && $src == *.gem ]]; then
if [[ -z "$dontBuild" ]]; then
# we won't know the name of the directory that RubyGems creates,
# so we'll just use a glob to find it and move it over.
gempkg="$src"
sourceRoot=source
gem unpack $gempkg --target=container
cp -r container/* $sourceRoot
rm -r container
# copy out the original gemspec, for convenience during patching /
# overrides.
gem specification $gempkg --ruby > original.gemspec
gemspec=$(readlink -f .)/original.gemspec
else
gempkg="$src"
fi
else
# Fall back to the original thing for everything else.
dontBuild=""
preUnpack="" postUnpack="" unpackPhase
fi
runHook postUnpack
'';
buildPhase = attrs.buildPhase or ''
runHook preBuild
if [[ "$type" == "gem" ]]; then
if [[ -z "$gemspec" ]]; then
gemspec="$(find . -name '*.gemspec')"
echo "found the following gemspecs:"
echo "$gemspec"
gemspec="$(echo "$gemspec" | head -n1)"
fi
exec 3>&1
output="$(gem build $gemspec | tee >(cat - >&3))"
exec 3>&-
gempkg=$(echo "$output" | grep -oP 'File: \K(.*)')
echo "gem package built: $gempkg"
fi
runHook postBuild
'';
# Note:
# We really do need to keep the $out/${ruby.gemPath}/cache.
# This is very important in order for many parts of RubyGems/Bundler to not blow up.
# See https://github.com/bundler/bundler/issues/3327
installPhase = attrs.installPhase or ''
runHook preInstall
export GEM_HOME=$out/${ruby.gemPath}
mkdir -p $GEM_HOME
echo "buildFlags: $buildFlags"
${lib.optionalString (type == "git") ''
ruby ${./nix-bundle-install.rb} \
${gemName} \
${attrs.url} \
${src} \
${attrs.rev} \
${version} \
${shellEscape (toString buildFlags)}
''}
${lib.optionalString (type == "gem") ''
if [[ -z "$gempkg" ]]; then
echo "failure: \$gempkg path unspecified" 1>&2
exit 1
elif [[ ! -f "$gempkg" ]]; then
echo "failure: \$gempkg path invalid" 1>&2
exit 1
fi
gem install \
--local \
--force \
--http-proxy 'http://nodtd.invalid' \
--ignore-dependencies \
--build-root '/' \
--backtrace \
${documentFlag} \
$gempkg $gemFlags -- $buildFlags
# looks like useless files which break build repeatability and consume space
rm -fv $out/${ruby.gemPath}/doc/*/*/created.rid || true
rm -fv $out/${ruby.gemPath}/gems/*/ext/*/mkmf.log || true
# write out metadata and binstubs
spec=$(echo $out/${ruby.gemPath}/specifications/*.gemspec)
ruby ${./gem-post-build.rb} "$spec"
''}
runHook postInstall
'';
propagatedBuildInputs = gemPath ++ propagatedBuildInputs;
propagatedUserEnvPkgs = gemPath ++ propagatedUserEnvPkgs;
passthru = passthru // { isRubyGem = true; };
inherit meta;
})
)
@@ -1,77 +0,0 @@
require 'rbconfig'
require 'rubygems'
require 'rubygems/specification'
require 'fileutils'
ruby = File.join(ENV["ruby"], "bin", RbConfig::CONFIG['ruby_install_name'])
out = ENV["out"]
bin_path = File.join(ENV["out"], "bin")
gem_home = ENV["GEM_HOME"]
gem_path = ENV["GEM_PATH"].split(":")
install_path = Dir.glob("#{gem_home}/gems/*").first
gemspec_path = ARGV[0]
if defined?(Encoding.default_internal)
Encoding.default_internal = Encoding::UTF_8
Encoding.default_external = Encoding::UTF_8
end
gemspec_content = File.read(gemspec_path)
spec = nil
if gemspec_content[0..2] == "---" # YAML header
spec = Gem::Specification.from_yaml(gemspec_content)
else
spec = Gem::Specification.load(gemspec_path)
end
FileUtils.mkdir_p("#{out}/nix-support")
# write meta-data
meta = "#{out}/nix-support/gem-meta"
FileUtils.mkdir_p(meta)
FileUtils.ln_s(gemspec_path, "#{meta}/spec")
File.open("#{meta}/name", "w") do |f|
f.write(spec.name)
end
File.open("#{meta}/install-path", "w") do |f|
f.write(install_path)
end
File.open("#{meta}/require-paths", "w") do |f|
f.write(spec.require_paths.join(" "))
end
File.open("#{meta}/executables", "w") do |f|
f.write(spec.executables.join(" "))
end
# add this gem to the GEM_PATH for dependencies
File.open("#{out}/nix-support/setup-hook", "a") do |f|
f.puts("addToSearchPath GEM_PATH #{gem_home}")
spec.require_paths.each do |dir|
f.puts("addToSearchPath RUBYLIB #{install_path}/#{dir}")
end
end
# create regular rubygems binstubs
FileUtils.mkdir_p(bin_path)
spec.executables.each do |exe|
File.open("#{bin_path}/#{exe}", "w") do |f|
f.write(<<-EOF)
#!#{ruby}
#
# This file was generated by Nix.
#
# The application '#{exe}' is installed as part of a gem, and
# this file is here to facilitate running it.
#
gem_path = ENV["GEM_PATH"]
ENV["GEM_PATH"] = "\#{gem_path}\#{":" unless gem_path.nil? || gem_path.empty?}#{(gem_path+[gem_home]).join(":")}"
require 'rubygems'
load Gem.bin_path(#{spec.name.inspect}, #{exe.inspect})
EOF
end
FileUtils.chmod("+x", "#{bin_path}/#{exe}")
end
@@ -1,152 +0,0 @@
require 'rbconfig'
require 'bundler/vendored_thor'
require 'bundler'
require 'rubygems/command'
require 'fileutils'
require 'pathname'
require 'tmpdir'
# Options:
#
# name - the gem name
# uri - git repo uri
# repo - path to local checkout
# ref - the commit hash
# version - gem version
# build-flags - build arguments
ruby = File.join(ENV["ruby"], "bin", RbConfig::CONFIG['ruby_install_name'])
out = ENV["out"]
bin_dir = File.join(ENV["out"], "bin")
name = ARGV[0]
uri = ARGV[1]
REPO = ARGV[2]
ref = ARGV[3]
version = ARGV[4]
build_flags = ARGV[5]
# options to pass to bundler
options = {
"name" => name,
"uri" => uri,
"ref" => ref,
"version" => version,
}
# Monkey-patch Bundler to use our local checkout.
# I wish we didn't have to do this, but bundler does not expose an API to do
# these kinds of things.
Bundler.module_eval do
def self.requires_sudo?
false
end
def self.root
# we don't have a Gemfile, so it doesn't make sense to try to make paths
# relative to the (non existent) parent directory thereof, so we give a
# nonsense path here.
Pathname.new("/no-root-path")
end
def self.bundle_path
Pathname.new(ENV["GEM_HOME"])
end
def self.locked_gems
nil
end
end
Bundler::Source::Git.class_eval do
def allow_git_ops?
true
end
end
Bundler::Source::Git::GitProxy.class_eval do
def checkout
unless path.exist?
FileUtils.mkdir_p(path.dirname)
FileUtils.cp_r(File.join(REPO, ".git"), path)
system("chmod -R +w #{path}")
end
end
def copy_to(destination, submodules=false)
unless File.exist?(destination.join(".git"))
FileUtils.mkdir_p(destination.dirname)
FileUtils.cp_r(REPO, destination)
system("chmod -R +w #{destination}")
end
end
end
# UI
verbose = false
no_color = false
Bundler.ui = Bundler::UI::Shell.new({"no-color" => no_color})
Bundler.ui.level = "debug" if verbose
# Install
source = Bundler::Source::Git.new(options)
spec = source.specs.search_all(name).first
Bundler.rubygems.with_build_args [build_flags] do
source.install(spec)
end
msg = spec.post_install_message
if msg
Bundler.ui.confirm "Post-install message from #{name}:"
Bundler.ui.info msg
end
# Write out the binstubs
if spec.executables.any?
FileUtils.mkdir_p(bin_dir)
spec.executables.each do |exe|
wrapper = File.join(bin_dir, exe)
File.open(wrapper, "w") do |f|
f.write(<<-EOF)
#!#{ruby}
#
# This file was generated by Nix.
#
# The application '#{exe}' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path(#{spec.name.inspect}, #{exe.inspect})
EOF
end
FileUtils.chmod("+x", wrapper)
end
end
# Write out metadata
meta = "#{out}/nix-support/gem-meta"
FileUtils.mkdir_p(meta)
FileUtils.ln_s(spec.loaded_from.to_s, "#{meta}/spec")
File.open("#{meta}/name", "w") do |f|
f.write spec.name
end
File.open("#{meta}/install-path", "w") do |f|
f.write source.install_path.to_s
end
File.open("#{meta}/require-paths", "w") do |f|
f.write spec.require_paths.join(" ")
end
File.open("#{meta}/executables", "w") do |f|
f.write spec.executables.join(" ")
end
# make the lib available during bundler/git installs
File.open("#{out}/nix-support/setup-hook", "a") do |f|
spec.require_paths.each do |dir|
f.puts("addToSearchPath RUBYLIB #{source.install_path}/#{dir}")
end
end
@@ -1,44 +0,0 @@
{ buildRubyGem, lib, bundler, ruby, nix, nix-prefetch-git }:
buildRubyGem rec {
inherit ruby;
name = "${gemName}-${version}";
gemName = "bundix";
version = "2.0.6";
sha256 = "0yd960awd427mg29r2yzhccd0vjimn1ljr8d8hncj6m6wg84nvh5";
buildInputs = [bundler];
postInstall = ''
substituteInPlace $GEM_HOME/gems/${gemName}-${version}/lib/bundix.rb \
--replace \
"'nix-instantiate'" \
"'${nix}/bin/nix-instantiate'" \
--replace \
"'nix-hash'" \
"'${nix}/bin/nix-hash'" \
--replace \
"'nix-prefetch-url'" \
"'${nix}/bin/nix-prefetch-url'" \
--replace \
"'nix-prefetch-git'" \
"'${nix-prefetch-git}/bin/nix-prefetch-git'"
'';
meta = {
inherit version;
description = "Creates Nix packages from Gemfiles";
longDescription = ''
This is a tool that converts Gemfile.lock files to nix expressions.
The output is then usable by the bundlerEnv derivation to list all the
dependencies of a ruby package.
'';
homepage = "https://github.com/manveru/bundix";
license = "MIT";
maintainers = with lib.maintainers; [ manveru zimbatm ];
platforms = lib.platforms.all;
};
}
@@ -1,113 +0,0 @@
{ stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib
, callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv
, rubygems
, git
, makeWrapper
, bundler
, tree
}@defs:
{ name, gemset, gemfile, lockfile, ruby ? defs.ruby, gemConfig ? defaultGemConfig
, postBuild ? null
, document ? []
, meta ? {}
, ignoreCollisions ? false
, ...
}@args:
let
shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'";
importedGemset = import gemset;
applyGemConfigs = attrs:
(if gemConfig ? "${attrs.gemName}"
then attrs // gemConfig."${attrs.gemName}" attrs
else attrs);
configuredGemset = lib.flip lib.mapAttrs importedGemset (name: attrs:
applyGemConfigs (attrs // { gemName = name; })
);
hasBundler = builtins.hasAttr "bundler" importedGemset;
bundler = if hasBundler then gems.bundler else defs.bundler.override (attrs: { inherit ruby; });
rubygems = defs.rubygems.override (attrs: { inherit ruby; });
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs:
buildRubyGem ((removeAttrs attrs ["source"]) // attrs.source // {
inherit ruby rubygems;
gemName = name;
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
}));
# We have to normalize the Gemfile.lock, otherwise bundler tries to be
# helpful by doing so at run time, causing executables to immediately bail
# out. Yes, I'm serious.
confFiles = runCommand "gemfile-and-lockfile" {} ''
mkdir -p $out
cp ${gemfile} $out/Gemfile
cp ${lockfile} $out/Gemfile.lock
cd $out
chmod +w Gemfile.lock
source ${rubygems}/nix-support/setup-hook
export GEM_PATH=${bundler}/${ruby.gemPath}
${ruby}/bin/ruby -rubygems -e \
"require 'bundler'; Bundler.definition.lock('Gemfile.lock')"
'';
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
bundlerEnv = buildEnv {
inherit name ignoreCollisions;
paths = envPaths;
pathsToLink = [ "/lib" ];
postBuild = ''
source ${rubygems}/nix-support/setup-hook
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
"${ruby}/bin/ruby" \
"${confFiles}/Gemfile" \
"$out/${ruby.gemPath}" \
"${bundler}/${ruby.gemPath}" \
${shellEscape (toString envPaths)}
'' + lib.optionalString (postBuild != null) postBuild;
passthru = rec {
inherit ruby bundler meta gems;
wrappedRuby = stdenv.mkDerivation {
name = "wrapped-ruby-${name}";
nativeBuildInputs = [ makeWrapper ];
buildCommand = ''
mkdir -p $out/bin
for i in ${ruby}/bin/*; do
makeWrapper "$i" $out/bin/$(basename "$i") \
--set BUNDLE_GEMFILE ${confFiles}/Gemfile \
--set BUNDLE_PATH ${bundlerEnv}/${ruby.gemPath} \
--set GEM_HOME ${bundlerEnv}/${ruby.gemPath} \
--set GEM_PATH ${bundlerEnv}/${ruby.gemPath}
done
'';
};
env = let
irbrc = builtins.toFile "irbrc" ''
if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?)
require ENV["OLD_IRBRC"]
end
require 'rubygems'
require 'bundler/setup'
'';
in stdenv.mkDerivation {
name = "interactive-${name}-environment";
nativeBuildInputs = [ wrappedRuby bundlerEnv ];
shellHook = ''
export OLD_IRBRC="$IRBRC"
export IRBRC=${irbrc}
'';
buildCommand = ''
echo >&2 ""
echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
echo >&2 ""
exit 1
'';
};
};
};
in
bundlerEnv
@@ -1,46 +0,0 @@
require 'rbconfig'
require 'rubygems'
require 'rubygems/specification'
require 'fileutils'
# args/settings
out = ENV["out"]
ruby = ARGV[0]
gemfile = ARGV[1]
bundle_path = ARGV[2]
bundler_gem_path = ARGV[3]
paths = ARGV[4].split
# generate binstubs
FileUtils.mkdir_p("#{out}/bin")
paths.each do |path|
next unless File.directory?("#{path}/nix-support/gem-meta")
name = File.read("#{path}/nix-support/gem-meta/name")
executables = File.read("#{path}/nix-support/gem-meta/executables").split
executables.each do |exe|
File.open("#{out}/bin/#{exe}", "w") do |f|
f.write(<<-EOF)
#!#{ruby}
#
# This file was generated by Nix.
#
# The application '#{exe}' is installed as part of a gem, and
# this file is here to facilitate running it.
#
ENV["BUNDLE_GEMFILE"] = "#{gemfile}"
ENV["BUNDLE_PATH"] = "#{bundle_path}"
gem_path = ENV["GEM_PATH"]
ENV["GEM_PATH"] = "\#{gem_path}\#{":" unless gem_path.nil? || gem_path.empty?}#{bundler_gem_path}"
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path(#{name.inspect}, #{exe.inspect})
EOF
FileUtils.chmod("+x", "#{out}/bin/#{exe}")
end
end
end
@@ -1,10 +0,0 @@
{ buildRubyGem, makeWrapper, ruby, coreutils }:
buildRubyGem rec {
inherit ruby;
name = "${gemName}-${version}";
gemName = "bundler";
version = "1.10.6";
sha256 = "1vlzfq0bkkj4jyq6av0y55mh5nj5n0f3mfbmmifwgkh44g8k6agv";
dontPatchShebangs = true;
}
+39 -12
View File
@@ -1,6 +1,7 @@
{ stdenv, lib, fetchurl, fetchFromSavannah, fetchFromGitHub
, zlib, openssl, gdbm, ncurses, readline, groff, libyaml, libffi, autoreconfHook, bison
, autoconf, darwin ? null
, buildEnv, bundler, bundix
} @ args:
let
@@ -9,6 +10,10 @@ let
opString = stdenv.lib.optionalString;
patchSet = import ./rvm-patchsets.nix { inherit fetchFromGitHub; };
config = import ./config.nix { inherit fetchFromSavannah; };
rubygemsSrc = import ./rubygems-src.nix { inherit fetchurl; };
unpackdir = obj:
lib.removeSuffix ".tgz"
(lib.removeSuffix ".tar.gz" obj.name);
generic = { majorVersion, minorVersion, teenyVersion, patchLevel, sha256 }: let
versionNoPatch = "${majorVersion}.${minorVersion}.${teenyVersion}";
@@ -31,13 +36,10 @@ let
, libffi, fiddleSupport ? true
, autoreconfHook, bison, autoconf
, darwin ? null
, buildEnv, bundler, bundix
}:
stdenv.mkDerivation rec {
inherit version;
name = "ruby-${version}";
src = if useRailsExpress then fetchFromGitHub {
let rubySrc =
if useRailsExpress then fetchFromGitHub {
owner = "ruby";
repo = "ruby";
rev = tag;
@@ -46,6 +48,18 @@ let
url = "http://cache.ruby-lang.org/pub/ruby/${majorVersion}.${minorVersion}/ruby-${fullVersionName}.tar.gz";
sha256 = sha256.src;
};
in
stdenv.mkDerivation rec {
inherit version;
name = "ruby-${version}";
srcs = [ rubySrc rubygemsSrc ];
sourceRoot =
if useRailsExpress then
"ruby-${tag}-src"
else
unpackdir rubySrc;
# Have `configure' avoid `/usr/bin/nroff' in non-chroot builds.
NROFF = "${groff}/bin/nroff";
@@ -67,11 +81,15 @@ let
enableParallelBuilding = true;
patches = (import ./patchsets.nix {
inherit patchSet useRailsExpress ops patchLevel;
})."${versionNoPatch}";
patches =
[ ./gem_hook.patch ] ++
(import ./patchsets.nix {
inherit patchSet useRailsExpress ops patchLevel;
})."${versionNoPatch}";
postUnpack = opString isRuby21 ''
postUnpack = ''
cp -r ${unpackdir rubygemsSrc} ${sourceRoot}/rubygems
'' + opString isRuby21 ''
rm "$sourceRoot/enc/unicode/name2ctype.h"
'';
@@ -99,6 +117,11 @@ let
installFlags = stdenv.lib.optionalString docSupport "install-doc";
# Bundler tries to create this directory
postInstall = ''
# Update rubygems
pushd rubygems
$out/bin/ruby setup.rb
popd
# Bundler tries to create this directory
mkdir -pv $out/${passthru.gemPath}
mkdir -p $out/nix-support
@@ -119,17 +142,21 @@ let
meta = {
license = stdenv.lib.licenses.ruby;
homepage = "http://www.ruby-lang.org/en/";
homepage = http://www.ruby-lang.org/en/;
description = "The Ruby language";
platforms = stdenv.lib.platforms.all;
};
passthru = rec {
inherit majorVersion minorVersion teenyVersion patchLevel;
inherit majorVersion minorVersion teenyVersion patchLevel version;
rubyEngine = "ruby";
baseRuby = baseruby;
libPath = "lib/${rubyEngine}/${versionNoPatch}";
gemPath = "lib/${rubyEngine}/gems/${versionNoPatch}";
dev = import ./dev.nix {
inherit buildEnv bundler bundix;
ruby = self;
};
};
}
) args; in self;
@@ -0,0 +1,24 @@
/* An environment for development that bundles ruby, bundler and bundix
together. This avoids version conflicts where each is using a diferent
version of each-other.
*/
{ buildEnv, ruby, bundler, bundix }:
let
bundler_ = bundler.override {
ruby = ruby;
};
bundix_ = bundix.override {
ruby = ruby;
bundler = bundler_;
};
in
buildEnv {
name = "${ruby.rubyEngine}-dev-${ruby.version}";
paths = [
bundix_
bundler_
ruby
];
pathsToLink = [ "/bin" ];
ignoreCollisions = true;
}
@@ -1,18 +1,21 @@
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index d1ef3cb..bf15652 100755
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -545,6 +545,13 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
diff --git a/rubygems/lib/rubygems/installer.rb b/rubygems/lib/rubygems/installer.rb
index a88d393..8612901 100644
--- a/rubygems/lib/rubygems/installer.rb
+++ b/rubygems/lib/rubygems/installer.rb
@@ -766,7 +766,15 @@ TEXT
# Ensures that files can't be installed outside the gem directory.
say path if Gem.configuration.really_verbose
end
+
+ if !ENV['NIX_POST_EXTRACT_FILES_HOOK'].nil?
+ print "\nrunning NIX_POST_EXTRACT_FILES_HOOK #{ENV['NIX_POST_EXTRACT_FILES_HOOK']} #{@gem_dir}\n"
+ print `#{ENV['NIX_POST_EXTRACT_FILES_HOOK']} #{@gem_dir}`
+ print "\nrunning NIX_POST_EXTRACT_FILES_HOOK done\n"
def extract_files
- @package.extract_files gem_dir
+ ret = @package.extract_files gem_dir
+ if ENV['NIX_POST_EXTRACT_FILES_HOOK']
+ puts
+ puts "running NIX_POST_EXTRACT_FILES_HOOK #{ENV['NIX_POST_EXTRACT_FILES_HOOK']} #{gem_dir}"
+ system("#{ENV['NIX_POST_EXTRACT_FILES_HOOK']} #{gem_dir}")
+ puts "running NIX_POST_EXTRACT_FILES_HOOK done"
+ puts
+ end
+
+ ret
end
##
@@ -1,166 +0,0 @@
# The standard set of gems in nixpkgs including potential fixes.
#
# The gemset is derived from two points of entry:
# - An attrset describing a gem, including version, source and dependencies
# This is just meta data, most probably automatically generated by a tool
# like Bundix (https://github.com/aflatter/bundix).
# {
# name = "bundler";
# version = "1.6.5";
# sha256 = "1s4x0f5by9xs2y24jk6krq5ky7ffkzmxgr4z1nhdykdmpsi2zd0l";
# dependencies = [ "rake" ];
# }
# - An optional derivation that may override how the gem is built. For popular
# gems that don't behave correctly, fixes are already provided in the form of
# derivations.
#
# This seperates "what to build" (the exact gem versions) from "how to build"
# (to make gems behave if necessary).
{ lib, fetchurl, writeScript, ruby, kerberos, libxml2, libxslt, python, stdenv, which
, libiconv, postgresql, v8_3_16_14, clang, sqlite, zlib, imagemagick
, pkgconfig , ncurses, xapian, gpgme, utillinux, fetchpatch, tzdata, icu, libffi
, cmake, libssh2, openssl, mysql, darwin, git, perl, gecode_3, curl
, libmsgpack
}:
let
v8 = v8_3_16_14;
in
{
charlock_holmes = attrs: {
buildInputs = [ which icu zlib ];
};
dep-selector-libgecode = attrs: {
USE_SYSTEM_GECODE = true;
postInstall = ''
installPath=$(cat $out/nix-support/gem-meta/install-path)
sed -i $installPath/lib/dep-selector-libgecode.rb -e 's@VENDORED_GECODE_DIR =.*@VENDORED_GECODE_DIR = "${gecode_3}"@'
'';
};
eventmachine = attrs: {
buildInputs = [ openssl ];
};
ffi = attrs: {
buildInputs = [ libffi pkgconfig ];
};
gpgme = attrs: {
buildInputs = [ gpgme ];
};
# note that you need version >= v3.16.14.8,
# otherwise the gem will fail to link to the libv8 binary.
# see: https://github.com/cowboyd/libv8/pull/161
libv8 = attrs: {
buildInputs = [ which v8 python ];
buildFlags = [ "--with-system-v8=true" ];
};
msgpack = attrs: {
buildInputs = [ libmsgpack ];
};
mysql2 = attrs: {
buildInputs = [ mysql.lib zlib openssl ];
};
ncursesw = attrs: {
buildInputs = [ ncurses ];
buildFlags = [
"--with-cflags=-I${ncurses}/include"
"--with-ldflags=-L${ncurses}/lib"
];
};
nokogiri = attrs: {
buildFlags = [
"--use-system-libraries"
"--with-zlib-dir=${zlib}"
"--with-xml2-lib=${libxml2}/lib"
"--with-xml2-include=${libxml2}/include/libxml2"
"--with-xslt-lib=${libxslt}/lib"
"--with-xslt-include=${libxslt}/include"
"--with-exslt-lib=${libxslt}/lib"
"--with-exslt-include=${libxslt}/include"
] ++ lib.optional stdenv.isDarwin "--with-iconv-dir=${libiconv}";
};
patron = attrs: {
buildInputs = [ curl ];
};
pg = attrs: {
buildFlags = [
"--with-pg-config=${postgresql}/bin/pg_config"
];
};
puma = attrs: {
buildInputs = [ openssl ];
};
rmagick = attrs: {
buildInputs = [ imagemagick pkgconfig ];
};
rugged = attrs: {
buildInputs = [ cmake pkgconfig openssl libssh2 zlib ];
};
sqlite3 = attrs: {
buildFlags = [
"--with-sqlite3-include=${sqlite}/include"
"--with-sqlite3-lib=${sqlite}/lib"
];
};
sup = attrs: {
dontBuild = false;
# prevent sup from trying to dynamically install `xapian-ruby`.
postPatch = ''
cp ${./mkrf_conf_xapian.rb} ext/mkrf_conf_xapian.rb
substituteInPlace lib/sup/crypto.rb \
--replace 'which gpg2' \
'${which}/bin/which gpg2'
'';
};
timfel-krb5-auth = attrs: {
buildInputs = [ kerberos ];
};
therubyracer = attrs: {
buildFlags = [
"--with-v8-dir=${v8}"
"--with-v8-include=${v8}/include"
"--with-v8-lib=${v8}/lib"
];
};
tzinfo = attrs: {
dontBuild = false;
postPatch = ''
substituteInPlace lib/tzinfo/zoneinfo_data_source.rb \
--replace "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo"
'';
};
xapian-ruby = attrs: {
# use the system xapian
dontBuild = false;
buildInputs = [ xapian pkgconfig zlib ];
postPatch = ''
cp ${./xapian-Rakefile} Rakefile
'';
preInstall = ''
export XAPIAN_CONFIG=${xapian}/bin/xapian-config
'';
};
}
@@ -1,14 +0,0 @@
require 'rubygems'
require 'rubygems/command.rb'
require 'rubygems/dependency_installer.rb'
require 'rbconfig'
begin
Gem::Command.build_args = ARGV
rescue NoMethodError
end
# create dummy rakefile to indicate success
f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w")
f.write("task :default\n")
f.close
@@ -1,38 +0,0 @@
# encoding: utf-8
# Install the xapian binaries into the lib folder of the gem
require 'rbconfig'
c = RbConfig::CONFIG
def system!(cmd)
puts cmd
system(cmd) or raise
end
source_dir = 'xapian_source'
bindings = Dir["#{source_dir}/xapian-bindings-*"].first
bindings = File.basename(bindings, ".tar.xz")
task :default do
system! "tar -xJf #{source_dir}/#{bindings}.tar.xz"
prefix = Dir.pwd
ENV['LDFLAGS'] = "-L#{prefix}/lib"
system! "mkdir -p lib"
Dir.chdir bindings do
ENV['RUBY'] ||= "#{c['bindir']}/#{c['RUBY_INSTALL_NAME']}"
system! "./configure --prefix=#{prefix} --exec-prefix=#{prefix} --with-ruby"
system! "make clean all"
end
system! "cp -r #{bindings}/ruby/.libs/_xapian.* lib"
system! "cp #{bindings}/ruby/xapian.rb lib"
system! "rm lib/*.la"
system! "rm lib/*.lai"
system! "rm -R #{bindings}"
system! "rm -R #{source_dir}"
end
@@ -1,138 +0,0 @@
{ fetchurl, writeScript, ruby, ncurses, sqlite, libxml2, libxslt, libffi
, zlib, libuuid, gems, jdk, python, stdenv, libiconv, imagemagick
, pkgconfig }:
let
patchUsrBinEnv = writeScript "path-usr-bin-env" ''
#!/bin/sh
echo "==================="
find "$1" -type f -name "*.rb" | xargs sed -i "s@/usr/bin/env@$(type -p env)@g"
find "$1" -type f -name "*.mk" | xargs sed -i "s@/usr/bin/env@$(type -p env)@g"
'';
in
{
buildr = {
# Many Buildfiles rely on RUBYLIB containing the current directory
# (as was the default in Ruby < 1.9.2).
extraWrapperFlags = "--prefix RUBYLIB : .";
};
fakes3 = {
postInstall = ''
cd $out/${ruby.gemPath}/gems/*
patch -Np1 -i ${../../ruby-modules/fake-s3-list-bucket.patch}
'';
};
ffi = {
postUnpack = "onetuh";
buildFlags = ["--with-ffi-dir=${libffi}"];
NIX_POST_EXTRACT_FILES_HOOK = patchUsrBinEnv;
};
iconv = { buildInputs = [ libiconv ]; };
libv8 = {
# This fix is needed to fool scons, which clears the environment by default.
# It's ugly, but it works.
#
# We create a gcc wrapper wrapper, which reexposes the environment variables
# that scons hides. Furthermore, they treat warnings as errors causing the
# build to fail, due to an unused variable.
#
# Finally, we must set CC and AR explicitly to allow scons to find the
# compiler and archiver
preBuild = ''
cat > $TMPDIR/g++ <<EOF
#! ${stdenv.shell}
$(export)
g++ \$(echo \$@ | sed 's/-Werror//g')
EOF
chmod +x $TMPDIR/g++
export CXX=$TMPDIR/g++
export AR=$(type -p ar)
'';
buildInputs = [ python ];
NIX_POST_EXTRACT_FILES_HOOK = writeScript "patch-scons" ''
#!/bin/sh
for i in `find "$1" -name scons`
do
sed -i -e "s@/usr/bin/env@$(type -p env)@g" $i
done
'';
};
ncurses = { propagatedBuildInputs = [ ncurses ]; };
ncursesw = { propagatedBuildInputs = [ ncurses ]; };
nix = {
postInstall = ''
cd $out/${ruby.gemPath}/gems/nix*
patch -Np1 -i ${./fix-gem-nix-versions.patch}
'';
};
nokogiri = {
buildInputs = [ libxml2 ];
buildFlags =
[ "--with-xml2-dir=${libxml2} --with-xml2-include=${libxml2}/include/libxml2"
"--with-xslt-dir=${libxslt} --use-system-libraries"
libiconv
];
};
pry = { gemFlags = "--no-ri --no-rdoc"; };
rails = { gemFlags = "--no-ri --no-rdoc"; };
rjb = {
buildInputs = [ jdk ];
JAVA_HOME = jdk;
};
rmagick = {
buildInputs = [ imagemagick pkgconfig ];
NIX_CFLAGS_COMPILE = "-I${imagemagick}/include/ImageMagick-6";
};
sqlite3 = { propagatedBuildInputs = [ sqlite ]; };
xapian_full = {
buildInputs = [ gems.rake zlib libuuid ];
gemFlags = "--no-rdoc --no-ri";
};
xapian_full_alaveteli = {
buildInputs = [ zlib libuuid ];
};
xapian_ruby = {
buildInputs = [ zlib libuuid ];
};
xrefresh_server =
let
patch = fetchurl {
url = "http://mawercer.de/~nix/xrefresh.diff.gz";
sha256 = "1f7bnmn1pgkmkml0ms15m5lx880hq2sxy7vsddb3sbzm7n1yyicq";
};
in {
propagatedBuildInputs = [ gems.rb_inotify ];
# monitor implementation for Linux
postInstall = ''
cd $out/${ruby.gemPath}/gems/*
zcat ${patch} | patch -p 1
''; # */
};
bundler = { dontPatchShebangs=1; };
}
@@ -0,0 +1,8 @@
{ fetchurl
, version ? "2.6.2"
, sha256 ? "1j02ajici555f35vd6ky6m4bxs8lh8nqb1c59qqib4jp4ibcv6zy"
}:
fetchurl {
url = "http://production.cf.rubygems.org/rubygems/rubygems-${version}.tgz";
sha256 = sha256;
}
@@ -1,35 +0,0 @@
{ stdenv, lib, fetchurl, makeWrapper, ruby }:
stdenv.mkDerivation rec {
name = "rubygems-${version}";
version = "2.4.8";
src = fetchurl {
url = "http://production.cf.rubygems.org/rubygems/${name}.tgz";
sha256 = "0pl4civyf0vhqsqbqaivvxrb3fsg8sid9a8jv5vfnk4hypz3ahss";
};
patches = [ ./gem_hook.patch ];
buildInputs = [ruby makeWrapper];
buildPhase = ":";
installPhase = ''
ruby setup.rb --prefix=$out/
wrapProgram $out/bin/gem --prefix RUBYLIB : $out/lib
find $out -type f -name "*.rb" |
xargs sed -i "s@/usr/bin/env@$(type -p env)@g"
mkdir -pv $out/nix-support
cat > $out/nix-support/setup-hook <<EOF
export RUBYOPT=rubygems
addToSearchPath RUBYLIB $out/lib
EOF
'';
meta = {
description = "A package management framework for Ruby";
};
}