about summary refs log tree commit diff
path: root/nixpkgs/maintainers/scripts/update-discord
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/maintainers/scripts/update-discord')
-rwxr-xr-xnixpkgs/maintainers/scripts/update-discord36
1 files changed, 36 insertions, 0 deletions
diff --git a/nixpkgs/maintainers/scripts/update-discord b/nixpkgs/maintainers/scripts/update-discord
new file mode 100755
index 000000000000..23ec6e401be4
--- /dev/null
+++ b/nixpkgs/maintainers/scripts/update-discord
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+# script to generate `pkgs/networking/instant-messengers/discord/default.nix`
+
+set -e
+exec >${1:?usage: $0 <output-file>}
+
+cat <<EOF
+{ branch ? "stable", pkgs }:
+
+let
+  inherit (pkgs) callPackage fetchurl;
+in {
+EOF
+
+for branch in "" ptb canary; do
+    url=$(curl -sI "https://discordapp.com/api/download${branch:+/}${branch}?platform=linux&format=tar.gz" | grep -oP 'location: \K\S+')
+    version=${url##https://dl*.discordapp.net/apps/linux/}
+    version=${version%%/*.tar.gz}
+    echo "  ${branch:-stable} = callPackage ./base.nix {"
+    echo "    pname = \"discord${branch:+-}${branch}\";"
+    case $branch in
+        "") suffix="" ;;
+        ptb) suffix="PTB" ;;
+        canary) suffix="Canary" ;;
+    esac
+    echo "    binaryName = \"Discord${suffix}\";"
+    echo "    desktopName = \"Discord${suffix:+ }${suffix}\";"
+    echo "    version = \"${version}\";"
+    echo "    src = fetchurl {"
+    echo "      url = \"${url}\";"
+    echo "      sha256 = \"$(nix-prefetch-url "$url")\";"
+    echo "    };"
+    echo "  };"
+done
+
+echo "}.\${branch}"