Skip to content

Commit 63089c1

Browse files
amcli for Nix and the AUR (#2207)
The repository is a flake that installs the latest release's build of amcli on x86-64, ARM64 and ARMv7 Linux: nix run github:asc-community/AngouriMath -- simp "x + x". It fetches the release's self-contained archive, whose version and SHA-256 are in Sources/Terminal/AngouriMath.Terminal/packaging/release.json, patches it for the store, and wraps it with the ICU and OpenSSL the runtime opens by name. It is not stripped: the assemblies are executable in the archive, and strip rewrites a PE file it is given. render-pkgbuild.sh writes the PKGBUILD of the AUR's amcli-bin for a release, from the same archives, with the man page, the completion script and the licence fetched from the tag. The Terminal release workflow renders both after the build, in a job that can only read, and on a release publishes them in one that runs no code from the repository: release.json goes to master by a pull request, and the PKGBUILD is pushed to the AUR where the repository has the AUR_SSH_KEY secret, against the AUR's published host key. Part of #1660 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent f950af8 commit 63089c1

6 files changed

Lines changed: 275 additions & 2 deletions

File tree

‎.github/workflows/TerminalNightly.yml‎

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ name: 'Terminal release'
44
# attached to each release of the packages, whose version they carry, read from the release's
55
# tag as Nuget.yml reads it. Run by hand, it builds and packs without attaching anything unless
66
# asked to, and a pull request that touches the workflow or its scripts builds and packs the
7-
# same way. Only the job that attaches the builds can write to the repository, and it runs no
8-
# code from it.
7+
# same way. Only the jobs that attach the builds and publish the packages can write, and they run
8+
# no code from the repository.
99
# https://github.com/asc-community/AngouriMath/issues/539
10+
# The AUR's amcli-bin and the Nix flake's release.json are rendered from the same archives, and
11+
# published with the release. https://github.com/asc-community/AngouriMath/issues/1660
1012
on:
1113
release:
1214
types: [published]
@@ -17,6 +19,7 @@ on:
1719
- 'Sources/Terminal/AngouriMath.Terminal/pack-deb-linux.sh'
1820
- 'Sources/Terminal/AngouriMath.Terminal/amcli.1'
1921
- 'Sources/Terminal/AngouriMath.Terminal/amcli.bash'
22+
- 'Sources/Terminal/AngouriMath.Terminal/packaging/**'
2023
workflow_dispatch:
2124
inputs:
2225
version:
@@ -34,6 +37,7 @@ jobs:
3437
permissions:
3538
contents: read
3639
outputs:
40+
version: ${{ steps.version.outputs.version }}
3741
tag: ${{ steps.version.outputs.tag }}
3842

3943
steps:
@@ -129,3 +133,113 @@ jobs:
129133
'angourimath-terminal-arm64.deb' \
130134
-R "$GITHUB_REPOSITORY" \
131135
--clobber
136+
137+
# The PKGBUILD for the AUR's amcli-bin, its .SRCINFO, and the release.json the Nix flake reads,
138+
# from the archives the build made. Rendered on every run, so that a pull request that touches
139+
# them shows they still render, and published only with a release.
140+
TerminalPackagesRender:
141+
needs: TerminalBuild
142+
runs-on: ubuntu-latest
143+
permissions:
144+
contents: read
145+
146+
steps:
147+
- uses: actions/checkout@v6
148+
with:
149+
fetch-depth: 0
150+
151+
- uses: actions/download-artifact@v4
152+
with:
153+
name: angourimath-terminal
154+
path: archives
155+
156+
# The tag's own files where there is a tag; for a pull request or a run by hand, the commit
157+
# being built.
158+
- name: 'Render'
159+
env:
160+
VERSION: ${{ needs.TerminalBuild.outputs.version }}
161+
TAG: ${{ needs.TerminalBuild.outputs.tag }}
162+
run: |
163+
sum() { sha256sum "archives/angourimath-terminal-$1.zip" | cut -d' ' -f1; }
164+
if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null; then ref="$TAG"; else ref=HEAD; fi
165+
mkdir -p packages
166+
PACKAGING_REF="$ref" Sources/Terminal/AngouriMath.Terminal/packaging/render-pkgbuild.sh \
167+
"$VERSION" "$(sum linux-x64)" "$(sum linux-arm64)" "$(sum linux-arm)" > packages/PKGBUILD
168+
printf '{\n "version": "%s",\n "sha256": {\n "linux-x64": "%s",\n "linux-arm64": "%s",\n "linux-arm": "%s"\n }\n}\n' \
169+
"$VERSION" "$(sum linux-x64)" "$(sum linux-arm64)" "$(sum linux-arm)" > packages/release.json
170+
cat packages/PKGBUILD packages/release.json
171+
172+
# makepkg will not run as root, and an Arch container is the only place it is.
173+
- name: '.SRCINFO'
174+
run: |
175+
docker run --rm -v "$PWD/packages:/packages" archlinux:base-devel bash -c \
176+
'useradd -m builder && cp /packages/PKGBUILD /home/builder/ && cd /home/builder && su builder -c "makepkg --printsrcinfo" > /packages/.SRCINFO'
177+
cat packages/.SRCINFO
178+
179+
- name: 'Keep the packages'
180+
uses: actions/upload-artifact@v4
181+
with:
182+
name: amcli-packages
183+
retention-days: 7
184+
include-hidden-files: true
185+
path: packages
186+
187+
# The PKGBUILD is pushed to the AUR where the repository has the AUR_SSH_KEY secret, the private
188+
# key of the AUR account that owns amcli-bin; without it nothing is pushed. release.json goes to
189+
# master by a pull request, which is what moves the flake to the release.
190+
TerminalPackagesPublish:
191+
needs: [TerminalBuild, TerminalRelease, TerminalPackagesRender]
192+
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.release)
193+
runs-on: ubuntu-latest
194+
permissions:
195+
contents: write
196+
pull-requests: write
197+
198+
steps:
199+
- uses: actions/checkout@v6
200+
with:
201+
ref: ${{ github.event.repository.default_branch }}
202+
203+
- uses: actions/download-artifact@v4
204+
with:
205+
name: amcli-packages
206+
path: packages
207+
208+
- name: 'The flake follows the release'
209+
env:
210+
GH_TOKEN: ${{ github.token }}
211+
VERSION: ${{ needs.TerminalBuild.outputs.version }}
212+
run: |
213+
branch="amcli-release-$VERSION"
214+
cp packages/release.json Sources/Terminal/AngouriMath.Terminal/packaging/release.json
215+
if git diff --quiet; then echo "release.json already names $VERSION"; exit 0; fi
216+
git config user.name 'github-actions[bot]'
217+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
218+
git switch -c "$branch"
219+
git commit -am "The Nix flake installs amcli $VERSION"
220+
git push --force origin "$branch"
221+
gh pr create --base "${{ github.event.repository.default_branch }}" --head "$branch" \
222+
--title "The Nix flake installs amcli $VERSION" \
223+
--body "release.json for the $VERSION archives, rendered by the Terminal release workflow (#1660)."
224+
225+
- name: 'The AUR follows the release'
226+
env:
227+
AUR_SSH_KEY: ${{ secrets.AUR_SSH_KEY }}
228+
VERSION: ${{ needs.TerminalBuild.outputs.version }}
229+
run: |
230+
if [ -z "$AUR_SSH_KEY" ]; then echo 'No AUR_SSH_KEY secret: amcli-bin is not pushed.'; exit 0; fi
231+
install -d -m 700 ~/.ssh
232+
printf '%s\n' "$AUR_SSH_KEY" > ~/.ssh/aur && chmod 600 ~/.ssh/aur
233+
# The host key the AUR publishes on https://aur.archlinux.org, and no other.
234+
ssh-keyscan -t ed25519 aur.archlinux.org > aur.key 2> /dev/null
235+
[ "$(ssh-keygen -lf aur.key | cut -d' ' -f2)" = 'SHA256:RFzBCUItH9LZS0cKB5UE6ceAYhBD5C8GeOBip8Z11+4' ] \
236+
|| { echo 'aur.archlinux.org did not present its published Ed25519 key'; exit 1; }
237+
cat aur.key >> ~/.ssh/known_hosts
238+
export GIT_SSH_COMMAND='ssh -i ~/.ssh/aur -o IdentitiesOnly=yes'
239+
git clone ssh://aur@aur.archlinux.org/amcli-bin.git aur
240+
cp packages/PKGBUILD packages/.SRCINFO aur/
241+
cd aur
242+
git config user.name 'github-actions[bot]'
243+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
244+
git add PKGBUILD .SRCINFO
245+
git diff --cached --quiet || { git commit -m "amcli $VERSION"; git push origin HEAD:master; }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version": "2.6.0",
3+
"sha256": {
4+
"linux-x64": "61998c4f322f1f8adfed8fa4324dd382c822ca6c30c2c49165bcbae95d36f9da",
5+
"linux-arm64": "b8e5ffe84d011c41f1c89002855c40f593d0f7f0cd7ba945fbf7ff215aea1a26",
6+
"linux-arm": "d4fcf4bb69df3f5f531046ca4fddaf9285f2b22a0efe412d8a498747a456087b"
7+
}
8+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# Writes the AUR's amcli-bin PKGBUILD for a release to standard output, from the release's version
3+
# and the SHA-256 of its three Linux archives. The man page, the completion script and the licence
4+
# are fetched from the tag, so they are hashed as the tag has them: PACKAGING_REF names it, v2.6.0
5+
# for 2.6.0, and is the release's tag where the workflow runs this.
6+
# https://github.com/asc-community/AngouriMath/issues/1660
7+
set -euo pipefail
8+
version="${1:?usage: render-pkgbuild.sh VERSION SHA256_LINUX_X64 SHA256_LINUX_ARM64 SHA256_LINUX_ARM}"
9+
x64="${2:?}"; arm64="${3:?}"; arm="${4:?}"
10+
ref="${PACKAGING_REF:-v$version}"
11+
sum() { git show "$ref:$1" | sha256sum | cut -d' ' -f1; }
12+
# A pkgver has no hyphen: 2.7.0-beta.1 is packed as 2.7.0_beta.1, from the tag v2.7.0-beta.1.
13+
cat <<PKGBUILD
14+
# Generated by Sources/Terminal/AngouriMath.Terminal/packaging/render-pkgbuild.sh in
15+
# https://github.com/asc-community/AngouriMath for each release.
16+
pkgname=amcli-bin
17+
pkgver=${version//-/_}
18+
pkgrel=1
19+
pkgdesc="AngouriMath's terminal and command-line computer algebra system"
20+
arch=('x86_64' 'aarch64' 'armv7h')
21+
url="https://am.angouri.org"
22+
license=('MIT')
23+
depends=('icu' 'zlib' 'openssl' 'krb5' 'gcc-libs')
24+
provides=('amcli')
25+
conflicts=('amcli')
26+
options=('!strip' '!debug')
27+
_tag="v${version}"
28+
_release="https://github.com/asc-community/AngouriMath/releases/download/\${_tag}"
29+
_raw="https://raw.githubusercontent.com/asc-community/AngouriMath/\${_tag}"
30+
source=("amcli-\${_tag}.1::\${_raw}/Sources/Terminal/AngouriMath.Terminal/amcli.1"
31+
"amcli-\${_tag}.bash::\${_raw}/Sources/Terminal/AngouriMath.Terminal/amcli.bash"
32+
"LICENSE-\${_tag}.md::\${_raw}/LICENSE.md")
33+
source_x86_64=("angourimath-terminal-linux-x64-\${_tag}.zip::\${_release}/angourimath-terminal-linux-x64.zip")
34+
source_aarch64=("angourimath-terminal-linux-arm64-\${_tag}.zip::\${_release}/angourimath-terminal-linux-arm64.zip")
35+
source_armv7h=("angourimath-terminal-linux-arm-\${_tag}.zip::\${_release}/angourimath-terminal-linux-arm.zip")
36+
sha256sums=('$(sum Sources/Terminal/AngouriMath.Terminal/amcli.1)'
37+
'$(sum Sources/Terminal/AngouriMath.Terminal/amcli.bash)'
38+
'$(sum LICENSE.md)')
39+
sha256sums_x86_64=('${x64}')
40+
sha256sums_aarch64=('${arm64}')
41+
sha256sums_armv7h=('${arm}')
42+
43+
package() {
44+
case "\$CARCH" in
45+
x86_64) _runtime=linux-x64 ;;
46+
aarch64) _runtime=linux-arm64 ;;
47+
armv7h) _runtime=linux-arm ;;
48+
esac
49+
install -d "\$pkgdir/opt/amcli" "\$pkgdir/usr/bin"
50+
cp -r "\$srcdir/\$_runtime/." "\$pkgdir/opt/amcli/"
51+
# The runtime's tracing provider wants LTTng, which nothing here uses.
52+
rm -f "\$pkgdir/opt/amcli/libcoreclrtraceptprovider.so"
53+
ln -s /opt/amcli/AngouriMath.Terminal "\$pkgdir/usr/bin/amcli"
54+
install -Dm644 "amcli-\${_tag}.1" "\$pkgdir/usr/share/man/man1/amcli.1"
55+
install -Dm644 "amcli-\${_tag}.bash" "\$pkgdir/usr/share/bash-completion/completions/amcli"
56+
install -Dm644 "LICENSE-\${_tag}.md" "\$pkgdir/usr/share/licenses/\$pkgname/LICENSE.md"
57+
}
58+
PKGBUILD

