style: nix fmt

This commit is contained in:
Kat Inskip 2025-07-13 05:10:57 -07:00
parent 7913481b66
commit 6e0cc170eb
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
112 changed files with 1977 additions and 1739 deletions

View file

@ -1,5 +1,12 @@
{ lib, stdenv, fetchFromGitLab, glib, gettext, substituteAll, gnome-menus }:
{
lib,
stdenv,
fetchFromGitLab,
glib,
gettext,
substituteAll,
gnome-menus,
}:
stdenv.mkDerivation rec {
pname = "gnome-shell-extension-arcmenu";
version = "63";
@ -19,10 +26,11 @@ stdenv.mkDerivation rec {
];
buildInputs = [
glib gettext
glib
gettext
];
makeFlags = [ "INSTALLBASE=${placeholder "out"}/share/gnome-shell/extensions" ];
makeFlags = ["INSTALLBASE=${placeholder "out"}/share/gnome-shell/extensions"];
passthru = {
extensionUuid = "arcmenu@arcmenu.com";
@ -32,7 +40,7 @@ stdenv.mkDerivation rec {
meta = with lib; {
description = "Application menu for GNOME Shell, designed to provide a more traditional user experience and workflow";
license = licenses.gpl2Plus;
maintainers = with maintainers; [ dkabot ];
maintainers = with maintainers; [dkabot];
homepage = "https://gitlab.com/arcmenu/ArcMenu";
};
}
}

View file

@ -3,7 +3,6 @@
stdenvNoCC,
fetchgit,
openssh,
findutils,
...
}:
stdenvNoCC.mkDerivation rec {

View file

@ -1,10 +1,6 @@
{
stdenv,
lib,
fetchFromGitHub,
pkg-config,
cmake,
setuptools,
python,
}: let
cppyy = python.buildPythonPackage rec {
@ -26,4 +22,5 @@
license = licenses.bsd3Lbnl;
};
};
in cppyy
in
cppyy

View file

