char/sorcery
static-files based git repo viewer
git clone https://git.t4t.associates/char/sorcery
6f745f9
main
languages
- Rust 58.7%
- TypeScript 29.0%
- CSS 5.5%
- Zig 4.3%
- Nix 1.0%
- Markdown 1.0%
- TOML 0.4%
- JSON 0.1%
files
| assets/fonts/ | |
| extra/sorcery-ssh/ | |
| src/ | |
| web/ | |
| .gitignore | 140 B |
| Cargo.lock | 68.5 KiB |
| Cargo.toml | 971 B |
| README.md | 3.3 KiB |
| flake.lock | 569 B |
| flake.nix | 3.3 KiB |
| sorcery.ngx.ts | 1.9 KiB |
sorcery
tiny read-only git repo viewer
- point at a dir containing
user/repobare git repos - generates static sites for every repo
- serves via nginx (or other proxy supporting the
X-Accelheaders) - progressively enhances via js to provide dynamic content (commit diffs, tree-at-revision, etc)
- syntax highlighting via arborium (both serverside and clientside)
- supports "git smart HTTP" for read-only clones
pairs well with ssh git for read-write access
usage
compiles to a static executable (linux musl) on the default package in the flake:
nix build
install it as /usr/local/bin/sorceryd or whatever
nginx
production nginx config generated via @char/ngx:
deno run sorcery.ngx.ts> sorcery.conf
systemd
Example /etc/systemd/system/sorceryd.service:
[ Unit ] Description = Sorcery Git forgeAfter = network.target[ Service ] Type = simpleUser = gitGroup = gitRuntimeDirectory = sorceryCacheDirectory = sorceryConfigurationDirectory = sorceryEnvironmentFile = /etc/sorcery/envExecStart = /usr/local/bin/sorcerydRestart = on-failureRestartSec = 2UMask = 0027NoNewPrivileges = truePrivateTmp = trueProtectSystem = strictProtectHome = read-only[ Install ] WantedBy = multi-user.target
With /etc/sorcery/env:
SORCERY_REPOSITORIES =/home/git/publicSORCERY_CACHE =/var/cache/sorcerySORCERY_SOCKET =/run/sorcery/sockSORCERY_INSTANCE_NAME =my-cool-git.exampleSORCERY_CLONE_URL_BASE =https://my-cool-git.exampleSORCERY_REFRESH_TOKEN_FILE =/etc/sorcery/refresh-token
Command-line flags remain available and override the corresponding environment variables.
ssh
sorcery-ssh is an sshd ForceCommand that provides read-write git access.
it auto-creates bare repositories on first push (like sourcehut)
and also provides commands + an optional interactive tui for editing the description of a repo.
nix build .#sorcery-sshnix build .#sorcery-ssh-tui# optional
install sorcery-ssh (and sorcery-ssh-tui), ensure the git user can read /etc/sorcery/refresh-token, and add the following to sshd_config:
Match User git SetEnv SORCERY_REPOSITORIES=/home/git/public SORCERY_SOCKET=/run/sorcery/sock SORCERY_REFRESH_TOKEN_FILE=/etc/sorcery/refresh-token SORCERY_CLONE_URL_BASE=https://my-cool-git.example SORCERY_INSTANCE_NAME=my-cool-git.example SORCERY_SSH_TUI=/usr/local/bin/sorcery-ssh-tui ForceCommand /usr/local/bin/sorcery-ssh
optional: push refresh
since this is a static-files-based viewer, repositories need updating when their state changes.
if you're using sorcery-ssh, repositories will automatically refresh after a git receive-pack.
otherwise, you can use a post-receive hook like so:
#!/usr/bin/env sh repo =$( basename " $ PWD " .git) user =$( basename " $( dirname " $ PWD " ) " ) token =$( cat /etc/sorcery/refresh-token) exec curl-fsS --unix-socket /run/sorcery/sock \-H "Authorization: Bearer $ token " \-X POST"https://my-cool-git.example/-/refresh/ $ user / $ repo "
in any case, sorceryd's scanner will pick changes up eventually, so this is optional
development
cd web&& deno task check&& deno task test&& deno task buildcd ..&& cargo test
since we embed the frontend inside the executable, you must generate the frontend bundle before running a cargo build.