From 04990cdb8501c6410fd870b120e02d11ada6e579 Mon Sep 17 00:00:00 2001 From: Samuel Ainsworth Date: Tue, 3 Nov 2020 18:38:30 -0800 Subject: [PATCH 1/3] slack: refactor to be amenable to auto-updates --- .../instant-messengers/slack/default.nix | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/networking/instant-messengers/slack/default.nix b/pkgs/applications/networking/instant-messengers/slack/default.nix index bd41fc562bfc..6b2c2875e3ec 100644 --- a/pkgs/applications/networking/instant-messengers/slack/default.nix +++ b/pkgs/applications/networking/instant-messengers/slack/default.nix @@ -39,9 +39,16 @@ let throwSystem = throw "Unsupported system: ${system}"; pname = "slack"; + + x86_64-darwin-version = "4.10.3"; + x86_64-darwin-sha256 = "0r77l57vr603xamich4h4gbdd5vdcj0sjs6yjpymfx9s0f98v8bb"; + + x86_64-linux-version = "4.10.3"; + x86_64-linux-sha256 = "1gnjj2iyk8cwjajg8h9qpmzx10j4qjxjzciq8csg45qfzwkr3drf"; + version = { - x86_64-darwin = "4.10.3"; - x86_64-linux = "4.10.3"; + x86_64-darwin = x86_64-darwin-version; + x86_64-linux = x86_64-linux-version; }.${system} or throwSystem; src = let @@ -49,11 +56,11 @@ let in { x86_64-darwin = fetchurl { url = "${base}/releases/macos/${version}/prod/x64/Slack-${version}-macOS.dmg"; - sha256 = "0r77l57vr603xamich4h4gbdd5vdcj0sjs6yjpymfx9s0f98v8bb"; + sha256 = x86_64-darwin-sha256; }; x86_64-linux = fetchurl { url = "${base}/linux_releases/slack-desktop-${version}-amd64.deb"; - sha256 = "1gnjj2iyk8cwjajg8h9qpmzx10j4qjxjzciq8csg45qfzwkr3drf"; + sha256 = x86_64-linux-sha256; }; }.${system} or throwSystem; From f0fc6961fd5c9603c43b553628d36488708949fe Mon Sep 17 00:00:00 2001 From: Samuel Ainsworth Date: Tue, 3 Nov 2020 18:38:44 -0800 Subject: [PATCH 2/3] slack: add auto-updater script --- .../instant-messengers/slack/update.sh | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 pkgs/applications/networking/instant-messengers/slack/update.sh diff --git a/pkgs/applications/networking/instant-messengers/slack/update.sh b/pkgs/applications/networking/instant-messengers/slack/update.sh new file mode 100755 index 000000000000..adef44411091 --- /dev/null +++ b/pkgs/applications/networking/instant-messengers/slack/update.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p curl gnused + +set -eou pipefail + +latest_linux_version=$(curl --silent https://slack.com/downloads/linux | sed -n 's/.*Version \([0-9\.]\+\).*/\1/p') +latest_mac_version=$(curl --silent https://slack.com/downloads/mac | sed -n 's/.*Version \([0-9\.]\+\).*/\1/p') + +# Double check that the latest mac and linux versions are in sync. +if [[ "$latest_linux_version" != "$latest_mac_version" ]]; then + echo "the latest linux ($latest_linux_version) and mac ($latest_mac_version) versions are not the same" + exit 1 +fi + +nixpkgs="$(git rev-parse --show-toplevel)" +slack_nix="$nixpkgs/pkgs/applications/networking/instant-messengers/slack/default.nix" +nixpkgs_linux_version=$(cat "$slack_nix" | sed -n 's/.*x86_64-linux-version = \"\([0-9\.]\+\)\";.*/\1/p') +nixpkgs_mac_version=$(cat "$slack_nix" | sed -n 's/.*x86_64-darwin-version = \"\([0-9\.]\+\)\";.*/\1/p') + +if [[ "$nixpkgs_linux_version" == "$latest_linux_version" && "$nixpkgs_mac_version" == "$latest_mac_version" ]]; then + echo "nixpkgs versions are all up to date!" + exit 0 +fi + +linux_url="https://downloads.slack-edge.com/linux_releases/slack-desktop-${latest_linux_version}-amd64.deb" +mac_url="https://downloads.slack-edge.com/releases/macos/${latest_mac_version}/prod/x64/Slack-${latest_mac_version}-macOS.dmg" +linux_sha256=$(nix-prefetch-url ${linux_url}) +mac_sha256=$(nix-prefetch-url ${mac_url}) + +sed -i "s/x86_64-linux-version = \".*\"/x86_64-linux-version = \"${latest_linux_version}\"/" "$slack_nix" +sed -i "s/x86_64-darwin-version = \".*\"/x86_64-darwin-version = \"${latest_mac_version}\"/" "$slack_nix" +sed -i "s/x86_64-linux-sha256 = \".*\"/x86_64-linux-sha256 = \"${linux_sha256}\"/" "$slack_nix" +sed -i "s/x86_64-darwin-sha256 = \".*\"/x86_64-darwin-sha256 = \"${mac_sha256}\"/" "$slack_nix" + +if ! nix-build -A slack "$nixpkgs"; then + echo "The updated slack failed to build." + exit 1 +fi + +echo "Successfully updated" +echo "slack: $nixpkgs_linux_version -> $latest_linux_version" From 3037318511eccef339099704773564ee2b1bffe1 Mon Sep 17 00:00:00 2001 From: Samuel Ainsworth Date: Wed, 4 Nov 2020 16:12:36 -0800 Subject: [PATCH 3/3] slack: add passthru.updateScript --- .../networking/instant-messengers/slack/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/applications/networking/instant-messengers/slack/default.nix b/pkgs/applications/networking/instant-messengers/slack/default.nix index 6b2c2875e3ec..d27bd6a521de 100644 --- a/pkgs/applications/networking/instant-messengers/slack/default.nix +++ b/pkgs/applications/networking/instant-messengers/slack/default.nix @@ -75,6 +75,8 @@ let linux = stdenv.mkDerivation rec { inherit pname version src meta; + passthru.updateScript = ./update.sh; + rpath = stdenv.lib.makeLibraryPath [ alsaLib at-spi2-atk @@ -159,6 +161,8 @@ let darwin = stdenv.mkDerivation { inherit pname version src meta; + passthru.updateScript = ./update.sh; + nativeBuildInputs = [ undmg ]; sourceRoot = "Slack.app";