@ -18,9 +18,7 @@
webkitgtk_4_1,
cargo-tauri,
desktop-file-utils,
}:
let
}: let
webkitgtk_4_1' = webkitgtk_4_1.override {
enableExperimental = true;
};
@ -30,165 +28,163 @@ let
hash = "sha256-d9vaKLrl8RYNcHnE1iGN49ov6U/Y+9XpEsio+c1Sguc=";
meta = {
homepage = "https://github.com/uwu/shelter";
sourceProvenance = [ lib.sourceTypes.binaryBytecode ]; # actually, minified JS
sourceProvenance = [lib.sourceTypes.binaryBytecode]; # actually, minified JS
license = lib.licenses.cc0;
};
};
in
rustPlatform.buildRustPackage (finalAttrs: {
pname = "dorion";
version = "6.7.1";
rustPlatform.buildRustPackage (finalAttrs: {
pname = "dorion";
version = "6.7.1";
src = fetchFromGitHub {
owner = "SpikeHD";
repo = "Dorion";
tag = "v${finalAttrs.version}";
hash = "sha256-d4G3royqhz+te5wPWVLNqqG/w0qOvTd7dKcWSzxUMUo=";
};
src = fetchFromGitHub {
owner = "SpikeHD";
repo = "Dorion";
tag = "v${finalAttrs.version}";
hash = "sha256-d4G3royqhz+te5wPWVLNqqG/w0qOvTd7dKcWSzxUMUo=";
};
cargoPatches = [
./no-cargo-patch.patch
];
cargoPatches = [
./no-cargo-patch.patch
];
cargoRoot = "src-tauri";
buildAndTestSubdir = finalAttrs.cargoRoot;
cargoRoot = "src-tauri";
buildAndTestSubdir = finalAttrs.cargoRoot;
useFetchCargoVendor = true;
cargoHash = "sha256-1xpAJkS31DjrZCY5WJ4/Z1t1ALED5gz7xYLhVR1Qzww=";
useFetchCargoVendor = true;
cargoHash = "sha256-1xpAJkS31DjrZCY5WJ4/Z1t1ALED5gz7xYLhVR1Qzww=";
pnpmDeps = pnpm_9.fetchDeps {
inherit (finalAttrs) pname version src;
hash = "sha256-xBonUzA4+1zbViEsKap6CaG6ZRldW1LjNYIB+FmVRFs=";
};
pnpmDeps = pnpm_9.fetchDeps {
inherit (finalAttrs) pname version src;
hash = "sha256-xBonUzA4+1zbViEsKap6CaG6ZRldW1LjNYIB+FmVRFs=";
};
# CMake (webkit extension)
cmakeDir = ".";
cmakeBuildDir = "src-tauri/extension_webkit";
dontUseCmakeConfigure = true;
dontUseNinjaBuild = true;
dontUseNinjaCheck = true;
dontUseNinjaInstall = true;
# cmake's supposed to set this automatically
# ... but the detection is based on the presence of ninja build hook
cmakeFlags = [
"-GNinja"
];
# CMake (webkit extension)
cmakeDir = ".";
cmakeBuildDir = "src-tauri/extension_webkit";
dontUseCmakeConfigure = true;
dontUseNinjaBuild = true;
dontUseNinjaCheck = true;
dontUseNinjaInstall = true;
# cmake's supposed to set this automatically
# ... but the detection is based on the presence of ninja build hook
cmakeFlags = [
"-GNinja"
];
nativeBuildInputs = [
pnpm_9.configHook
cargo-tauri.hook
nodejs
pkg-config
wrapGAppsHook4
yq-go
desktop-file-utils
cmake
ninja
];
nativeBuildInputs = [
pnpm_9.configHook
cargo-tauri.hook
nodejs
pkg-config
wrapGAppsHook4
yq-go
desktop-file-utils
cmake
ninja
];
buildInputs = [
openssl
webkitgtk_4_1'
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-good
gst_all_1.gst-plugins-rs
glib-networking
libsysprof-capture
libayatana-appindicator
];
buildInputs = [
openssl
webkitgtk_4_1'
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-good
gst_all_1.gst-plugins-rs
glib-networking
libsysprof-capture
libayatana-appindicator
];
postPatch = ''
# remove updater
rm -rf updater
postPatch = ''
# remove updater
rm -rf updater
# patch cargo-deps
pushd $cargoDepsCopy/tauri-plugin-shell-*
patch -p1 < /build/source/src-tauri/patches/tauri-plugin-shell+*.patch
popd
# patch cargo-deps
pushd $cargoDepsCopy/tauri-plugin-shell-*
patch -p1 < /build/source/src-tauri/patches/tauri-plugin-shell+*.patch
popd
substituteInPlace $cargoDepsCopy/libappindicator-sys-*/src/lib.rs \
--replace-fail "libayatana-appindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1"
substituteInPlace $cargoDepsCopy/libappindicator-sys-*/src/lib.rs \
--replace-fail "libayatana-appindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1"
# disable pre-build script and disable auto-updater
yq -iPo=json '
.bundle.resources = (.bundle.resources | map(select(. != "updater*")))
' src-tauri/tauri.conf.json
# disable pre-build script and disable auto-updater
yq -iPo=json '
.bundle.resources = (.bundle.resources | map(select(. != "updater*")))
' src-tauri/tauri.conf.json
# link shelter injection
ln -s ${shelter} src-tauri/injection/shelter.js
# link shelter injection
ln -s ${shelter} src-tauri/injection/shelter.js
# link html/frontend data
ln -s /build/source/src /build/source/src-tauri/html
'';
configurePhase = ''
cmakeConfigurePhase
pnpmConfigHook
'';
buildPhase = ''
ninjaBuildPhase
cd /build/source
tauriBuildHook
'';
postInstall = ''
# Set up the resource directories
mkdir -p $out/lib/Dorion
ln -s $out/lib/Dorion $out/lib/dorion
rm -rf $out/lib/Dorion/injection
cp -r src-tauri/injection $out/lib/Dorion
cp -r src $out/lib/Dorion
# Modify the desktop file
desktop-file-edit \
--set-comment "Tiny alternative Discord client" \
--set-key="Exec" --set-value="Dorion %U" \
--set-key="TryExec" --set-value="Dorion" \
--set-key="StartupWMClass" --set-value="Dorion" \
--set-key="StartupNotify" --set-value="true" \
--set-key="Categories" --set-value="Network;InstantMessaging;Chat;" \
--set-key="Keywords" --set-value="dorion;discord;vencord;chat;im;vc;ds;dc;dsc;tauri;" \
--set-key="Terminal" --set-value="false" \
--set-key="MimeType" --set-value="x-scheme-handler/discord" \
$out/share/applications/Dorion.desktop
'';
# error: failed to run custom build command for `Dorion v6.5.3 (/build/source/src-tauri)`
# Permission denied (os error 13)
doCheck = false;
env = {
TAURI_RESOURCE_DIR = "${placeholder "out"}/lib";
};
meta = {
homepage = "https://spikehd.github.io/projects/dorion/";
description = "Tiny alternative Discord client";
longDescription = ''
Dorion is an alternative Discord client aimed towards lower-spec or
storage-sensitive PCs that supports themes, plugins, and more!
# link html/frontend data
ln -s /build/source/src /build/source/src-tauri/html
'';
changelog = "https://github.com/SpikeHD/Dorion/releases/tag/v${finalAttrs.version}";
downloadPage = "https://github.com/SpikeHD/Dorion/releases/tag/v${finalAttrs.version}";
license = with lib.licenses; [
gpl3Only
cc0 # Shelter
];
mainProgram = "Dorion";
maintainers = with lib.maintainers; [
nyabinary
aleksana
griffi-gh
getchoo
];
platforms = lib.platforms.linux;
sourceProvenance = [
lib.sourceTypes.binaryBytecode # actually, minified JS
lib.sourceTypes.fromSource
];
};
})
configurePhase = ''
cmakeConfigurePhase
pnpmConfigHook
'';
buildPhase = ''
ninjaBuildPhase
cd /build/source
tauriBuildHook
'';
postInstall = ''
# Set up the resource directories
mkdir -p $out/lib/Dorion
ln -s $out/lib/Dorion $out/lib/dorion
rm -rf $out/lib/Dorion/injection
cp -r src-tauri/injection $out/lib/Dorion
cp -r src $out/lib/Dorion
# Modify the desktop file
desktop-file-edit \
--set-comment "Tiny alternative Discord client" \
--set-key="Exec" --set-value="Dorion %U" \
--set-key="TryExec" --set-value="Dorion" \
--set-key="StartupWMClass" --set-value="Dorion" \
--set-key="StartupNotify" --set-value="true" \
--set-key="Categories" --set-value="Network;InstantMessaging;Chat;" \
--set-key="Keywords" --set-value="dorion;discord;vencord;chat;im;vc;ds;dc;dsc;tauri;" \
--set-key="Terminal" --set-value="false" \
--set-key="MimeType" --set-value="x-scheme-handler/discord" \
$out/share/applications/Dorion.desktop
'';
# error: failed to run custom build command for `Dorion v6.5.3 (/build/source/src-tauri)`
# Permission denied (os error 13)
doCheck = false;
env = {
TAURI_RESOURCE_DIR = "${placeholder "out"}/lib";
};
meta = {
homepage = "https://spikehd.github.io/projects/dorion/";
description = "Tiny alternative Discord client";
longDescription = ''
Dorion is an alternative Discord client aimed towards lower-spec or
storage-sensitive PCs that supports themes, plugins, and more!
'';
changelog = "https://github.com/SpikeHD/Dorion/releases/tag/v${finalAttrs.version}";
downloadPage = "https://github.com/SpikeHD/Dorion/releases/tag/v${finalAttrs.version}";
license = with lib.licenses; [
gpl3Only
cc0 # Shelter
];
mainProgram = "Dorion";
maintainers = with lib.maintainers; [
nyabinary
aleksana
griffi-gh
getchoo
];
platforms = lib.platforms.linux;
sourceProvenance = [
lib.sourceTypes.binaryBytecode # actually, minified JS
lib.sourceTypes.fromSource
];
};
})

