From 6c0583557406de86192d2c80d34a7a0dd2762c87 Mon Sep 17 00:00:00 2001
From: Freya Murphy <freya@freyacat.org>
Date: Thu, 12 Dec 2024 22:53:10 -0500
Subject: [PATCH] add guix installer workflow

---
 .forgejo/workflows/installer.yaml | 57 +++++++++++++++++++++++++++++++
 scripts/build-installer           |  2 +-
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 .forgejo/workflows/installer.yaml

diff --git a/.forgejo/workflows/installer.yaml b/.forgejo/workflows/installer.yaml
new file mode 100644
index 0000000..1e481b7
--- /dev/null
+++ b/.forgejo/workflows/installer.yaml
@@ -0,0 +1,57 @@
+# title: install
+# desc: generate a guix installer image
+# adapted from https://github.com/SystemCrafters/guix-installer/
+
+name: installer
+
+on:
+  push:
+    branches:
+      - main
+
+jobs:
+  build:
+    runs-on: docker
+
+    container:
+      image: alpine:3.21
+      options: "--cap-add=SYS_ADMIN" # needed for guix time-machine
+
+    steps:
+      - name: Install dependencies
+        run: |
+          apk add --no-cache git nodejs
+
+      - name: Git checkout
+        uses: actions/checkout@v4
+
+      - name: Guix cache
+        uses: actions/cache@v4
+        with:
+          path: ~/.cache/guix
+          key: guix-cache-${{ github.sha }}
+          restore-keys: |
+            guix-cache
+
+      - name: Install guix
+        run: |
+          apk add --no-cache guix openrc
+
+          cat <<EOF > /etc/init.d/guix-daemon
+          #!/sbin/openrc-run
+          start(){ guix-daemon --build-users-group=guixbuild & }
+          EOF
+          chmod +x /etc/init.d/guix-daemon
+
+          rc-update add guix-daemon
+          openrc boot
+
+      - name: Build ISO
+        run: |
+          ./scripts/build-installer
+
+      - name: Save artifact
+        uses: actions/upload-artifact@v4
+        with:
+          name: installer
+          path: guix-installer-*.iso
diff --git a/scripts/build-installer b/scripts/build-installer
index 10cd84c..05d03da 100755
--- a/scripts/build-installer
+++ b/scripts/build-installer
@@ -3,7 +3,7 @@ retry="$(dirname $0)/guix-retry"
 repo="$(realpath "$(dirname $0)/..")"
 extra_args=""
 
-if [ ! -d /gnu/store ]; then
+if [ -f /usr/local/bin ]; then
 # we are likely in a non guix system
 # just for building the installer
 # make sure to authorize the substitute