uboot: (firmwareOdroidC2/C4) don't invoke patch tool, use patches = [] instead
https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L948 this can do it nicely. Signed-off-by: Anton Arapov <anton@deadbeef.mx>
This commit is contained in:
commit
56de2bcd43
30691 changed files with 3076956 additions and 0 deletions
251
pkgs/development/ruby-modules/gem/default.nix
Normal file
251
pkgs/development/ruby-modules/gem/default.nix
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
# 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, fetchurl, fetchgit, makeWrapper, gitMinimal, darwin
|
||||
, ruby, bundler
|
||||
} @ 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 ? []
|
||||
, meta ? {}
|
||||
, patches ? []
|
||||
, gemPath ? []
|
||||
, dontStrip ? false
|
||||
# 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
|
||||
, dontInstallManpages ? false
|
||||
, propagatedBuildInputs ? []
|
||||
, propagatedUserEnvPkgs ? []
|
||||
, buildFlags ? []
|
||||
, passthru ? {}
|
||||
# bundler expects gems to be stored in the cache directory for certain actions
|
||||
# such as `bundler install --redownload`.
|
||||
# At the cost of increasing the store size, you can keep the gems to have closer
|
||||
# alignment with what Bundler expects.
|
||||
, keepGemCache ? false
|
||||
, ...} @ attrs:
|
||||
|
||||
let
|
||||
src = attrs.src or (
|
||||
if type == "gem" then
|
||||
fetchurl {
|
||||
urls = map (
|
||||
remote: "${remote}/gems/${gemName}-${version}.gem"
|
||||
) (attrs.source.remotes or [ "https://rubygems.org" ]);
|
||||
inherit (attrs.source) sha256;
|
||||
}
|
||||
else if type == "git" then
|
||||
fetchgit {
|
||||
inherit (attrs.source) url rev sha256 fetchSubmodules;
|
||||
}
|
||||
else if type == "url" then
|
||||
fetchurl attrs.source
|
||||
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 ((builtins.removeAttrs attrs ["source"]) // {
|
||||
inherit ruby;
|
||||
inherit dontBuild;
|
||||
inherit dontStrip;
|
||||
inherit type;
|
||||
|
||||
buildInputs = [
|
||||
ruby makeWrapper
|
||||
] ++ lib.optionals (type == "git") [ gitMinimal ]
|
||||
++ lib.optionals (type != "gem") [ bundler ]
|
||||
++ lib.optional stdenv.isDarwin darwin.libobjc
|
||||
++ buildInputs;
|
||||
|
||||
#name = builtins.trace (attrs.name or "no attr.name" ) "${namePrefix}${gemName}-${version}";
|
||||
name = attrs.name or "${namePrefix}${gemName}-${version}";
|
||||
|
||||
inherit src;
|
||||
|
||||
|
||||
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
|
||||
'';
|
||||
|
||||
# As of ruby 3.0, ruby headers require -fdeclspec when building with clang
|
||||
# Introduced in https://github.com/ruby/ruby/commit/0958e19ffb047781fe1506760c7cbd8d7fe74e57
|
||||
NIX_CFLAGS_COMPILE = lib.optionals (stdenv.cc.isClang && lib.versionAtLeast ruby.version.major "3") [
|
||||
"-fdeclspec"
|
||||
];
|
||||
|
||||
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"
|
||||
elif [[ "$type" == "git" ]]; then
|
||||
git init
|
||||
# remove variations to improve the likelihood of a bit-reproducible output
|
||||
rm -rf .git/logs/ .git/hooks/ .git/index .git/FETCH_HEAD .git/ORIG_HEAD .git/refs/remotes/origin/HEAD .git/config
|
||||
# support `git ls-files`
|
||||
git add .
|
||||
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 == "url") ''
|
||||
ruby ${./nix-bundle-install.rb} \
|
||||
"path" \
|
||||
'${gemName}' \
|
||||
'${version}' \
|
||||
'${lib.escapeShellArgs buildFlags}'
|
||||
''}
|
||||
${lib.optionalString (type == "git") ''
|
||||
ruby ${./nix-bundle-install.rb} \
|
||||
"git" \
|
||||
'${gemName}' \
|
||||
'${version}' \
|
||||
'${lib.escapeShellArgs buildFlags}' \
|
||||
'${attrs.source.url}' \
|
||||
'.' \
|
||||
'${attrs.source.rev}'
|
||||
''}
|
||||
|
||||
${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 \
|
||||
--install-dir "$GEM_HOME" \
|
||||
--build-root '/' \
|
||||
--backtrace \
|
||||
--no-env-shebang \
|
||||
${documentFlag} \
|
||||
$gempkg $gemFlags -- $buildFlags
|
||||
|
||||
# looks like useless files which break build repeatability and consume space
|
||||
pushd $out/${ruby.gemPath}
|
||||
find doc/ -iname created.rid -delete -print
|
||||
find gems/*/ext/ extensions/ \( -iname Makefile -o -iname mkmf.log -o -iname gem_make.out \) -delete -print
|
||||
${if keepGemCache then "" else "rm -fvr cache"}
|
||||
popd
|
||||
|
||||
# write out metadata and binstubs
|
||||
spec=$(echo $out/${ruby.gemPath}/specifications/*.gemspec)
|
||||
ruby ${./gem-post-build.rb} "$spec"
|
||||
''}
|
||||
|
||||
${lib.optionalString (!dontInstallManpages) ''
|
||||
for section in {1..9}; do
|
||||
mandir="$out/share/man/man$section"
|
||||
find $out/lib \( -wholename "*/man/*.$section" -o -wholename "*/man/man$section/*.$section" \) \
|
||||
-execdir mkdir -p $mandir \; -execdir cp '{}' $mandir \;
|
||||
done
|
||||
''}
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
propagatedBuildInputs = gemPath ++ propagatedBuildInputs;
|
||||
propagatedUserEnvPkgs = gemPath ++ propagatedUserEnvPkgs;
|
||||
|
||||
passthru = passthru // { isRubyGem = true; };
|
||||
meta = {
|
||||
# default to Ruby's platforms
|
||||
platforms = ruby.meta.platforms;
|
||||
} // meta;
|
||||
})
|
||||
|
||||
)
|
||||
81
pkgs/development/ruby-modules/gem/gem-post-build.rb
Normal file
81
pkgs/development/ruby-modules/gem/gem-post-build.rb
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
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(File::PATH_SEPARATOR).uniq
|
||||
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.
|
||||
#
|
||||
|
||||
require 'rubygems'
|
||||
|
||||
Gem.paths = {
|
||||
'GEM_PATH' => (
|
||||
ENV['GEM_PATH'].to_s.split(File::PATH_SEPARATOR) +
|
||||
#{([gem_home] + gem_path).to_s}
|
||||
).join(File::PATH_SEPARATOR)
|
||||
}
|
||||
|
||||
load Gem.activate_bin_path(#{spec.name.inspect}, #{exe.inspect}, #{spec.version.to_s.inspect})
|
||||
EOF
|
||||
end
|
||||
|
||||
FileUtils.chmod("+x", "#{bin_path}/#{exe}")
|
||||
end
|
||||
181
pkgs/development/ruby-modules/gem/nix-bundle-install.rb
Normal file
181
pkgs/development/ruby-modules/gem/nix-bundle-install.rb
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
require 'rbconfig'
|
||||
require 'bundler/vendored_thor'
|
||||
require 'bundler'
|
||||
require 'rubygems/command'
|
||||
require 'fileutils'
|
||||
require 'pathname'
|
||||
require 'tmpdir'
|
||||
require 'shellwords'
|
||||
|
||||
if defined?(Encoding.default_internal)
|
||||
Encoding.default_internal = Encoding::UTF_8
|
||||
Encoding.default_external = Encoding::UTF_8
|
||||
end
|
||||
|
||||
# Options:
|
||||
#
|
||||
# type - installation type, either "git" or "path"
|
||||
# name - the gem name
|
||||
# version - gem version
|
||||
# build-flags - build arguments
|
||||
#
|
||||
# Git-only options:
|
||||
#
|
||||
# uri - git repo uri
|
||||
# repo - path to local checkout
|
||||
# ref - the commit hash
|
||||
|
||||
ruby = File.join(ENV["ruby"], "bin", RbConfig::CONFIG['ruby_install_name'])
|
||||
out = ENV["out"]
|
||||
bin_dir = File.join(ENV["out"], "bin")
|
||||
|
||||
type = ARGV[0]
|
||||
name = ARGV[1]
|
||||
version = ARGV[2]
|
||||
build_flags = Shellwords.split(ARGV[3])
|
||||
if type == "git"
|
||||
uri = ARGV[4]
|
||||
REPO = ARGV[5]
|
||||
ref = ARGV[6]
|
||||
end
|
||||
|
||||
# options to pass to bundler
|
||||
options = {
|
||||
"name" => name,
|
||||
"version" => version,
|
||||
}
|
||||
if type == "path"
|
||||
options.merge!({
|
||||
"path" => Dir.pwd,
|
||||
})
|
||||
elsif type == "git"
|
||||
options.merge!({
|
||||
"uri" => uri,
|
||||
"ref" => ref,
|
||||
})
|
||||
end
|
||||
|
||||
# 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
|
||||
|
||||
if type == "git"
|
||||
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
|
||||
end
|
||||
|
||||
# UI
|
||||
verbose = false
|
||||
no_color = false
|
||||
Bundler.ui = Bundler::UI::Shell.new({"no-color" => no_color})
|
||||
Bundler.ui.level = "debug" if verbose
|
||||
|
||||
# Install
|
||||
if type == "git"
|
||||
source = Bundler::Source::Git.new(options)
|
||||
else
|
||||
source = Bundler::Source::Path.new(options)
|
||||
end
|
||||
spec = source.specs.search_all(name).first
|
||||
source.install(spec, :build_args => build_flags)
|
||||
|
||||
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
|
||||
if type == "git"
|
||||
File.open("#{meta}/install-path", "w") do |f|
|
||||
f.write source.install_path.to_s
|
||||
end
|
||||
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
|
||||
if type == "git"
|
||||
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
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue