From cdde640978b59004fb5ad91a66ba95a4ae52d770 Mon Sep 17 00:00:00 2001 From: Artturi Date: Sat, 22 Oct 2022 21:50:39 +0300 Subject: discord: add a script to disable breaking updates (#197248) --- .../discord/disable-breaking-updates.py | 42 +++++++++++++++++++++ .../instant-messengers/discord/linux.nix | 44 +++++++++++++++------- 2 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 pkgs/applications/networking/instant-messengers/discord/disable-breaking-updates.py diff --git a/pkgs/applications/networking/instant-messengers/discord/disable-breaking-updates.py b/pkgs/applications/networking/instant-messengers/discord/disable-breaking-updates.py new file mode 100644 index 00000000000..a7217d0ad6e --- /dev/null +++ b/pkgs/applications/networking/instant-messengers/discord/disable-breaking-updates.py @@ -0,0 +1,42 @@ +#!@pythonInterpreter@ +# slightly tweaked from the script created by @lionirdeadman +# https://github.com/flathub/com.discordapp.Discord/blob/master/disable-breaking-updates.py +""" +Disable breaking updates which will prompt users to download a deb or tar file +and lock them out of Discord making the program unusable. + +This will dramatically improve the experience : + + 1) The maintainer doesn't need to be worried at all times of an update which will break Discord. + 2) People will not be locked out of the program while the maintainer runs to update it. + +""" + +import json +import os +from pathlib import Path + +XDG_CONFIG_HOME = os.environ.get("XDG_CONFIG_HOME") or os.path.join( + os.path.expanduser("~"), ".config" +) + +settings_path = Path(f"{XDG_CONFIG_HOME}/@configDirName@/settings.json") +settings_path_temp = Path(f"{XDG_CONFIG_HOME}/@configDirName@/settings.json.tmp") +try: + with settings_path.open(encoding="utf-8") as settings_file: + settings = json.load(settings_file) + + if settings.get("SKIP_HOST_UPDATE"): + print("[Nix] Disabling updates already done") + else: + skip_host_update = {"SKIP_HOST_UPDATE": True} + settings.update(skip_host_update) + + with settings_path_temp.open("w", encoding="utf-8") as settings_file_temp: + json.dump(settings, settings_file_temp, indent=2) + + settings_path_temp.rename(settings_path) + print("[Nix] Disabled updates") + +except IOError: + print("[Nix] settings.json doesn't yet exist, can't disable it yet") diff --git a/pkgs/applications/networking/instant-messengers/discord/linux.nix b/pkgs/applications/networking/instant-messengers/discord/linux.nix index ec34959a290..9ac36b66ff8 100644 --- a/pkgs/applications/networking/instant-messengers/discord/linux.nix +++ b/pkgs/applications/networking/instant-messengers/discord/linux.nix @@ -4,9 +4,22 @@ , glib, gtk3, libcxx, libdrm, libnotify, libpulseaudio, libuuid, libX11 , libXScrnSaver, libXcomposite, libXcursor, libXdamage, libXext, libXfixes , libXi, libXrandr, libXrender, libXtst, libxcb, libxshmfence, mesa, nspr, nss -, pango, systemd, libappindicator-gtk3, libdbusmenu, writeScript +, pango, systemd, libappindicator-gtk3, libdbusmenu, writeScript, python3, runCommand , common-updater-scripts, withOpenASAR ? false }: +let + disableBreakingUpdates = runCommand "disable-breaking-updates.py" + { + pythonInterpreter = "${python3.interpreter}"; + configDirName = lib.toLower binaryName; + } '' + mkdir -p $out/bin + cp ${./disable-breaking-updates.py} $out/bin/disable-breaking-updates.py + substituteAllInPlace $out/bin/disable-breaking-updates.py + chmod +x $out/bin/disable-breaking-updates.py + ''; +in + stdenv.mkDerivation rec { inherit pname version src meta; @@ -85,7 +98,8 @@ stdenv.mkDerivation rec { "''${gappsWrapperArgs[@]}" \ --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \ --prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \ - --prefix LD_LIBRARY_PATH : ${libPath}:$out/opt/${binaryName} + --prefix LD_LIBRARY_PATH : ${libPath}:$out/opt/${binaryName} \ + --run "${lib.getExe disableBreakingUpdates}" ln -s $out/opt/${binaryName}/${binaryName} $out/bin/ # Without || true the install would fail on case-insensitive filesystems @@ -115,15 +129,19 @@ stdenv.mkDerivation rec { mimeTypes = [ "x-scheme-handler/discord" ]; }; - passthru.updateScript = writeScript "discord-update-script" '' - #!/usr/bin/env nix-shell - #!nix-shell -i bash -p curl gnugrep common-updater-scripts - set -eou pipefail; - url=$(curl -sI "https://discordapp.com/api/download/${ - builtins.replaceStrings [ "discord-" "discord" ] [ "" "stable" ] pname - }?platform=linux&format=tar.gz" | grep -oP 'location: \K\S+') - version=''${url##https://dl*.discordapp.net/apps/linux/} - version=''${version%%/*.tar.gz} - update-source-version ${pname} "$version" --file=./pkgs/applications/networking/instant-messengers/discord/default.nix - ''; + passthru = { + # make it possible to run disableBreakingUpdates standalone + inherit disableBreakingUpdates; + updateScript = writeScript "discord-update-script" '' + #!/usr/bin/env nix-shell + #!nix-shell -i bash -p curl gnugrep common-updater-scripts + set -eou pipefail; + url=$(curl -sI "https://discordapp.com/api/download/${ + builtins.replaceStrings [ "discord-" "discord" ] [ "" "stable" ] pname + }?platform=linux&format=tar.gz" | grep -oP 'location: \K\S+') + version=''${url##https://dl*.discordapp.net/apps/linux/} + version=''${version%%/*.tar.gz} + update-source-version ${pname} "$version" --file=./pkgs/applications/networking/instant-messengers/discord/default.nix + ''; + }; } -- cgit 1.4.1