From 459642b8de0ec77ed545786b1c63fbd8a66e38a7 Mon Sep 17 00:00:00 2001
From: aszlig <aszlig@redmoonstudios.org>
Date: Fri, 26 Feb 2016 10:47:04 +0100
Subject: [PATCH] chromium/updater: Allow a single plugin arch

Until now, if we have a failure to fetch either the 32bit Debian package
or the 64bit Debian package, neither of these will be put into
sources.nix.

Unfortunately the beta/dev channels do not have a 32bit Debian package,
so even though there is a 64bit Debian package available we don't get
plugins *at* *all*.

This also introduces a nicer error message rather than just failing with
an assertion in fetchurl because we did not provide url/urls.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
---
 .../browsers/chromium/source/update.nix       | 32 ++++++++++++-------
 .../networking/browsers/chromium/update.sh    |  5 +--
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/pkgs/applications/networking/browsers/chromium/source/update.nix b/pkgs/applications/networking/browsers/chromium/source/update.nix
index 49864cf1c7b..77ebb9488e2 100644
--- a/pkgs/applications/networking/browsers/chromium/source/update.nix
+++ b/pkgs/applications/networking/browsers/chromium/source/update.nix
@@ -62,14 +62,18 @@ in rec {
       pname = if channel == "dev"
               then "google-chrome-unstable"
               else "google-chrome-${channel}";
-      arch = if stdenv.is64bit then "amd64" else "i386";
-      relpath = "${pname}/${pname}_${chanAttrs.version}-1_${arch}.deb";
-    in lib.optionalAttrs (chanAttrs ? sha256bin64) {
-      urls = map (url: "${url}/${relpath}") ([ debURL ] ++ debMirrors);
-      sha256 = if stdenv.is64bit
-               then chanAttrs.sha256bin64
-               else chanAttrs.sha256bin32;
-    };
+
+      mkUrls = arch: let
+        relpath = "${pname}/${pname}_${chanAttrs.version}-1_${arch}.deb";
+      in map (url: "${url}/${relpath}") ([ debURL ] ++ debMirrors);
+
+    in if stdenv.is64bit && chanAttrs ? sha256bin64 then {
+      urls = mkUrls "amd64";
+      sha256 = chanAttrs.sha256bin64;
+    } else if stdenv.is32bit && chanAttrs ? sha256bin32 then {
+      urls = mkUrls "i386";
+      sha256 = chanAttrs.sha256bin64;
+    } else throw "No Chrome plugins are available for your architecture.";
   };
 
   updateHelpers = writeText "update-helpers.sh" ''
@@ -91,11 +95,15 @@ in rec {
 
       deb_pre="${debURL}/$pname/$pname";
 
-      deb32=$(nix-prefetch-url "''${deb_pre}_$version-1_i386.deb");
-      deb64=$(nix-prefetch-url "''${deb_pre}_$version-1_amd64.deb");
+      deb32="$(nix-prefetch-url "''${deb_pre}_$version-1_i386.deb")" || :
+      deb64="$(nix-prefetch-url "''${deb_pre}_$version-1_amd64.deb")" || :
 
-      echo "$deb32.$deb64";
-      return 0;
+      if [ -n "$deb32" -o -n "$deb64" ]; then
+        echo "$deb32.$deb64";
+        return 0
+      else
+        return 1
+      fi
     }
 
     prefetch_sha()
diff --git a/pkgs/applications/networking/browsers/chromium/update.sh b/pkgs/applications/networking/browsers/chromium/update.sh
index e079762420b..975e141e668 100755
--- a/pkgs/applications/networking/browsers/chromium/update.sh
+++ b/pkgs/applications/networking/browsers/chromium/update.sh
@@ -77,9 +77,10 @@ get_channel_exprs()
         echo "  $channel = {";
         echo "    version = \"$version\";";
         echo "    sha256 = \"$main\";";
-        if [ "x${deb#*[a-z0-9].[a-z0-9]}" != "x$deb" ];
-        then
+        if [ "x${deb#[a-z0-9]}" != "x$deb" ]; then
             echo "    sha256bin32 = \"$deb32\";";
+        fi;
+        if [ "x${deb#*.[a-z0-9]}" != "x$deb" ]; then
             echo "    sha256bin64 = \"$deb64\";";
         fi;
         echo "  };";