View file

@ -1,5 +1,4 @@
{
lib,
stdenv,
fetchFromGitHub,
extra-cmake-modules,

View file

@ -8,73 +8,73 @@ SYSTEM_TYPE=${3:-""}
# Helper functions
send_discord_message() {
local message="$1"
if [[ -n "$DISCORD_WEBHOOK_LINK" ]]; then
local escaped_message=$(printf '%s' "$message" | jq -R -s '.')
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
else
echo "Discord message (not sent): $message"
fi
local message="$1"
if [[ -n "$DISCORD_WEBHOOK_LINK" ]]; then
local escaped_message=$(printf '%s' "$message" | jq -R -s '.')
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
else
echo "Discord message (not sent): $message"
fi
}
init_nfargs() {
local nflinksuffix="-L"
local nflinksuffix="-L"
nfargs=(
"${NIX_BUILD_ARGS[@]}"
nfargs=(
"${NIX_BUILD_ARGS[@]}"
)
if [[ -n "${NF_ACTIONS_TEST_OUTLINK-}" || -n "${NF_UPDATE_CACHIX_PUSH-}" ]]; then
nfargs+=(
-o "${NF_ACTIONS_TEST_OUTLINK-result}" "$nflinksuffix"
)
if [[ -n "${NF_ACTIONS_TEST_OUTLINK-}" || -n "${NF_UPDATE_CACHIX_PUSH-}" ]]; then
nfargs+=(
-o "${NF_ACTIONS_TEST_OUTLINK-result}" "$nflinksuffix"
)
else
nfargs+=(
--no-link
)
fi
else
nfargs+=(
--no-link
)
fi
}
perform_cachix_push() {
local nflinksuffix="-L"
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
send_discord_message "Cachix pushing ${SYSTEM_TYPE} system build for ${ALIAS}"
cachix push kittywitch "./${NF_ACTIONS_TEST_OUTLINK-result}$nflinksuffix"*/
fi
local nflinksuffix="-L"
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
send_discord_message "Cachix pushing ${SYSTEM_TYPE} system build for ${ALIAS}"
cachix push kittywitch "./${NF_ACTIONS_TEST_OUTLINK-result}$nflinksuffix"*/
fi
}
perform_garbage_collection() {
if [[ -n ${NF_ACTIONS_TEST_GC-} ]]; then
nix-collect-garbage -d
fi
if [[ -n ${NF_ACTIONS_TEST_GC-} ]]; then
nix-collect-garbage -d
fi
}
# Main script
if [[ -z "$SYSTEM_LINK" || -z "$ALIAS" || -z "$SYSTEM_TYPE" ]]; then
echo "Usage: $0 <SYSTEM_LINK> <ALIAS> <SYSTEM_TYPE>" >&2
exit 1
echo "Usage: $0 <SYSTEM_LINK> <ALIAS> <SYSTEM_TYPE>" >&2
exit 1
fi
send_discord_message "Starting ${SYSTEM_TYPE} system build for ${ALIAS}"
if [[ -n ${CACHIX_AUTH_TOKEN-} ]]; then
export NF_UPDATE_CACHIX_PUSH=1
export NF_UPDATE_CACHIX_PUSH=1
fi
cd "$NF_CONFIG_ROOT"
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
fi
if [[ ${GITHUB_ACTIONS-} = true && ${RUNNER_NAME-} = "Github Actions"* ]]; then
echo "Enabled GC between builds due to restricted disk space..." >&2
export NF_ACTIONS_TEST_GC=1
echo "Enabled GC between builds due to restricted disk space..." >&2
export NF_ACTIONS_TEST_GC=1
fi
NIX_BUILD_ARGS=(
--show-trace
--show-trace
)
NIX_BUILD_ARGS_ASYNC=()
@ -84,37 +84,37 @@ init_nfargs
nfwarn=
if [[ -n "${NF_NIX_SYSTEMS_WARN-}" && " ${NF_NIX_SYSTEMS_WARN[*]} " = *" $nfsystem "* ]]; then
nfwarn=1
nfwarn=1
fi
if [[ -n ${NF_ACTIONS_TEST_ASYNC-} && -z $nfwarn ]]; then
NIX_BUILD_ARGS_ASYNC+=("$nfinstallable")
NIX_BUILD_ARGS_ASYNC+=("$nfinstallable")
else
echo "Building ${nfsystem}..." >&2
echo >&2
echo "Building ${nfsystem}..." >&2
echo >&2
if ! nix build "$nfinstallable" "${nfargs[@]}"; then
if [[ -n $nfwarn ]]; then
send_discord_message "Build failure allowed for ${nfsystem}, ignoring..."
echo "Build failure allowed for ${nfsystem}, ignoring..." >&2
else
send_discord_message "Build failure for ${nfsystem}, problem!"
exit 1
fi
if ! nix build "$nfinstallable" "${nfargs[@]}"; then
if [[ -n $nfwarn ]]; then
send_discord_message "Build failure allowed for ${nfsystem}, ignoring..."
echo "Build failure allowed for ${nfsystem}, ignoring..." >&2
else
send_discord_message "${SYSTEM_TYPE} system build of ${ALIAS} succeeded!"
perform_cachix_push
perform_garbage_collection
send_discord_message "Build failure for ${nfsystem}, problem!"
exit 1
fi
else
send_discord_message "${SYSTEM_TYPE} system build of ${ALIAS} succeeded!"
perform_cachix_push
perform_garbage_collection
fi
fi
if [[ -n ${NF_ACTIONS_TEST_ASYNC-} ]]; then
init_nfargs
if nix build "${nfargs[@]}" "${NIX_BUILD_ARGS_ASYNC[@]}"; then
perform_cachix_push
perform_garbage_collection
else
send_discord_message "Async build failure for ${nfsystem}, problem!"
exit 1
fi
init_nfargs
if nix build "${nfargs[@]}" "${NIX_BUILD_ARGS_ASYNC[@]}"; then
perform_cachix_push
perform_garbage_collection
else
send_discord_message "Async build failure for ${nfsystem}, problem!"
exit 1
fi
fi

View file

@ -5,10 +5,11 @@
cachix,
jq,
nix,
curl
curl,
}: let
inherit (lib) makeBinPath;
in writeShellScriptBin "nf-build-system" ''
in
writeShellScriptBin "nf-build-system" ''
export PATH="$PATH:${lib.makeBinPath [
git
cachix
@ -17,4 +18,4 @@ in writeShellScriptBin "nf-build-system" ''
curl
]}"
exec ${./build-system.sh} "$@"
''
''

