summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibault Gagnaux <tgagnaux@gmail.com>2022-05-25 16:10:10 +0200
committerThibault Gagnaux <tgagnaux@gmail.com>2022-05-27 17:28:30 +0200
commit9f80b6d8fe87eccd39e7018512de6998c2765551 (patch)
treec7a582e066707ca822063a663caba7f0a39b4b1b
parent8395d7a4d390dad584ebc3f31c14c67f71e9c591 (diff)
downloadnixpkgs-9f80b6d8fe87eccd39e7018512de6998c2765551.tar
nixpkgs-9f80b6d8fe87eccd39e7018512de6998c2765551.tar.gz
nixpkgs-9f80b6d8fe87eccd39e7018512de6998c2765551.tar.bz2
nixpkgs-9f80b6d8fe87eccd39e7018512de6998c2765551.tar.lz
nixpkgs-9f80b6d8fe87eccd39e7018512de6998c2765551.tar.xz
nixpkgs-9f80b6d8fe87eccd39e7018512de6998c2765551.tar.zst
nixpkgs-9f80b6d8fe87eccd39e7018512de6998c2765551.zip
libreoffice: refactor and document version reset workaround
-rw-r--r--pkgs/applications/office/libreoffice/darwin/darwin.nix30
-rw-r--r--pkgs/applications/office/libreoffice/darwin/update-test.nix66
-rw-r--r--pkgs/applications/office/libreoffice/darwin/update-utils.nix43
3 files changed, 81 insertions, 58 deletions
diff --git a/pkgs/applications/office/libreoffice/darwin/darwin.nix b/pkgs/applications/office/libreoffice/darwin/darwin.nix
index 7b2f89cf0a5..9ac615486ab 100644
--- a/pkgs/applications/office/libreoffice/darwin/darwin.nix
+++ b/pkgs/applications/office/libreoffice/darwin/darwin.nix
@@ -48,20 +48,28 @@ stdenv.mkDerivation rec {
 
   passthru.updateScript =
     let
-      inherit (import ./update-utils.nix { inherit lib; }) getLatestStableVersion getSha256 nullHash;
+      inherit (import ./update-utils.nix { inherit lib; })
+        getLatestStableVersion
+        getSha256
+        nullHash;
       newVersion = getLatestStableVersion;
+      newAarch64Sha256 = getSha256 dist."aarch64-darwin".url version newVersion;
+      newX86_64Sha256 = getSha256 dist."x86_64-darwin".url version newVersion;
     in
     writeScript "update-libreoffice.sh"
-    ''
-      #!/usr/bin/env nix-shell
-      #!nix-shell -i bash -p common-updater-scripts
-      set -o errexit
-      set -o nounset
-      set -o pipefail
-      update-source-version libreoffice ${newVersion} ${getSha256 dist."aarch64-darwin".url version newVersion} --system=aarch64-darwin
-      update-source-version libreoffice 0 ${nullHash} --system=x86_64-darwin
-      update-source-version libreoffice ${newVersion} ${getSha256 dist."x86_64-darwin".url version newVersion} --system=x86_64-darwin
-    '';
+      ''
+        #!/usr/bin/env nix-shell
+        #!nix-shell -i bash -p common-updater-scripts
+        set -o errexit
+        set -o nounset
+        set -o pipefail
+        
+        # reset version first so that both platforms are always updated and in sync
+        update-source-version libreoffice 0 ${nullHash} --system=aarch64-darwin
+        update-source-version libreoffice ${newVersion} ${newAarch64Sha256} --system=aarch64-darwin
+        update-source-version libreoffice 0 ${nullHash} --system=x86_64-darwin
+        update-source-version libreoffice ${newVersion} ${newX86_64Sha256} --system=x86_64-darwin
+      '';
 
   meta = with lib; {
     description = "Comprehensive, professional-quality productivity suite, a variant of openoffice.org";
diff --git a/pkgs/applications/office/libreoffice/darwin/update-test.nix b/pkgs/applications/office/libreoffice/darwin/update-test.nix
index eeffec39830..d77992263f3 100644
--- a/pkgs/applications/office/libreoffice/darwin/update-test.nix
+++ b/pkgs/applications/office/libreoffice/darwin/update-test.nix
@@ -1,4 +1,6 @@
-{ pkgs ? import <nixpkgs> {}, nixt }:
+# run the tests with nixt <absolutePath to parent dir> -v
+
+{ pkgs ? import <nixpkgs> { }, nixt }:
 let
   inherit (import ./update-utils.nix { inherit (pkgs) lib; })
     extractLatestVersionFromHtml
@@ -6,36 +8,40 @@ let
 in
 nixt.mkSuite "LibreOffice Updater"
 {
-  "should extract latest stable version from html" = let
-    latestVersionHtmlMock =
-    ''
-      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-      <html xmlns="http://www.w3.org/1999/xhtml">
-      <head>
-      <title>Index of /libreoffice/stable</title>
-      <link rel="stylesheet" href="/mirrorbrain.css" type="text/css" />
-      </head>
-      <body>
-      <h1>Index of /libreoffice/stable</h1>
-      <table><tr><th>&nbsp;</th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th>Metadata</th></tr><tr><th colspan="5"><hr /></th></tr>
-      <tr><td valign="top">&nbsp;</td><td><a href="/libreoffice/">Parent Directory</a></td><td>&nbsp;</td><td align="right">  - </td><td>&nbsp;</td></tr>
-      <tr><td valign="top">&nbsp;</td><td><a href="7.2.7/">7.2.7/</a></td><td align="right">10-Mar-2022 11:12  </td><td align="right">  - </td><td>&nbsp;</td></tr>
-      <tr><td valign="top">&nbsp;</td><td><a href="7.3.3/">7.3.3/</a></td><td align="right">12-May-2022 10:06  </td><td align="right">  - </td><td>&nbsp;</td></tr>
-      <tr><td valign="top">&nbsp;</td><td><a href="7.2.6/">7.2.6/</a></td><td align="right">05-May-2022 07:57  </td><td align="right">  - </td><td>&nbsp;</td></tr>
-      <tr><th colspan="5"><hr /></th></tr>
-      </table>
-      <address>Apache Server at <a href="mailto:hostmaster@documentfoundation.org">download.documentfoundation.org</a> Port 80</address>
-      <br/><address><a href="http://mirrorbrain.org/">MirrorBrain</a> powered by <a href="http://httpd.apache.org/">Apache</a></address>
-      </body></html>
-    '';
+  "should extract latest stable version from html" =
+    let
+      latestVersionHtmlMock =
+        ''
+          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+          <html xmlns="http://www.w3.org/1999/xhtml">
+          <head>
+          <title>Index of /libreoffice/stable</title>
+          <link rel="stylesheet" href="/mirrorbrain.css" type="text/css" />
+          </head>
+          <body>
+          <h1>Index of /libreoffice/stable</h1>
+          <table><tr><th>&nbsp;</th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th>Metadata</th></tr><tr><th colspan="5"><hr /></th></tr>
+          <tr><td valign="top">&nbsp;</td><td><a href="/libreoffice/">Parent Directory</a></td><td>&nbsp;</td><td align="right">  - </td><td>&nbsp;</td></tr>
+          <tr><td valign="top">&nbsp;</td><td><a href="7.2.7/">7.2.7/</a></td><td align="right">10-Mar-2022 11:12  </td><td align="right">  - </td><td>&nbsp;</td></tr>
+          <tr><td valign="top">&nbsp;</td><td><a href="7.3.3/">7.3.3/</a></td><td align="right">12-May-2022 10:06  </td><td align="right">  - </td><td>&nbsp;</td></tr>
+          <tr><td valign="top">&nbsp;</td><td><a href="7.2.6/">7.2.6/</a></td><td align="right">05-May-2022 07:57  </td><td align="right">  - </td><td>&nbsp;</td></tr>
+          <tr><th colspan="5"><hr /></th></tr>
+          </table>
+          <address>Apache Server at <a href="mailto:hostmaster@documentfoundation.org">download.documentfoundation.org</a> Port 80</address>
+          <br/><address><a href="http://mirrorbrain.org/">MirrorBrain</a> powered by <a href="http://httpd.apache.org/">Apache</a></address>
+          </body></html>
+        '';
 
-    actual = extractLatestVersionFromHtml latestVersionHtmlMock;
+      actual = extractLatestVersionFromHtml latestVersionHtmlMock;
 
-  in "7.3.3" == actual;
+    in
+    "7.3.3" == actual;
 
-  "should extract sha256 from html" = let
-    sha256Html = "50ed3deb8d9c987516e2687ebb865bca15486c69da79f1b6d74381e43f2ec863  LibreOffice_7.3.3_MacOS_aarch64.dmg\n";
-    actual = extractSha256FromHtml sha256Html;
-  in "50ed3deb8d9c987516e2687ebb865bca15486c69da79f1b6d74381e43f2ec863" == actual;
+  "should extract sha256 from html" =
+    let
+      sha256Html = "50ed3deb8d9c987516e2687ebb865bca15486c69da79f1b6d74381e43f2ec863  LibreOffice_7.3.3_MacOS_aarch64.dmg\n";
+      actual = extractSha256FromHtml sha256Html;
+    in
+    "50ed3deb8d9c987516e2687ebb865bca15486c69da79f1b6d74381e43f2ec863" == actual;
 }
diff --git a/pkgs/applications/office/libreoffice/darwin/update-utils.nix b/pkgs/applications/office/libreoffice/darwin/update-utils.nix
index fb4a7b0e7b2..71d8417e674 100644
--- a/pkgs/applications/office/libreoffice/darwin/update-utils.nix
+++ b/pkgs/applications/office/libreoffice/darwin/update-utils.nix
@@ -1,45 +1,54 @@
 { lib }:
 let
-# extractLatestVersionFromHtml :: String -> String
+  # extractLatestVersionFromHtml :: String -> String
   extractLatestVersionFromHtml = htmlString:
     let
       majorMinorPatchGroup = "([0-9]+\\.[0-9]+\\.[0-9]+)";
       splittedVersions = builtins.split "href=\"${majorMinorPatchGroup}" htmlString;
-      stableVersions = builtins.concatLists (builtins.filter (e: builtins.isList e) splittedVersions);
+      stableVersions = builtins.concatLists
+        (builtins.filter (e: builtins.isList e)
+          splittedVersions);
     in
-      if stableVersions == []
-        then abort "Failed to extract versions from html."
-        else lib.last (builtins.sort builtins.lessThan stableVersions);
+    if stableVersions == [ ]
+    then abort "Failed to extract versions from html."
+    else lib.last (builtins.sort builtins.lessThan stableVersions);
 
-# getHtml :: String -> String
+  # getHtml :: String -> String
   getHtml = url:
     builtins.readFile (builtins.fetchurl url);
 
-# getLatestStableVersion :: String
+  # getLatestStableVersion :: String
   getLatestStableVersion =
-    extractLatestVersionFromHtml (getHtml "https://download.documentfoundation.org/libreoffice/stable/");
+    extractLatestVersionFromHtml
+      (getHtml "https://download.documentfoundation.org/libreoffice/stable/");
 
-# extractSha256FromHtml :: String -> String
+  # extractSha256FromHtml :: String -> String
   extractSha256FromHtml = htmlString:
     let
       sha256 = (builtins.match ".*([0-9a-fA-F]{64}).*" htmlString);
     in
-      if sha256 == []
-        then abort "Failed to extract sha256 from html."
-        else builtins.head sha256;
+    if sha256 == [ ]
+    then abort "Failed to extract sha256 from html."
+    else builtins.head sha256;
 
-# getSha256 :: String -> String
+  # getSha256 :: String -> String
   getSha256 = dmgUrl: oldVersion: newVersion:
     extractSha256FromHtml (getHtml (getSha256Url dmgUrl oldVersion newVersion));
 
-# getSha256Url :: String -> String -> String -> String
+  # getSha256Url :: String -> String -> String -> String
   getSha256Url = dmgUrl: oldVersion: newVersion:
     (builtins.replaceStrings [ oldVersion ] [ newVersion ] dmgUrl) + ".sha256";
 
-# nullHash :: String
+  # nullHash :: String
   nullHash = "0000000000000000000000000000000000000000000000000000000000000000";
 in
 {
-  inherit extractLatestVersionFromHtml getHtml getLatestStableVersion
-    extractSha256FromHtml getSha256 getSha256Url nullHash;
+  inherit
+    extractLatestVersionFromHtml
+    getHtml
+    getLatestStableVersion
+    extractSha256FromHtml
+    getSha256
+    getSha256Url
+    nullHash;
 }