‎Sources/Terminal/readme.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ To uninstall it, run
2727
dotnet tool uninstall --global AngouriMath.Terminal
2828
```
2929

30+
### With Nix
31+
32+
The repository is a flake that installs the latest release's build, on x86-64, ARM64 and ARMv7 Linux:
33+
```
34+
nix run github:asc-community/AngouriMath -- simp "x + x"
35+
nix profile install github:asc-community/AngouriMath
36+
```
37+
3038
## One command, from a script
3139

3240
With a command after it, `amcli` answers once and exits, without opening the terminal or starting

‎flake.lock‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# amcli, the AngouriMath terminal, as the release built it: `nix run github:asc-community/AngouriMath`.
2+
# The version and the archives' hashes are in Sources/Terminal/AngouriMath.Terminal/packaging/release.json,
3+
# which the Terminal release workflow updates after each release.
4+
# https://github.com/asc-community/AngouriMath/issues/1660
5+
{
6+
description = "amcli, the AngouriMath terminal and command-line calculator";
7+
8+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
9+
10+
outputs = { self, nixpkgs }:
11+
let
12+
release = builtins.fromJSON (builtins.readFile ./Sources/Terminal/AngouriMath.Terminal/packaging/release.json);
13+
runtimes = { x86_64-linux = "linux-x64"; aarch64-linux = "linux-arm64"; armv7l-linux = "linux-arm"; };
14+
forEachSystem = f: nixpkgs.lib.genAttrs (builtins.attrNames runtimes)
15+
(system: f nixpkgs.legacyPackages.${system} runtimes.${system});
16+
in
17+
{
18+
packages = forEachSystem (pkgs: runtime: rec {
19+
amcli = pkgs.stdenv.mkDerivation {
20+
pname = "amcli";
21+
inherit (release) version;
22+
src = pkgs.fetchurl {
23+
url = "https://github.com/asc-community/AngouriMath/releases/download/v${release.version}/angourimath-terminal-${runtime}.zip";
24+
sha256 = release.sha256.${runtime};
25+
};
26+
sourceRoot = runtime;
27+
nativeBuildInputs = [ pkgs.unzip pkgs.autoPatchelfHook pkgs.makeWrapper pkgs.installShellFiles ];
28+
buildInputs = [ pkgs.stdenv.cc.cc.lib pkgs.zlib pkgs.icu pkgs.openssl pkgs.krb5 ];
29+
# The runtime's tracing provider wants LTTng, which nothing here uses.
30+
postPatch = "rm -f libcoreclrtraceptprovider.so";
31+
dontBuild = true;
32+
# The assemblies are executable in the archive, and strip rewrites a PE file it is given:
33+
# a stripped System.Private.CoreLib.dll is a bad image to the runtime.
34+
dontStrip = true;
35+
installPhase = ''
36+
runHook preInstall
37+
mkdir -p $out/lib/amcli
38+
cp -r . $out/lib/amcli
39+
# .NET opens ICU and OpenSSL by name at run time, which autoPatchelf does not see.
40+
makeWrapper $out/lib/amcli/AngouriMath.Terminal $out/bin/amcli \
41+
--prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath [ pkgs.icu pkgs.openssl pkgs.zlib pkgs.krb5 ]}
42+
installManPage ${./Sources/Terminal/AngouriMath.Terminal/amcli.1}
43+
installShellCompletion --bash --name amcli ${./Sources/Terminal/AngouriMath.Terminal/amcli.bash}
44+
runHook postInstall
45+
'';
46+
meta = {
47+
description = "AngouriMath's terminal and command-line computer algebra system";
48+
homepage = "https://am.angouri.org";
49+
license = pkgs.lib.licenses.mit;
50+
sourceProvenance = [ pkgs.lib.sourceTypes.binaryNativeCode pkgs.lib.sourceTypes.binaryBytecode ];
51+
platforms = builtins.attrNames runtimes;
52+
mainProgram = "amcli";
53+
};
54+
};
55+
default = amcli;
56+
});
57+
};
58+
}

0 commit comments

Comments
 (0)