about summary refs log tree commit diff
path: root/pkgs/shells
diff options
context:
space:
mode:
author1adept2024-08-21 12:10:50 +0200
committer1adept2024-08-21 17:28:14 +0200
commit99ac52261a5737cfda5cd6227ee15a0cd1b3330e (patch)
tree78d791081592ab5faad021ed1ca66881d11042a9 /pkgs/shells
parent2ccb979f80caf1c1dccada46d549e7db83cf072d (diff)
nushell: update script
script to update nushell using `nix-update`

Then to update each plugin
- build the plugin as-is
- replacing the hash with the new one from the failed build
- building again

All updated files will be added in git and commited

The resulting commit is checked with `nixpkgs-review`
Diffstat (limited to 'pkgs/shells')
-rw-r--r--pkgs/shells/nushell/update.sh70
1 files changed, 70 insertions, 0 deletions
diff --git a/pkgs/shells/nushell/update.sh b/pkgs/shells/nushell/update.sh
new file mode 100644
index 000000000000..9a8015e74600
--- /dev/null
+++ b/pkgs/shells/nushell/update.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash
+#!nix-shell -p git nix-update nixpkgs-review nixfmt-rfc-style
+
+set -euxo pipefail
+
+basedir="$(git rev-parse --show-toplevel)"
+cd "$basedir"
+
+branch="update-nushell"
+nuPath="pkgs/shells/nushell"
+
+function staged() {
+    if git status --porcelain | grep -q -E "^[AM].? +$1"; then
+        return 0
+    else
+        return 1
+    fi
+}
+
+function version() {
+    grep '\s*version = ' "$nuPath/default.nix" | cut -d'"' -f 2 | head --lines 1
+}
+
+git checkout -B "$branch"
+
+version_old=$(version)
+if ! staged "$nuPath/default.nix"; then
+    nix-update nushell
+    git add "$nuPath/default.nix"
+fi
+version_new=$(version)
+
+declare -a plugins=(formats query polars gstat)
+for plugin in "${plugins[@]}"; do
+    attr="nushellPlugins.$plugin"
+    pluginPath="$nuPath/plugins/$plugin.nix"
+
+    if staged "$pluginPath"; then
+        echo "Skipping '$plugin' because it's alredy staged"
+        continue
+    fi
+
+    echo "Attempting to build $attr"
+
+    set +e
+    newHash=$(nix build ".#$attr" 2> \
+        >(grep got |
+            awk -F' ' '{ print $2 }'))
+    set -e
+
+    # New hash ?
+    if [ -n "$newHash" ]; then
+        # Add the new hash
+        sed -i "s!cargoHash = ".*";!cargoHash = \"$newHash\";!" "$pluginPath"
+        nixfmt "$pluginPath"
+
+        echo "Building $plugin again with new hash $newHash"
+        nix build ".#$attr"
+        git add "$pluginPath"
+        echo "Plugin $plugin built sucessfully"
+    else
+        echo "No new hash for '$plugin'"
+    fi
+done
+
+git commit -m "nushell: $version_old -> $version_new"
+
+echo "Starting nixpkgs-review"
+nixpkgs-review rev "$branch"