View file

@ -5,10 +5,11 @@
cachix,
jq,
nix,
curl
curl,
}: let
inherit (lib) makeBinPath;
in writeShellScriptBin "nf-update" ''
in
writeShellScriptBin "nf-update" ''
export PATH="$PATH:${lib.makeBinPath [
git
cachix
@ -17,4 +18,4 @@ in writeShellScriptBin "nf-update" ''
curl
]}"
exec ${./update.sh} "$@"
''
''

View file

@ -5,14 +5,14 @@ DISCORD_WEBHOOK_LINK=${DISCORD_WEBHOOK_LINK:-""}
# Helper functions
send_discord_message() {
local message="$1"
local escaped_message=$(printf '%s' "$message" | jq -R -s '.')
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
local message="$1"
local escaped_message=$(printf '%s' "$message" | jq -R -s '.')
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
}
if [[ -n ${CACHIX_AUTH_TOKEN-} ]]; then
export NF_UPDATE_CACHIX_PUSH=1
export NF_UPDATE_CACHIX_PUSH=1
fi
cd "$NF_CONFIG_ROOT"
@ -22,48 +22,48 @@ send_discord_message "Beginning flake update cron job"
nix flake update "$@"
if [[ -n $(git status --porcelain ./flake.lock) ]]; then
git -P diff ./flake.lock
git -P diff ./flake.lock
else
echo "no source changes" >&2
exit
echo "no source changes" >&2
exit
fi
echo "checking that nodes still build..." >&2
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
fi
if [[ -z ${NF_UPDATE_SKIP-} ]]; then
send_discord_message "checking that nodes still build..."
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
fi
send_discord_message "checking that nodes still build..."
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
export NF_ACTIONS_TEST_OUTLINK=${NF_ACTIONS_TEST_OUTLINK-result}
fi
nix run .#nf-actions-test -- -L
fi
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} && -v NF_ACTIONS_TEST_OUTLINK ]]; then
send_discord_message "Cachix pushing"
cachix push kittywitch "./${NF_ACTIONS_TEST_OUTLINK}"*/ &
CACHIX_PUSH=$!
cachix push kittywitch "./${NF_ACTIONS_TEST_OUTLINK}"*/ &
CACHIX_PUSH=$!
fi
if [[ -z ${NF_UPDATE_GIT_COMMIT-} ]]; then
wait ${CACHIX_PUSH-}
exit
wait ${CACHIX_PUSH-}
exit
fi
if [[ -n $(git diff --staged) ]]; then
echo "git working tree dirty, refusing to commit..." >&2
exit 1
echo "git working tree dirty, refusing to commit..." >&2
exit 1
fi
git add flake.lock
env \
GIT_{COMMITTER,AUTHOR}_EMAIL=github@kittywit.ch \
GIT_{COMMITTER,AUTHOR}_NAME="flake cron job" \
git commit --message="chore(ci): flake update"
GIT_{COMMITTER,AUTHOR}_EMAIL=github@kittywit.ch \
GIT_{COMMITTER,AUTHOR}_NAME="flake cron job" \
git commit --message="chore(ci): flake update"
if [[ ${GITHUB_REF-} = refs/heads/${NF_UPDATE_BRANCH-main} ]]; then
git push origin HEAD:${NF_UPDATE_BRANCH-main}
git push origin HEAD:${NF_UPDATE_BRANCH-main}
send_discord_message "Pushed a new commit!"
fi

