nixpkgs/pkgs/development/tools/vagrant/default.nix

109 lines
3.7 KiB
Nix
Raw Normal View History

{ stdenv, fetchurl, dpkg, curl, libarchive, openssl, ruby, buildRubyGem, libiconv
, libxml2, libxslt, makeWrapper }:
2013-11-21 23:21:39 +01:00
assert stdenv.system == "x86_64-linux" || stdenv.system == "i686-linux";
2014-11-18 05:24:07 +01:00
let
2015-12-22 11:28:46 +01:00
version = "1.8.0";
2014-11-18 05:24:07 +01:00
rake = buildRubyGem {
inherit ruby;
ruby: new bundler infrastructure This improves our Bundler integration (i.e. `bundlerEnv`). Before describing the implementation differences, I'd like to point a breaking change: buildRubyGem now expects `gemName` and `version` as arguments, rather than a `name` attribute in the form of "<gem-name>-<version>". Now for the differences in implementation. The previous implementation installed all gems at once in a single derivation. This was made possible by using a set of monkey-patches to prevent Bundler from downloading gems impurely, and to help Bundler find and activate all required gems prior to installation. This had several downsides: * The patches were really hard to understand, and required subtle interaction with the rest of the build environment. * A single install failure would cause the entire derivation to fail. The new implementation takes a different approach: we install gems into separate derivations, and then present Bundler with a symlink forest thereof. This has a couple benefits over the existing approach: * Fewer patches are required, with less interplay with the rest of the build environment. * Changes to one gem no longer cause a rebuild of the entire dependency graph. * Builds take 20% less time (using gitlab as a reference). It's unfortunate that we still have to muck with Bundler's internals, though it's unavoidable with the way that Bundler is currently designed. There are a number improvements that could be made in Bundler that would simplify our packaging story: * Bundler requires all installed gems reside within the same prefix (GEM_HOME), unlike RubyGems which allows for multiple prefixes to be specified through GEM_PATH. It would be ideal if Bundler allowed for packages to be installed and sourced from multiple prefixes. * Bundler installs git sources very differently from how RubyGems installs gem packages, and, unlike RubyGems, it doesn't provide a public interface (CLI or programmatic) to guide the installation of a single gem. We are presented with the options of either reimplementing a considerable portion Bundler, or patch and use parts of its internals; I choose the latter. Ideally, there would be a way to install gems from git sources in a manner similar to how we drive `gem` to install gem packages. * When a bundled program is executed (via `bundle exec` or a binstub that does `require 'bundler/setup'`), the setup process reads the Gemfile.lock, activates the dependencies, re-serializes the lock file it read earlier, and then attempts to overwrite the Gemfile.lock if the contents aren't bit-identical. I think the reasoning is that by merely running an application with a newer version of Bundler, you'll automatically keep the Gemfile.lock up-to-date with any changes in the format. Unfortunately, that doesn't play well with any form of packaging, because bundler will immediately cause the application to abort when it attempts to write to the read-only Gemfile.lock in the store. We work around this by normalizing the Gemfile.lock with the version of Bundler that we'll use at runtime before we copy it into the store. This feels fragile, but it's the best we can do without changes upstream, or resorting to more delicate hacks. With all of the challenges in using Bundler, one might wonder why we can't just cut Bundler out of the picture and use RubyGems. After all, Nix provides most of the isolation that Bundler is used for anyway. The problem, however, is that almost every Rails application calls `Bundler::require` at startup (by way of the default project templates). Because bundler will then, by default, `require` each gem listed in the Gemfile, Rails applications are almost always written such that none of the source files explicitly require their dependencies. That leaves us with two options: support and use Bundler, or maintain massive patches for every Rails application that we package. Closes #8612
2015-11-15 03:17:29 +01:00
gemName = "rake";
version = "10.4.2";
2015-12-22 11:28:46 +01:00
sha256 = "1rn03rqlf1iv6n87a78hkda2yqparhhaivfjpizblmxvlw2hk5r8";
2014-11-18 05:24:07 +01:00
};
2014-09-04 20:24:21 +02:00
in
2013-11-21 23:21:39 +01:00
stdenv.mkDerivation rec {
2014-09-04 20:24:21 +02:00
name = "vagrant-${version}";
2013-11-21 23:21:39 +01:00
src =
if stdenv.system == "x86_64-linux" then
fetchurl {
2015-12-22 11:28:46 +01:00
url = "https://releases.hashicorp.com/vagrant/${version}/vagrant_${version}_x86_64.deb";
sha256 = "0hvi6db5lphgzsykm1wn76jj4wwmm6lshvvd0qz7ipyyyhnd7sjp";
2013-11-21 23:21:39 +01:00
}
else
fetchurl {
2015-12-22 11:28:46 +01:00
url = "https://releases.hashicorp.com/vagrant/${version}/vagrant_${version}_i686.deb";
sha256 = "1jvscbxqbhavw4q81y5718qbyj74b9lwfw3gb4c1f4jmgm08wxxk";
2013-11-21 23:21:39 +01:00
};
meta = with stdenv.lib; {
description = "A tool for building complete development environments";
homepage = http://vagrantup.com;
license = licenses.mit;
2015-06-22 08:25:07 +02:00
maintainers = with maintainers; [ lovek323 globin jgeerds ];
2013-11-21 23:21:39 +01:00
platforms = platforms.linux;
};
buildInputs = [ makeWrapper ];
2013-11-21 23:21:39 +01:00
unpackPhase = ''
${dpkg}/bin/dpkg-deb -x ${src} .
'';
buildPhase = false;
installPhase = ''
sed -i "s|/opt|$out/opt|" usr/bin/vagrant
# overwrite embedded binaries
2015-12-22 11:28:46 +01:00
# curl: curl, curl-config
rm opt/vagrant/embedded/bin/{curl,curl-config}
2013-11-21 23:21:39 +01:00
ln -s ${curl}/bin/curl opt/vagrant/embedded/bin
2015-12-22 11:28:46 +01:00
ln -s ${curl}/bin/curl-config opt/vagrant/embedded/bin
2013-11-21 23:21:39 +01:00
# libarchive: bsdtar, bsdcpio
rm opt/vagrant/embedded/bin/{bsdtar,bsdcpio}
ln -s ${libarchive}/bin/bsdtar opt/vagrant/embedded/bin
ln -s ${libarchive}/bin/bsdcpio opt/vagrant/embedded/bin
# openssl: c_rehash, openssl
rm opt/vagrant/embedded/bin/{c_rehash,openssl}
ln -s ${openssl}/bin/c_rehash opt/vagrant/embedded/bin
ln -s ${openssl}/bin/openssl opt/vagrant/embedded/bin
2015-12-22 11:28:46 +01:00
# ruby: erb, gem, irb, rake, rdoc, ri, ruby
rm opt/vagrant/embedded/bin/{erb,gem,irb,rake,rdoc,ri,ruby}
2013-11-21 23:21:39 +01:00
ln -s ${ruby}/bin/erb opt/vagrant/embedded/bin
ln -s ${ruby}/bin/gem opt/vagrant/embedded/bin
ln -s ${ruby}/bin/irb opt/vagrant/embedded/bin
2014-11-18 05:24:07 +01:00
ln -s ${rake}/bin/rake opt/vagrant/embedded/bin
2013-11-21 23:21:39 +01:00
ln -s ${ruby}/bin/rdoc opt/vagrant/embedded/bin
ln -s ${ruby}/bin/ri opt/vagrant/embedded/bin
ln -s ${ruby}/bin/ruby opt/vagrant/embedded/bin
# libiconv: iconv
rm opt/vagrant/embedded/bin/iconv
ln -s ${libiconv}/bin/iconv opt/vagrant/embedded/bin
2013-11-21 23:21:39 +01:00
# libxml: xml2-config, xmlcatalog, xmllint
rm opt/vagrant/embedded/bin/{xml2-config,xmlcatalog,xmllint}
ln -s ${libxml2}/bin/xml2-config opt/vagrant/embedded/bin
ln -s ${libxml2}/bin/xmlcatalog opt/vagrant/embedded/bin
ln -s ${libxml2}/bin/xmllint opt/vagrant/embedded/bin
# libxslt: xslt-config, xsltproc
rm opt/vagrant/embedded/bin/{xslt-config,xsltproc}
ln -s ${libxslt}/bin/xslt-config opt/vagrant/embedded/bin
ln -s ${libxslt}/bin/xsltproc opt/vagrant/embedded/bin
mkdir -p "$out"
cp -r opt "$out"
cp -r usr/bin "$out"
wrapProgram $out/bin/vagrant --prefix LD_LIBRARY_PATH : $out/opt/vagrant/embedded/lib
2013-11-21 23:21:39 +01:00
'';
2014-07-15 02:47:11 +02:00
preFixup = ''
# 'hide' the template file from shebang-patching
2015-12-22 11:28:46 +01:00
chmod -x $out/opt/vagrant/embedded/gems/gems/bundler-1.10.6/lib/bundler/templates/Executable
2015-04-29 13:15:17 +02:00
chmod -x $out/opt/vagrant/embedded/gems/gems/vagrant-${version}/plugins/provisioners/salt/bootstrap-salt.sh
2014-07-15 02:47:11 +02:00
'';
postFixup = ''
2015-12-22 11:28:46 +01:00
chmod +x $out/opt/vagrant/embedded/gems/gems/bundler-1.10.6/lib/bundler/templates/Executable
2015-04-29 13:15:17 +02:00
chmod +x $out/opt/vagrant/embedded/gems/gems/vagrant-${version}/plugins/provisioners/salt/bootstrap-salt.sh
2014-07-15 02:47:11 +02:00
'';
2013-11-21 23:21:39 +01:00
}