change capitalization of storage endpoints & backup misskey media

This commit is contained in:
Chaos 2023-01-07 11:59:13 +00:00
parent 2da13bd3ee
commit b61acd731c
No known key found for this signature in database
8 changed files with 134 additions and 19 deletions

View file

@ -13,7 +13,7 @@
rclone_config = pkgs.writeText "rclone.conf" '' rclone_config = pkgs.writeText "rclone.conf" ''
[Music] [Music]
type = webdav type = webdav
url = https://storage-webdav.owo.monster/music_ro/ url = https://storage-webdav.owo.monster/MusicRO/
vendor = nextcloud vendor = nextcloud
''; '';
in '' in ''

View file

@ -1,13 +1,14 @@
{...}: { {...}: {
rclone_serve_webdav_main = 4242; rclone_serve_webdav_main = 4200;
rclone_serve_webdav_media = 4243; rclone_serve_webdav_media = 4201;
rclone_serve_webdav_music_ro = 4244; rclone_serve_webdav_misskey = 4202;
rclone_serve_webdav_music_ro = 4203;
rclone_serve_restic_hvm = 4245; rclone_serve_restic_hvm = 4210;
rclone_serve_restic_music = 4246; rclone_serve_restic_music = 4211;
rclone_serve_restic_vault = 4247; rclone_serve_restic_vault = 4212;
rclone_serve_restic_matrix = 4248; rclone_serve_restic_matrix = 4213;
rclone_serve_http_music = 4249; rclone_serve_http_music = 4220;
rclone_serve_http_public = 4250; rclone_serve_http_public = 4221;
} }

View file

@ -23,12 +23,23 @@ in {
extraArgs = [ extraArgs = [
"--addr=0.0.0.0:${toString ports.rclone_serve_webdav_main}" "--addr=0.0.0.0:${toString ports.rclone_serve_webdav_main}"
"--htpasswd=${secrets.webdav_main_htpasswd.path}" "--htpasswd=${secrets.webdav_main_htpasswd.path}"
"--baseurl=/main/" "--baseurl=/Main/"
"--cache-dir=/caches/main_webdav_serve" "--cache-dir=/caches/main_webdav_serve"
"--vfs-cache-mode=full" "--vfs-cache-mode=full"
]; ];
inherit serviceConfig; inherit serviceConfig;
} }
{
user = "storage";
remote = "StorageBox:Backups/Misskey";
type = "webdav";
extraArgs = [
"--addr=0.0.0.0:${toString ports.rclone_serve_webdav_misskey}"
"--htpasswd=${secrets.webdav_misskey_htpasswd.path}"
"--baseurl=/Misskey/"
];
inherit serviceConfig;
}
{ {
user = "storage"; user = "storage";
remote = "Media-Combine-Serve:"; remote = "Media-Combine-Serve:";
@ -36,7 +47,7 @@ in {
extraArgs = [ extraArgs = [
"--addr=0.0.0.0:${toString ports.rclone_serve_webdav_media}" "--addr=0.0.0.0:${toString ports.rclone_serve_webdav_media}"
"--htpasswd=${secrets.webdav_media_htpasswd.path}" "--htpasswd=${secrets.webdav_media_htpasswd.path}"
"--baseurl=/media/" "--baseurl=/Media/"
"--cache-dir=/caches/media_webdav_serve" "--cache-dir=/caches/media_webdav_serve"
"--vfs-cache-max-age=30m" "--vfs-cache-max-age=30m"
"--vfs-cache-max-size=5g" "--vfs-cache-max-size=5g"
@ -51,7 +62,7 @@ in {
extraArgs = [ extraArgs = [
"--addr=0.0.0.0:${toString ports.rclone_serve_webdav_music_ro}" "--addr=0.0.0.0:${toString ports.rclone_serve_webdav_music_ro}"
"--read-only" "--read-only"
"--baseurl=/music_ro/" "--baseurl=/MusicRO/"
]; ];
inherit serviceConfig; inherit serviceConfig;
} }

View file

@ -80,6 +80,7 @@
htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null
''; '';
}; };
webdav_main_htpasswd = { webdav_main_htpasswd = {
user = "storage"; user = "storage";
group = "storage"; group = "storage";
@ -89,7 +90,6 @@
htpasswd -bc "$secretFile" "$username" "$password" 2>&1 htpasswd -bc "$secretFile" "$username" "$password" 2>&1
''; '';
}; };
webdav_media_htpasswd = { webdav_media_htpasswd = {
user = "storage"; user = "storage";
group = "storage"; group = "storage";
@ -99,6 +99,15 @@
htpasswd -bc "$secretFile" "$username" "$password" 2>&1 htpasswd -bc "$secretFile" "$username" "$password" 2>&1
''; '';
}; };
webdav_misskey_htpasswd = {
user = "storage";
group = "storage";
fetchScript = ''
username=$(simple_get "/api-keys/storage/webdav/misskey" .username)
password=$(simple_get "/api-keys/storage/webdav/misskey" .password)
htpasswd -bc "$secretFile" "$username" "$password" 2>&1
'';
};
rclone_config = { rclone_config = {
user = "storage"; user = "storage";

View file

@ -72,9 +72,10 @@ in {
forceSSL = true; forceSSL = true;
enableACME = true; enableACME = true;
locations = { locations = {
"/main/".proxyPass = "http://${containerIP}:${toString ports.rclone_serve_webdav_main}"; "/Main/".proxyPass = "http://${containerIP}:${toString ports.rclone_serve_webdav_main}";
"/media/".proxyPass = "http://${containerIP}:${toString ports.rclone_serve_webdav_media}"; "/Media/".proxyPass = "http://${containerIP}:${toString ports.rclone_serve_webdav_media}";
"/music_ro/".proxyPass = "http://${containerIP}:${toString ports.rclone_serve_webdav_music_ro}"; "/Misskey/".proxyPass = "http://${containerIP}:${toString ports.rclone_serve_webdav_misskey}";
"/MusicRO/".proxyPass = "http://${containerIP}:${toString ports.rclone_serve_webdav_music_ro}";
}; };
}; };

View file

@ -0,0 +1,12 @@
[Misskey-Storage]
type = webdav
url = https://storage-webdav.owo.monster/Misskey/
vendor = nextcloud
user = misskey
pass = MISSKEY_STORAGE_PASSWORD
[Storage-Media-Crypt]
type = crypt
remote = Misskey-Storage:
password = STORAGE_MISSKEY_CRYPT_PASSWORD
password2 = STORAGE_MISSKEY_CRYPT_SALT

View file

@ -1,8 +1,11 @@
{ {
config,
pkgs, pkgs,
tree, tree,
... ...
}: let }: let
secrets = config.services.secrets.secrets;
ports = import ../ports.nix {}; ports = import ../ports.nix {};
misskeyDomain = "social.owo.monster"; misskeyDomain = "social.owo.monster";
@ -62,8 +65,6 @@ in {
imports = with tree; [home.base home.dev.small]; imports = with tree; [home.base home.dev.small];
}; };
systemd.tmpfiles.rules = ["d /home/misskey/misskey-files - misskey users"];
systemd.services.misskey-files = { systemd.services.misskey-files = {
serviceConfig.Type = "oneshot"; serviceConfig.Type = "oneshot";
wantedBy = ["misskey.service"]; wantedBy = ["misskey.service"];
@ -151,4 +152,36 @@ in {
enable = true; enable = true;
port = ports.misskey-redis; port = ports.misskey-redis;
}; };
environment.systemPackages = with pkgs; [
rclone
(pkgs.writeShellScriptBin "rclone-misskey" ''
${pkgs.rclone}/bin/rclone --config ${secrets.misskey_storage_rclone_config.path} \
$@
'')
];
systemd.tmpfiles.rules = [
"d /home/misskey/misskey-files - misskey users"
"d /home/misskey/.config - misskey users"
"d /home/misskey/.config/rclone - misskey users"
"L /home/misskey/.config/rclone/rclone.conf - - - - ${secrets.misskey_storage_rclone_config.path}"
];
services.rclone-sync = {
enable = true;
user = "misskey";
sync_jobs = [
{
source = "/home/misskey/misskey-files";
dest = "Storage-Media-Crypt:";
serviceConfig = {};
timerConfig = {
OnStartupSec = "60";
OnCalendar = "4h";
};
}
];
};
} }

View file

@ -5,8 +5,32 @@
extraPackages = with pkgs; [ extraPackages = with pkgs; [
# for music & mail passwd files # for music & mail passwd files
apacheHttpd apacheHttpd
# for rclone file for misskey files sync
rclone
]; ];
extraFunctions = ''
replace_slash_for_sed() {
sed "s#/#\\\/#"
}
simple_get_obscure() {
rclone obscure "$(simple_get "$@")"
}
simple_get_replace_crypt() {
password=$(simple_get "$1" .password | replace_slash_for_sed)
salt=$(simple_get "$1" .salt | replace_slash_for_sed)
replace_password=''${2}_ACCOUNT
replace_salt=''${2}_KEY
sed -i "s/$replace_password/$password/" "$3"
sed -i "s/$replace_salt/$salt/" "$3"
}
'';
secrets = { secrets = {
mpd_control_password = { mpd_control_password = {
user = "mpd"; user = "mpd";
@ -63,6 +87,30 @@
echo "GITLAB_TOKEN=$token" > $secretFile echo "GITLAB_TOKEN=$token" > $secretFile
''; '';
}; };
misskey_storage_rclone_config = {
user = "misskey";
group = "users";
fetchScript = ''
TMP_DIR="$(mktemp -d)"
cp ${./data/misskey_rclone.template} "$TMP_DIR/template"
pushd "$TMP_DIR" 2>/dev/null
MISSKEY_STORAGE_PASSWORD=$(simple_get_obscure /api-keys/storage/webdav/misskey .password)
sed -i "s/MISSKEY_STORAGE_PASSWORD/$MISSKEY_STORAGE_PASSWORD/" ./template
simple_get_replace_crypt "/private-public-keys/rclone/Backups-Misskey-Crypt" "STORAGE_MISSKEY_CRYPT" ./template
cp ./template $secretFile
popd 2>/dev/null
rm -rf "$TMP_DIR"
'';
};
matrix_restic_password = { matrix_restic_password = {
fetchScript = '' fetchScript = ''
simple_get "/private-public-keys/restic/Matrix" .password > $secretFile simple_get "/private-public-keys/restic/Matrix" .password > $secretFile