git.iko.soy/typeable/nixpkgs
on master help sign in
vagrant: add darwin support

Vagrant on macOS is distributed as a .dmg installer. Luckily, the internal contents of that archive resemble that of the .deb we use for linux. In fact, the similarity is enough that if we move its `embedded` directory to `opt/vagrant/embedded` and its `bin` to `usr/bin` (and back again after installation), the derivation's installPhase (which replaces embedded libs & binaries with those from the package's inputs) can remain exactly the same between macOS and linux.

commit224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac authorRyan Artecona <ryanartecona@gmail.com> dateSun 9 Oct 2016, 15:23 (10 years ago) parentca6b9be
1 file changed+38−14
pkgs/development/tools/vagrant/default.nix+38−14
pkgs/development/tools/vagrant/default.nix+38−14
@@ -1,7 +1,5 @@
11{ stdenv, fetchurl, fetchpatch, dpkg, curl, libarchive, openssl, ruby, buildRubyGem, libiconv
2−, libxml2, libxslt, makeWrapper }:
3−
4−assert stdenv.system == "x86_64-linux" || stdenv.system == "i686-linux";
2+, libxml2, libxslt, makeWrapper, p7zip, xar, gzip, cpio }:
53
64let
75 version = "1.8.6";
@@ -12,9 +10,16 @@ let
1210 sha256 = "1rn03rqlf1iv6n87a78hkda2yqparhhaivfjpizblmxvlw2hk5r8";
1311 };
1412
13+ url = if stdenv.isLinux
14+ then "https://releases.hashicorp.com/vagrant/${version}/vagrant_${version}_${arch}.deb"
15+ else if stdenv.isDarwin
16+ then "https://releases.hashicorp.com/vagrant/${version}/vagrant_${version}.dmg"
17+ else "system ${stdenv.system} not supported";
18+
1519 sha256 = {
16− "x86_64-linux" = "1nkhf160hcl02yvafj6hq53j204qqxyvxjngnmf4f5md8dmkpn76";
17− "i686-linux" = "0mr4pn7nggjdsqyxh1z2mflvvmpzhbxh5gax501d2hi8xr0y68df";
20+ "x86_64-linux" = "1nkhf160hcl02yvafj6hq53j204qqxyvxjngnmf4f5md8dmkpn76";
21+ "i686-linux" = "0mr4pn7nggjdsqyxh1z2mflvvmpzhbxh5gax501d2hi8xr0y68df";
22+ "x86_64-darwin" = "1nd2adxwhs2vwmi5vw2z720ny4q9rpj8i4dlcdxzbyli7h8cs5mr";
1823 }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
1924
2025 arch = builtins.replaceStrings ["-linux"] [""] stdenv.system;
@@ -24,8 +29,7 @@ in stdenv.mkDerivation rec {
2429 inherit version;
2530
2631 src = fetchurl {
27− url = "https://releases.hashicorp.com/vagrant/${version}/vagrant_${version}_${arch}.deb";
28− inherit sha256;
32+ inherit url sha256;
2933 };
3034
3135 meta = with stdenv.lib; {
@@ -33,14 +37,29 @@ in stdenv.mkDerivation rec {
3337 homepage = http://vagrantup.com;
3438 license = licenses.mit;
3539 maintainers = with maintainers; [ lovek323 globin jgeerds kamilchm ];
36− platforms = platforms.linux;
40+ platforms = with platforms; linux ++ darwin;
3741 };
3842
39− buildInputs = [ makeWrapper ];
40−
41− unpackPhase = ''
42− ${dpkg}/bin/dpkg-deb -x "$src" .
43− '';
43+ buildInputs = [ makeWrapper ]
44+ ++ stdenv.lib.optional stdenv.isDarwin [ p7zip xar gzip cpio ];
45+
46+ unpackPhase = if stdenv.isLinux
47+ then ''
48+ ${dpkg}/bin/dpkg-deb -x "$src" .
49+ ''
50+ else ''
51+ 7z x $src
52+ cd Vagrant/
53+ xar -xf Vagrant.pkg
54+ cd core.pkg/
55+ cat Payload | gzip -d - | cpio -id
56+
57+ # move unpacked directories to match unpacked .deb from linux,
58+ # so installPhase can be shared
59+ mkdir -p opt/vagrant/ usr/
60+ mv embedded opt/vagrant/embedded
61+ mv bin usr/bin
62+ '';
4463
4564 buildPhase = "";
4665
@@ -110,5 +129,10 @@ in stdenv.mkDerivation rec {
110129 postFixup = ''
111130 chmod +x "$out/opt/vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/templates/Executable"
112131 chmod +x "$out/opt/vagrant/embedded/gems/gems/vagrant-$version/plugins/provisioners/salt/bootstrap-salt.sh"
113− '';
132+ '' +
133+ (stdenv.lib.optionalString stdenv.isDarwin ''
134+ # undo the directory movement done in unpackPhase
135+ mv $out/opt/vagrant/embedded $out/
136+ rm -r $out/opt
137+ '');
114138}