summary refs log tree commit diff
path: root/pkgs/common-updater
diff options
context:
space:
mode:
authorworldofpeace <worldofpeace@protonmail.ch>2020-04-24 19:16:41 -0400
committerGitHub <noreply@github.com>2020-04-24 19:16:41 -0400
commit05d1546060b24fbbd6beff642241980f89f56c9c (patch)
treefad21a7ee60821dc5eddc9991b84d59ce7ee4c5d /pkgs/common-updater
parentcf2e613dc662e1739d93644810b81b773b57808a (diff)
parentb74be134dbdb8baa63051e1d9e75723b8a289ac2 (diff)
downloadnixpkgs-05d1546060b24fbbd6beff642241980f89f56c9c.tar
nixpkgs-05d1546060b24fbbd6beff642241980f89f56c9c.tar.gz
nixpkgs-05d1546060b24fbbd6beff642241980f89f56c9c.tar.bz2
nixpkgs-05d1546060b24fbbd6beff642241980f89f56c9c.tar.lz
nixpkgs-05d1546060b24fbbd6beff642241980f89f56c9c.tar.xz
nixpkgs-05d1546060b24fbbd6beff642241980f89f56c9c.tar.zst
nixpkgs-05d1546060b24fbbd6beff642241980f89f56c9c.zip
Merge pull request #85337 from petabyteboy/feature/mark-broken
common-updater-scripts: add mark-broken script
Diffstat (limited to 'pkgs/common-updater')
-rw-r--r--pkgs/common-updater/scripts.nix4
-rwxr-xr-xpkgs/common-updater/scripts/mark-broken86
2 files changed, 88 insertions, 2 deletions
diff --git a/pkgs/common-updater/scripts.nix b/pkgs/common-updater/scripts.nix
index 655924e5f28..739f44387b3 100644
--- a/pkgs/common-updater/scripts.nix
+++ b/pkgs/common-updater/scripts.nix
@@ -1,4 +1,4 @@
-{ stdenv, makeWrapper, coreutils, gnused, gnugrep, diffutils, nix, git }:
+{ stdenv, makeWrapper, coreutils, gnused, gnugrep, diffutils, nix, git, jq }:
 
 stdenv.mkDerivation {
   name = "common-updater-scripts";
@@ -12,7 +12,7 @@ stdenv.mkDerivation {
     cp ${./scripts}/* $out/bin
 
     for f in $out/bin/*; do
-      wrapProgram $f --prefix PATH : ${stdenv.lib.makeBinPath [ coreutils gnused gnugrep nix diffutils git ]}
+      wrapProgram $f --prefix PATH : ${stdenv.lib.makeBinPath [ coreutils gnused gnugrep nix diffutils git jq ]}
     done
   '';
 }
diff --git a/pkgs/common-updater/scripts/mark-broken b/pkgs/common-updater/scripts/mark-broken
new file mode 100755
index 00000000000..d128d0d458b
--- /dev/null
+++ b/pkgs/common-updater/scripts/mark-broken
@@ -0,0 +1,86 @@
+#!/usr/bin/env bash
+set -e
+
+scriptName=mark-broken # do not use the .wrapped name
+
+die() {
+    echo "$scriptName: error: $1" >&2
+    exit 1
+}
+
+usage() {
+    echo "Usage: $scriptName <attr> [--new-value=<new-value>]"
+}
+
+args=()
+
+for arg in "$@"; do
+    case $arg in
+        --new-value=*)
+            newValue="${arg#*=}"
+        ;;
+        --help)
+            usage
+            exit 0
+        ;;
+        --*)
+            echo "$scriptName: Unknown argument: $arg"
+            usage
+            exit 1
+        ;;
+        *)
+            args["${#args[*]}"]=$arg
+        ;;
+    esac
+done
+
+attr=${args[0]}
+
+if (( "${#args[*]}" < 1 )); then
+    echo "$scriptName: Too few arguments"
+    usage
+    exit 1
+fi
+
+if (( "${#args[*]}" > 1 )); then
+    echo "$scriptName: Too many arguments"
+    usage
+    exit 1
+fi
+
+if [ -z $newValue ]; then
+  newValue="true"
+fi
+
+nixFile=$(nix-instantiate --eval --json -E "with import ./. {}; (builtins.unsafeGetAttrPos \"description\" $attr.meta).file" | jq -r .)
+if [[ ! -f "$nixFile" ]]; then
+    die "Couldn't evaluate 'builtins.unsafeGetAttrPos \"description\" $attr.meta' to locate the .nix file!"
+fi
+
+# Insert broken attribute
+sed -i.bak "$nixFile" -r \
+  -e "/^\s*broken\s*=.*$/d" \
+  -e "s/(\s*)meta\s*=.*\{/&\n\1  broken = $newValue;/"
+
+if cmp -s "$nixFile" "$nixFile.bak"; then
+    mv "$nixFile.bak" "$nixFile"
+    die "Failed to mark the package as broken! Does it have a meta attribute?"
+fi
+
+if [[ "$newValue" == "true" ]]; then
+    # broken should evaluate to true in any case now
+    markedSuccessfully=$(nix-instantiate --eval -E "with import ./. {}; $attr.meta.broken" || true)
+    if [[ ! "$markedSuccessfully" == "true" ]]; then
+        mv "$nixFile.bak" "$nixFile"
+        die "Couldn't verify the broken attribute to be set correctly, restoring backup!"
+    fi
+else
+    # we can not check if broken evaluates to the correct value, but we can check that it does evaluate
+    if ! nix-instantiate --eval -E "with import ./. {}; $attr.meta.broken" >/dev/null; then
+        mv "$nixFile.bak" "$nixFile"
+        die "Couldn't verify the broken attribute to be set correctly, restoring backup!"
+    fi
+fi
+
+rm -f "$nixFile.bak"
+rm -f "$attr.fetchlog"