summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-12-12 22:53:10 -0500
committerFreya Murphy <freya@freyacat.org>2024-12-19 23:37:47 -0500
commit55de09d9095b8f14239b778bb1eda7cdde95d9f0 (patch)
tree6c6128e70dff5902eb62c67d82bf2eb089a2f492 /scripts
parentfix build-installer on posix shell (diff)
downloaddotfiles-guix-55de09d9095b8f14239b778bb1eda7cdde95d9f0.tar.gz
dotfiles-guix-55de09d9095b8f14239b778bb1eda7cdde95d9f0.tar.bz2
dotfiles-guix-55de09d9095b8f14239b778bb1eda7cdde95d9f0.zip
add guix installer workflow
Diffstat (limited to '')
-rwxr-xr-xscripts/build-installer24
-rwxr-xr-xscripts/guix-retry76
2 files changed, 66 insertions, 34 deletions
diff --git a/scripts/build-installer b/scripts/build-installer
index 10cd84c..1293315 100755
--- a/scripts/build-installer
+++ b/scripts/build-installer
@@ -1,28 +1,8 @@
#!/bin/sh
+set -e -o pipefail
retry="$(dirname $0)/guix-retry"
repo="$(realpath "$(dirname $0)/..")"
-extra_args=""
-
-if [ ! -d /gnu/store ]; then
-# we are likely in a non guix system
-# just for building the installer
-# make sure to authorize the substitute
-# servers for nonguix and sakura
-guix archive --authorize < "$repo/files/keys/nonguix.pub"
-guix archive --authorize < "$repo/files/keys/sakura.pub"
-substitutes=$(
-(cat <<EOF
-https://substitutes.nonguix.org
-https://substitutes.freya.cat
-https://bordeaux.guix.gnu.org
-https://ci.guix.gnu.org
-EOF
-) | tr '\n' ' ')
-extra_args="--substitute-urls=\"$substitutes\""
-fi
-
-command="\"$retry\" guix time-machine -C \"$repo/channels.scm\" $extra_args -- system -L \"$repo/modules\" image -t iso9660 \"$repo/systems/installer.scm\""
+command="\"$retry\" guix system -L \"$repo/modules\" image -t iso9660 \"$repo/systems/installer.scm\""
image=$(sh -c "$command")
-
date="$(date -Iseconds)"
cp $image "guix-installer-$date.iso"
diff --git a/scripts/guix-retry b/scripts/guix-retry
index c504048..6fe4da4 100755
--- a/scripts/guix-retry
+++ b/scripts/guix-retry
@@ -1,21 +1,73 @@
#!/bin/sh
-error="write_to_session_record_port"
+# fail on errors
+set -e
-# create redirection
-# file descripters
-exec 11>&1 # stdout
-exec 22>&2 # stderr
+# if the error output matches this regex, auto retry
+# and dont prompt user.
+auto_retry_regex="write_to_session_record_port" # Guix does not know how to
+ # gracefully reconnect TLS...
+# run dir
+run="${XDG_RUNTIME_DIR:-/tmp}/guix-retry/$$"
+mkdir -p "$run"
+# delete run dir on exit
+function cleanup {
+ real="$(realpath "$run")"
+ if [[ ! "$real" = "/" ]]; then
+ rm -fr "$real"
+ fi
+}
+
+trap cleanup EXIT
+
+# get error stream
+stderr="$run/stderr"
+mkfifo -m 600 "$stderr"
+
+log="$run/log"
+
+# unset fail on errors
+set +e
+
+# retry command forever
+# until success or abort
while true; do
- # send stdout to stdout
- # send stderr though pipe
- output=$("$@" 2>&1 1>&11 | tee >(cat - >&22)) # return stderr to
- # normal stderr as well
- # check if error is in stderr
- if echo "$output" | grep -q "$error"; then
+ # execute command
+ if [[ ! -z "$GUIX_RETRY_NO_TTY" ]]; then
+ "$@" 2>"$stderr" &
+ else
+ command="$@"
+ script -q -c "$command" 2>"$stderr" "$log" &
+ fi
+ pid="$!"
+ output="$(cat "$stderr" | tee /dev/stderr)"
+ wait "$pid"
+ err="$?"
+ if [[ -z "$GUIX_RETRY_NO_TTY" ]]; then
+ err="$(tail -n1 "$log" | awk -F '"' '{ print $2 }')"
+ fi
+
+ if [[ "$err" -eq 0 ]]; then
+ # command succeeded, break loop
+ break
+ fi
+
+ if [[ "$output" =~ "$auto_retry_regex" ]]; then
+ # command errored and is set to auto retry
continue
fi
- break
+
+ if [[ ! -z "$GUIX_RETRY_NO_PROMPT" ]]; then
+ # do not prompt, just fail
+ exit 1
+ fi
+
+ # check if user wants to retry
+ read -p "Command failed. Retry? (y/N): " response
+ if [[ ! "$response" = "y" ]]; then
+ # command failed and told to abort, break loop
+ exit 1
+ fi
done