Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 stdenv,
3 lib,
4 fetchurl,
5 buildRubyGem,
6 bundlerEnv,
7 ruby,
8 libarchive,
9 libguestfs,
10 qemu,
11 writeText,
12 withLibvirt ? stdenv.hostPlatform.isLinux,
13 openssl,
14}:
15
16let
17 # NOTE: bumping the version and updating the hash is insufficient;
18 # you must use bundix to generate a new gemset.nix in the Vagrant source.
19 version = "2.4.3";
20 url = "https://github.com/hashicorp/vagrant/archive/v${version}.tar.gz";
21 hash = "sha256-ZQWdSCV5lBL8XUnOvCFwJAFk+tw30q2lRTHR93qeZ2I=";
22
23 deps = bundlerEnv rec {
24 name = "${pname}-${version}";
25 pname = "vagrant";
26 inherit version;
27
28 inherit ruby;
29 gemfile = writeText "Gemfile" "";
30 lockfile = writeText "Gemfile.lock" "";
31 gemset = lib.recursiveUpdate (import ./gemset.nix) (
32 {
33 vagrant = {
34 source = {
35 type = "url";
36 inherit url hash;
37 };
38 inherit version;
39 };
40 }
41 // lib.optionalAttrs withLibvirt (import ./gemset_libvirt.nix)
42 );
43
44 # This replaces the gem symlinks with directories, resolving this
45 # error when running vagrant (I have no idea why):
46 # /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)
47 postBuild = ''
48 for gem in "$out"/lib/ruby/gems/*/gems/*; do
49 cp -a "$gem/" "$gem.new"
50 rm "$gem"
51 # needed on macOS, otherwise the mv yields permission denied
52 chmod +w "$gem.new"
53 mv "$gem.new" "$gem"
54 done
55 '';
56 };
57
58in
59buildRubyGem rec {
60 name = "${gemName}-${version}";
61 gemName = "vagrant";
62 inherit version;
63
64 doInstallCheck = true;
65 dontBuild = false;
66 src = fetchurl { inherit url hash; };
67
68 # Some reports indicate that some connection types, particularly
69 # WinRM, suffer from "Digest initialization failed" errors. Adding
70 # openssl as a build input resolves this runtime error.
71 buildInputs = [ openssl ];
72
73 patches = [
74 ./unofficial-installation-nowarn.patch
75 ./use-system-bundler-version.patch
76 ./0004-Support-system-installed-plugins.patch
77 ./0001-Revert-Merge-pull-request-12225-from-chrisroberts-re.patch
78 ];
79
80 postPatch = ''
81 substituteInPlace lib/vagrant/plugin/manager.rb --subst-var-by \
82 system_plugin_dir "$out/vagrant-plugins"
83 '';
84
85 # PATH additions:
86 # - libarchive: Make `bsdtar` available for extracting downloaded boxes
87 # withLibvirt only:
88 # - libguestfs: Make 'virt-sysprep' available for 'vagrant package'
89 # - qemu: Make 'qemu-img' available for 'vagrant package'
90 postInstall =
91 let
92 pathAdditions = lib.makeSearchPath "bin" (
93 map (x: lib.getBin x) (
94 [
95 libarchive
96 ]
97 ++ lib.optionals withLibvirt [
98 libguestfs
99 qemu
100 ]
101 )
102 );
103 in
104 ''
105 wrapProgram "$out/bin/vagrant" \
106 --set GEM_PATH "${deps}/lib/ruby/gems/${ruby.version.libDir}" \
107 --prefix PATH ':' ${pathAdditions} \
108 --set-default VAGRANT_CHECKPOINT_DISABLE 1
109
110 mkdir -p "$out/vagrant-plugins/plugins.d"
111 echo '{}' > "$out/vagrant-plugins/plugins.json"
112
113 # install bash completion
114 mkdir -p $out/share/bash-completion/completions/
115 cp -av contrib/bash/completion.sh $out/share/bash-completion/completions/vagrant
116 # install zsh completion
117 mkdir -p $out/share/zsh/site-functions/
118 cp -av contrib/zsh/_vagrant $out/share/zsh/site-functions/
119 ''
120 + lib.optionalString withLibvirt ''
121 substitute ${./vagrant-libvirt.json.in} $out/vagrant-plugins/plugins.d/vagrant-libvirt.json \
122 --subst-var-by ruby_version ${ruby.version} \
123 --subst-var-by vagrant_version ${version}
124 '';
125
126 installCheckPhase = ''
127 HOME="$(mktemp -d)" $out/bin/vagrant init --output - > /dev/null
128 '';
129
130 passthru = {
131 inherit ruby deps;
132 };
133
134 meta = with lib; {
135 description = "Tool for building complete development environments";
136 homepage = "https://www.vagrantup.com/";
137 license = licenses.bsl11;
138 maintainers = with maintainers; [ tylerjl ];
139 platforms = with platforms; linux ++ darwin;
140 };
141}