snac2nex/README.md
2025-07-05 23:26:14 +03:00

143 lines
No EOL
4.9 KiB
Markdown

# snac2nex
[![Dependencies](https://deps.rs/repo/codeberg/postscriptum/snac2nex/status.svg)](https://deps.rs/repo/codeberg/postscriptum/snac2nex)
[![crates.io](https://img.shields.io/crates/v/snac2nex.svg)](https://crates.io/crates/snac2nex)
Convert [Snac](https://codeberg.org/grunfink/snac2) profiles to the [Nex](https://nightfall.city/nex/info/specification.txt) blog format.
Useful as a mirroring tool for an existing fediverse instance or for migrating the data once.
## Install
``` bash
cargo install snac2nex
```
## Usage
``` bash
snac2nex -s /path/to/snac/storage -t /path/to/nex -u user1 -u user2
```
### Options
``` bash
-s, --source <SOURCE>
Path to the Snac2 profile directory
-t, --target <TARGET>
Target directory for public data export
-u, --user <USER>
Username(s) to export
-a, --attachment <ATTACHMENT>
Include attachment files export
Supported values:
* `c` (`copy`) - copy files
* `h` (`hard`) - create hard links
* `s` (`soft`) - create soft links (macos, linux, windows only)
-r, --rotate <ROTATE>
Keep running as the daemon, renew every `n` seconds
-f, --format-content <FORMAT_CONTENT>
Post template pattern
[default: {content}{attachments}{link}{tags}{updated}]
--format-filename <FORMAT_FILENAME>
Post filenames format
* append trailing slash to parse documents as the directory
* append `.gmi` or `.gemtext` extension to format documents as Gemtext
* escape with `%%` when using in `systemd` context
* be careful when removing the seconds part, as it may cause overwrite collisions!
[default: %H-%M-%S]
--format-updated <FORMAT_UPDATED>
Post `{updated}` time format
* escaped with `%%`
[default: "%Y/%m/%d %H:%M:%S"]
--filesystem-sync-time
Sync file meta with Snac entry time (e.g. time modified)
--filesystem-dir-permissions <FILESYSTEM_DIR_PERMISSIONS>
Set new directory permissions (macos, linux only)
--filesystem-file-permissions <FILESYSTEM_FILE_PERMISSIONS>
Set new file permissions (macos, linux only)
-k, --keep
Keep Nex entry on Snac post was removed
-d, --daemon
Disables some debug output
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
```
### Systemd
To use `snac2nex` as the `systemd` service, install binary to the canonical system location:
* `git clone https://codeberg.org/postscriptum/snac2nex.git && cd snac2nex`
* `cargo build --release`
* `sudo install target/release/snac2nex /usr/local/bin/snac2nex`
* tip: now you may want to clean the `snac2nex` sources folder to free up disk space
Setup shared access permissions:
1. `useradd -m snac2nex` - create new user with home dir (for log files)
2. `usermod -aG snac snac2nex` - replace `snac` with the `systemd` group for your [Snac](https://codeberg.org/grunfink/snac2) server
* `chmod -R g+r /path/to/snac/storage` - give the group read permissions to Snac directories
3. `usermod -aG nexy snac2nex` - replace `nexy` with the `systemd` group for your your Nex protocol server (e.g. [Nexy](https://github.com/YGGverse/nexy))
* `chmod -R g+rw /path/to/nex` - give the group read/write permissions to Nex directories
Create new `systemd` configuration file `/etc/systemd/system/snac2nex.service`:
``` snac2nex.service
[Unit]
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=snac2nex
Group=snac2nex
# Uncomment if your Snac or Nex unit has ExecStartPre timeout option
# ExecStartPre=/bin/sleep 15
ExecStart=/usr/local/bin/snac2nex -s /path/to/snac/storage -t /path/to/nex -u user1 -u user2 -r 3600 -d
StandardOutput=file:/home/snac2nex/debug.log
StandardError=file:/home/snac2nex/error.log
[Install]
WantedBy=multi-user.target
```
* replace `ExecStart` arguments with your values, where:
* `-s` - Snac `storage` location
* `-u` - Snac `user`(s) to sync
* `-t` - Nex server `target` location for public files
* `-r` - is `rotate` every hour (`3600` seconds) to apply Snac instance updates (instead of export once)
* `-d` - enable `daemon` mode, which disables some debug output, to prevent extra write operations
* optionally, include `-a` (`attachment`) as `c` (`copy`) | `h` (`hard` link) | `s` (`soft` link)
* `systemctl daemon-reload` - apply new `systemd` configuration
* `systemctl enable snac2nex` - auto-start `snac2nex` sync on system boot
* `systemctl start snac2nex` - start `snac2nex` sync now
## Demo
* `nex://[302:68d0:f0d5:b88d::b]/` | `nex://ps.ygg/` - My personal [Yggdrasil](https://yggdrasil-network.github.io/) / [Alfis DNS](https://github.com/Revertron/Alfis) mirror
## See also
* [Nexy](https://github.com/YGGverse/nexy) - Server for the Nex protocol, written in Rust
* [Yoda](https://github.com/YGGverse/Yoda) - Client for the Gemini & Nex protocols, written in Rust