lol
1{ stdenv, lib, fetchurl, buildRubyGem, bundlerEnv, ruby, libarchive
2, libguestfs, qemu, writeText, withLibvirt ? stdenv.isLinux
3}:
4
5let
6 # NOTE: bumping the version and updating the hash is insufficient;
7 # you must use bundix to generate a new gemset.nix in the Vagrant source.
8 version = "2.3.4";
9 url = "https://github.com/hashicorp/vagrant/archive/v${version}.tar.gz";
10 sha256 = "sha256-Q+sUYcbc/SOgw4ZXDmwqh24G0jiLvA8fDJyZ45OqLw8=";
11
12 deps = bundlerEnv rec {
13 name = "${pname}-${version}";
14 pname = "vagrant";
15 inherit version;
16
17 inherit ruby;
18 gemfile = writeText "Gemfile" "";
19 lockfile = writeText "Gemfile.lock" "";
20 gemset = lib.recursiveUpdate (import ./gemset.nix) ({
21 vagrant = {
22 source = {
23 type = "url";
24 inherit url sha256;
25 };
26 inherit version;
27 };
28 } // lib.optionalAttrs withLibvirt (import ./gemset_libvirt.nix));
29
30 # This replaces the gem symlinks with directories, resolving this
31 # error when running vagrant (I have no idea why):
32 # /nix/store/p4hrycs0zaa9x0gsqylbk577ppnryixr-vagrant-2.2.6/lib/ruby/gems/2.6.0/gems/i18n-1.1.1/lib/i18n/config.rb:6:in `<module:I18n>': uninitialized constant I18n::Config (NameError)
33 postBuild = ''
34 for gem in "$out"/lib/ruby/gems/*/gems/*; do
35 cp -a "$gem/" "$gem.new"
36 rm "$gem"
37 # needed on macOS, otherwise the mv yields permission denied
38 chmod +w "$gem.new"
39 mv "$gem.new" "$gem"
40 done
41 '';
42 };
43
44in buildRubyGem rec {
45 name = "${gemName}-${version}";
46 gemName = "vagrant";
47 inherit version;
48
49 doInstallCheck = true;
50 dontBuild = false;
51 src = fetchurl { inherit url sha256; };
52
53 patches = [
54 ./unofficial-installation-nowarn.patch
55 ./use-system-bundler-version.patch
56 ./0004-Support-system-installed-plugins.patch
57 ./0001-Revert-Merge-pull-request-12225-from-chrisroberts-re.patch
58 ];
59
60 postPatch = ''
61 substituteInPlace lib/vagrant/plugin/manager.rb --subst-var-by \
62 system_plugin_dir "$out/vagrant-plugins"
63 '';
64
65 # PATH additions:
66 # - libarchive: Make `bsdtar` available for extracting downloaded boxes
67 # withLibvirt only:
68 # - libguestfs: Make 'virt-sysprep' available for 'vagrant package'
69 # - qemu: Make 'qemu-img' available for 'vagrant package'
70 postInstall =
71 let
72 pathAdditions = lib.makeSearchPath "bin"
73 (map (x: lib.getBin x) ([
74 libarchive
75 ] ++ lib.optionals withLibvirt [
76 libguestfs
77 qemu
78 ]));
79 in ''
80 wrapProgram "$out/bin/vagrant" \
81 --set GEM_PATH "${deps}/lib/ruby/gems/${ruby.version.libDir}" \
82 --prefix PATH ':' ${pathAdditions} \
83 --set-default VAGRANT_CHECKPOINT_DISABLE 1
84
85 mkdir -p "$out/vagrant-plugins/plugins.d"
86 echo '{}' > "$out/vagrant-plugins/plugins.json"
87
88 mkdir -p $out/share/bash-completion/completions/
89 cp -av contrib/bash/completion.sh $out/share/bash-completion/completions/vagrant
90 '' +
91 lib.optionalString withLibvirt ''
92 substitute ${./vagrant-libvirt.json.in} $out/vagrant-plugins/plugins.d/vagrant-libvirt.json \
93 --subst-var-by ruby_version ${ruby.version} \
94 --subst-var-by vagrant_version ${version}
95 '';
96
97 installCheckPhase = ''
98 HOME="$(mktemp -d)" $out/bin/vagrant init --output - > /dev/null
99 '';
100
101 # `patchShebangsAuto` patches this one script which is intended to run
102 # on foreign systems.
103 postFixup = ''
104 sed -i -e '1c#!/bin/sh -' \
105 $out/lib/ruby/gems/*/gems/vagrant-*/plugins/provisioners/salt/bootstrap-salt.sh
106 '';
107
108 passthru = {
109 inherit ruby deps;
110 };
111
112 meta = with lib; {
113 description = "A tool for building complete development environments";
114 homepage = "https://www.vagrantup.com/";
115 license = licenses.mit;
116 maintainers = with maintainers; [ ];
117 platforms = with platforms; linux ++ darwin;
118 };
119}