summary refs log tree commit diff
path: root/pkgs/development/tools/vagrant/default.nix
diff options
context:
space:
mode:
authorRyan Artecona <ryanartecona@gmail.com>2016-10-09 15:23:32 -0400
committerRyan Artecona <ryanartecona@gmail.com>2016-10-09 15:25:41 -0400
commit224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac (patch)
treecea9fde3f55bb72bf8872706a0cd0d27887f61a7 /pkgs/development/tools/vagrant/default.nix
parentca6b9be5d197f19a59862f9c64b17fcda77e463d (diff)
downloadnixpkgs-224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac.tar
nixpkgs-224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac.tar.gz
nixpkgs-224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac.tar.bz2
nixpkgs-224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac.tar.lz
nixpkgs-224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac.tar.xz
nixpkgs-224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac.tar.zst
nixpkgs-224a6b85fa0ef0b8496a3a6d1b3bf0a6903099ac.zip
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.
Diffstat (limited to 'pkgs/development/tools/vagrant/default.nix')
-rw-r--r--pkgs/development/tools/vagrant/default.nix52
1 files changed, 38 insertions, 14 deletions
diff --git a/pkgs/development/tools/vagrant/default.nix b/pkgs/development/tools/vagrant/default.nix
index cf4f34cbdfe..062873f0ccd 100644
--- a/pkgs/development/tools/vagrant/default.nix
+++ b/pkgs/development/tools/vagrant/default.nix
@@ -1,7 +1,5 @@
 { stdenv, fetchurl, fetchpatch, dpkg, curl, libarchive, openssl, ruby, buildRubyGem, libiconv
-, libxml2, libxslt, makeWrapper }:
-
-assert stdenv.system == "x86_64-linux" || stdenv.system == "i686-linux";
+, libxml2, libxslt, makeWrapper, p7zip, xar, gzip, cpio }:
 
 let
   version = "1.8.6";
@@ -12,9 +10,16 @@ let
     sha256 = "1rn03rqlf1iv6n87a78hkda2yqparhhaivfjpizblmxvlw2hk5r8";
   };
 
+  url = if stdenv.isLinux
+    then "https://releases.hashicorp.com/vagrant/${version}/vagrant_${version}_${arch}.deb"
+    else if stdenv.isDarwin
+      then "https://releases.hashicorp.com/vagrant/${version}/vagrant_${version}.dmg"
+      else "system ${stdenv.system} not supported";
+
   sha256 = {
-    "x86_64-linux" = "1nkhf160hcl02yvafj6hq53j204qqxyvxjngnmf4f5md8dmkpn76";
-    "i686-linux"   = "0mr4pn7nggjdsqyxh1z2mflvvmpzhbxh5gax501d2hi8xr0y68df";
+    "x86_64-linux"  = "1nkhf160hcl02yvafj6hq53j204qqxyvxjngnmf4f5md8dmkpn76";
+    "i686-linux"    = "0mr4pn7nggjdsqyxh1z2mflvvmpzhbxh5gax501d2hi8xr0y68df";
+    "x86_64-darwin" = "1nd2adxwhs2vwmi5vw2z720ny4q9rpj8i4dlcdxzbyli7h8cs5mr";
   }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
 
   arch = builtins.replaceStrings ["-linux"] [""] stdenv.system;
@@ -24,8 +29,7 @@ in stdenv.mkDerivation rec {
   inherit version;
 
   src = fetchurl {
-    url = "https://releases.hashicorp.com/vagrant/${version}/vagrant_${version}_${arch}.deb";
-    inherit sha256;
+    inherit url sha256;
   };
 
   meta = with stdenv.lib; {
@@ -33,14 +37,29 @@ in stdenv.mkDerivation rec {
     homepage    = http://vagrantup.com;
     license     = licenses.mit;
     maintainers = with maintainers; [ lovek323 globin jgeerds kamilchm ];
-    platforms   = platforms.linux;
+    platforms   = with platforms; linux ++ darwin;
   };
 
-  buildInputs = [ makeWrapper ];
-
-  unpackPhase = ''
-    ${dpkg}/bin/dpkg-deb -x "$src" .
-  '';
+  buildInputs = [ makeWrapper ]
+    ++ stdenv.lib.optional stdenv.isDarwin [ p7zip xar gzip cpio ];
+
+  unpackPhase = if stdenv.isLinux
+    then ''
+      ${dpkg}/bin/dpkg-deb -x "$src" .
+    ''
+    else ''
+      7z x $src
+      cd Vagrant/
+      xar -xf Vagrant.pkg
+      cd core.pkg/
+      cat Payload | gzip -d - | cpio -id
+
+      # move unpacked directories to match unpacked .deb from linux,
+      # so installPhase can be shared
+      mkdir -p opt/vagrant/ usr/
+      mv embedded opt/vagrant/embedded
+      mv bin usr/bin
+    '';
 
   buildPhase = "";
 
@@ -110,5 +129,10 @@ in stdenv.mkDerivation rec {
   postFixup = ''
     chmod +x "$out/opt/vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/templates/Executable"
     chmod +x "$out/opt/vagrant/embedded/gems/gems/vagrant-$version/plugins/provisioners/salt/bootstrap-salt.sh"
-  '';
+  '' +
+  (stdenv.lib.optionalString stdenv.isDarwin ''
+    # undo the directory movement done in unpackPhase
+    mv $out/opt/vagrant/embedded $out/
+    rm -r $out/opt
+  '');
 }