View file

@ -10,89 +10,89 @@ MONTHS_TO_KEEP=1
# Helper functions
send_discord_message() {
local message="$1"
echo "$message"
local escaped_message=$(printf '%s' "$message" | jq -R -s '.')
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
local message="$1"
echo "$message"
local escaped_message=$(printf '%s' "$message" | jq -R -s '.')
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-X POST --data "{\"content\": $escaped_message}" "$DISCORD_WEBHOOK_LINK"
}
get_db_size() {
sudo -u postgres psql matrix-synapse -t -c \
"SELECT pg_size_pretty(pg_database_size('matrix-synapse'));" | tr -d ' '
sudo -u postgres psql matrix-synapse -t -c \
"SELECT pg_size_pretty(pg_database_size('matrix-synapse'));" | tr -d ' '
}
get_media_store_size() {
sudo du /var/lib/matrix-synapse/media_store -hd 0 | awk '{print $1}'
sudo du /var/lib/matrix-synapse/media_store -hd 0 | awk '{print $1}'
}
get_filesystem_usage() {
df -h / | awk 'NR==2 {print $5 " (" $3 ")"}' | tr -d '\n'
df -h / | awk 'NR==2 {print $5 " (" $3 ")"}' | tr -d '\n'
}
calculate_ratio() {
local before="$1"
local after="$2"
awk "BEGIN {printf \"%.2f\", ($after / $before) * 100}"
local before="$1"
local after="$2"
awk "BEGIN {printf \"%.2f\", ($after / $before) * 100}"
}
# Main script
main() {
# Check for required variables
if [[ -z "$HOMESERVER" || -z "$API_ID" || -z "$DISCORD_WEBHOOK_LINK" ]]; then
send_discord_message "Error: HOMESERVER, API_ID, and DISCORD_WEBHOOK_LINK must be set."
exit 1
# Check for required variables
if [[ -z "$HOMESERVER" || -z "$API_ID" || -z "$DISCORD_WEBHOOK_LINK" ]]; then
send_discord_message "Error: HOMESERVER, API_ID, and DISCORD_WEBHOOK_LINK must be set."
exit 1
fi
# Initial sizes and usage
local db_before_size=$(get_db_size)
local media_before_size=$(get_media_store_size)
local fs_before_usage=$(get_filesystem_usage)
send_discord_message "Beginning matrix-synapse optimization process - Database before size: ${db_before_size}, Media store before size: ${media_before_size}, Filesystem usage before: ${fs_before_usage}"
send_discord_message "Starting synapse"
systemctl start matrix-synapse
sleep 5
send_discord_message "Collecting required room data"
curl --header "Authorization: Bearer ${API_ID}" \
"https://${HOMESERVER}/_synapse/admin/v1/rooms?limit=500" > "${TEMPDIR}/roomlist.json"
jq '.rooms[] | select(.joined_local_members == 0) | .room_id' < "${TEMPDIR}/roomlist.json" > "${TEMPDIR}/to_purge.txt"
jq -c '.rooms[] | select(.joined_local_members != 0) | .room_id' < "${TEMPDIR}/roomlist.json" > "${TEMPDIR}/history_purge.txt"
local ts=$(( $(date --date="${MONTHS_TO_KEEP} month ago" +%s)*1000 ))
send_discord_message "Cleaning up media store"
curl --header "Authorization: Bearer ${API_ID}" -X POST \
"https://${HOMESERVER}/_synapse/admin/v1/media/delete?before_ts=${ts}&include_local=true"
send_discord_message "Deleting empty rooms"
while read -r room_id; do
if [ -n "${room_id}" ]; then
curl --header "Authorization: Bearer ${API_ID}" -X DELETE \
-H "Content-Type: application/json" -d "{}" \
"https://${HOMESERVER}/_synapse/admin/v2/rooms/${room_id}"
fi
done < "${TEMPDIR}/to_purge.txt"
# Initial sizes and usage
local db_before_size=$(get_db_size)
local media_before_size=$(get_media_store_size)
local fs_before_usage=$(get_filesystem_usage)
send_discord_message "Deleting unnecessary room history"
while read -r room_id; do
room_id=$(echo "$room_id" | tr -d '"') # Remove quotes if present
if [ -n "${room_id}" ]; then
curl --header "Authorization: Bearer ${API_ID}" -X POST \
-H "Content-Type: application/json" \
-d "{ \"delete_local_events\": true, \"purge_up_to_ts\": ${ts} }" \
"https://${HOMESERVER}/_synapse/admin/v1/purge_history/${room_id}"
fi
done < "${TEMPDIR}/history_purge.txt"
send_discord_message "Beginning matrix-synapse optimization process - Database before size: ${db_before_size}, Media store before size: ${media_before_size}, Filesystem usage before: ${fs_before_usage}"
send_discord_message "Starting synapse"
systemctl start matrix-synapse
sleep 5
send_discord_message "Collecting required room data"
curl --header "Authorization: Bearer ${API_ID}" \
"https://${HOMESERVER}/_synapse/admin/v1/rooms?limit=500" > "${TEMPDIR}/roomlist.json"
jq '.rooms[] | select(.joined_local_members == 0) | .room_id' < "${TEMPDIR}/roomlist.json" > "${TEMPDIR}/to_purge.txt"
jq -c '.rooms[] | select(.joined_local_members != 0) | .room_id' < "${TEMPDIR}/roomlist.json" > "${TEMPDIR}/history_purge.txt"
local ts=$(( $(date --date="${MONTHS_TO_KEEP} month ago" +%s)*1000 ))
send_discord_message "Cleaning up media store"
curl --header "Authorization: Bearer ${API_ID}" -X POST \
"https://${HOMESERVER}/_synapse/admin/v1/media/delete?before_ts=${ts}&include_local=true"
send_discord_message "Deleting empty rooms"
while read -r room_id; do
if [ -n "${room_id}" ]; then
curl --header "Authorization: Bearer ${API_ID}" -X DELETE \
-H "Content-Type: application/json" -d "{}" \
"https://${HOMESERVER}/_synapse/admin/v2/rooms/${room_id}"
fi
done < "${TEMPDIR}/to_purge.txt"
send_discord_message "Deleting unnecessary room history"
while read -r room_id; do
room_id=$(echo "$room_id" | tr -d '"') # Remove quotes if present
if [ -n "${room_id}" ]; then
curl --header "Authorization: Bearer ${API_ID}" -X POST \
-H "Content-Type: application/json" \
-d "{ \"delete_local_events\": true, \"purge_up_to_ts\": ${ts} }" \
"https://${HOMESERVER}/_synapse/admin/v1/purge_history/${room_id}"
fi
done < "${TEMPDIR}/history_purge.txt"
send_discord_message "Performing database optimization"
systemctl stop matrix-synapse
export PGHOST=/var/run/postgresql/
export PGDATABASE=matrix-synapse
export PGUSER=matrix-synapse
send_discord_message "Performing database optimization"
systemctl stop matrix-synapse
export PGHOST=/var/run/postgresql/
export PGDATABASE=matrix-synapse
export PGUSER=matrix-synapse
sudo -u postgres psql matrix-synapse <<_EOF
BEGIN;
@ -125,33 +125,33 @@ WHERE NOT EXISTS
COMMIT;
_EOF
send_discord_message "Running synapse_auto_compressor"
sudo -u matrix-synapse synapse_auto_compressor \
-p "postgresql://matrix-synapse?user=matrix-synapse&host=/var/run/postgresql/" \
-c 500 -n 100
send_discord_message "Running synapse_auto_compressor"
sudo -u matrix-synapse synapse_auto_compressor \
-p "postgresql://matrix-synapse?user=matrix-synapse&host=/var/run/postgresql/" \
-c 500 -n 100
send_discord_message "Reindexing database"
sudo -u postgres psql matrix-synapse -c "REINDEX (VERBOSE) DATABASE \"matrix-synapse\";"
send_discord_message "Reindexing database"
sudo -u postgres psql matrix-synapse -c "REINDEX (VERBOSE) DATABASE \"matrix-synapse\";"
send_discord_message "Vacuuming database"
sudo -u postgres psql matrix-synapse -c "VACUUM FULL VERBOSE;"
send_discord_message "Vacuuming database"
sudo -u postgres psql matrix-synapse -c "VACUUM FULL VERBOSE;"
rm -rf "${TEMPDIR}"
rm -rf "${TEMPDIR}"
send_discord_message "Synapse cleanup performed, booting up"
systemctl start matrix-synapse
send_discord_message "Synapse cleanup performed, booting up"
systemctl start matrix-synapse
# Final sizes, usage, and ratios
local db_after_size=$(get_db_size)
local media_after_size=$(get_media_store_size)
local fs_after_usage=$(get_filesystem_usage)
local db_ratio=$(calculate_ratio "${db_before_size//[A-Za-z]/}" "${db_after_size//[A-Za-z]/}")
local media_ratio=$(calculate_ratio "${media_before_size//[A-Za-z]/}" "${media_after_size//[A-Za-z]/}")
# Final sizes, usage, and ratios
local db_after_size=$(get_db_size)
local media_after_size=$(get_media_store_size)
local fs_after_usage=$(get_filesystem_usage)
local db_ratio=$(calculate_ratio "${db_before_size//[A-Za-z]/}" "${db_after_size//[A-Za-z]/}")
local media_ratio=$(calculate_ratio "${media_before_size//[A-Za-z]/}" "${media_after_size//[A-Za-z]/}")
send_discord_message "Matrix-synapse optimization process finished -
send_discord_message "Matrix-synapse optimization process finished -
Database: ${db_before_size} -> ${db_after_size} (${db_ratio}%),
Media store: ${media_before_size} -> ${media_after_size} (${media_ratio}%),
Filesystem usage: ${fs_before_usage} -> ${fs_after_usage}"
Filesystem usage: ${fs_before_usage} -> ${fs_after_usage}"
}
# Run the main function