2022-12-04 13:45:43 +00:00
|
|
|
{
|
2023-01-07 11:59:13 +00:00
|
|
|
config,
|
2022-12-04 13:45:43 +00:00
|
|
|
pkgs,
|
|
|
|
tree,
|
|
|
|
...
|
|
|
|
}: let
|
2023-01-07 11:59:13 +00:00
|
|
|
secrets = config.services.secrets.secrets;
|
|
|
|
|
2022-12-04 13:45:43 +00:00
|
|
|
ports = import ../ports.nix {};
|
2022-11-02 12:24:55 +00:00
|
|
|
|
2022-11-02 08:40:25 +00:00
|
|
|
misskeyDomain = "social.owo.monster";
|
|
|
|
|
|
|
|
misskeyPackages = with pkgs; [
|
|
|
|
nodejs
|
|
|
|
nodePackages.node-gyp
|
2023-03-24 08:19:03 +00:00
|
|
|
nodePackages.pnpm
|
2022-11-02 08:40:25 +00:00
|
|
|
|
|
|
|
python3
|
|
|
|
pkg-config
|
|
|
|
glib
|
|
|
|
vips
|
|
|
|
|
|
|
|
stdenv
|
|
|
|
];
|
|
|
|
|
|
|
|
misskeyConfig = {
|
|
|
|
url = "https://${misskeyDomain}/";
|
2022-11-03 06:44:02 +00:00
|
|
|
port = ports.misskey;
|
2022-11-02 08:40:25 +00:00
|
|
|
id = "aid";
|
|
|
|
|
|
|
|
db = {
|
|
|
|
host = "localhost";
|
|
|
|
port = "5432";
|
|
|
|
db = "misskey";
|
|
|
|
user = "misskey";
|
|
|
|
pass = "password";
|
|
|
|
};
|
|
|
|
|
|
|
|
redis = {
|
|
|
|
host = "127.0.0.1";
|
2022-11-03 06:44:02 +00:00
|
|
|
port = ports.misskey-redis;
|
2022-11-02 08:40:25 +00:00
|
|
|
};
|
2022-11-23 15:58:12 +00:00
|
|
|
|
2022-12-20 12:28:00 +00:00
|
|
|
# Allows federation with gotosocial which requires AP Get to be signed
|
|
|
|
signToActivityPubGet = true;
|
2022-11-23 15:58:12 +00:00
|
|
|
clusterLimit = 4;
|
|
|
|
outgoingAddressFamily = "dual";
|
2022-11-02 08:40:25 +00:00
|
|
|
};
|
|
|
|
in {
|
2023-02-09 16:25:37 +00:00
|
|
|
environment.etc."misskey.yml".text = pkgs.lib.generators.toYAML {} misskeyConfig;
|
2023-01-14 18:31:53 +00:00
|
|
|
|
2022-11-02 08:40:25 +00:00
|
|
|
users.users."misskey" = {
|
|
|
|
isNormalUser = true;
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
home-manager.users."misskey" = {
|
|
|
|
home.packages = misskeyPackages;
|
|
|
|
home.stateVersion = "22.05";
|
|
|
|
|
2022-12-04 13:45:43 +00:00
|
|
|
imports = with tree; [home.base home.dev.small];
|
2022-11-02 08:40:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.misskey-password = {
|
|
|
|
serviceConfig.Type = "oneshot";
|
2022-12-04 13:45:43 +00:00
|
|
|
wantedBy = ["misskey.service"];
|
|
|
|
wants = ["postgresql.service"];
|
|
|
|
after = ["postgresql.service"];
|
2022-11-02 08:40:25 +00:00
|
|
|
script = ''
|
|
|
|
${pkgs.postgresql}/bin/psql -c "ALTER USER misskey WITH PASSWORD 'password';"
|
|
|
|
'';
|
|
|
|
serviceConfig.User = "misskey";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.misskey = {
|
2022-12-04 13:45:43 +00:00
|
|
|
wantedBy = ["multi-user.target"];
|
2023-01-14 18:31:53 +00:00
|
|
|
after = ["misskey-password.service"];
|
2022-12-04 13:45:43 +00:00
|
|
|
wants = ["postgresql.service" "redis-misskey.service"];
|
|
|
|
path = with pkgs; [bash git] ++ misskeyPackages;
|
2022-11-02 08:40:25 +00:00
|
|
|
environment.NODE_ENV = "production";
|
|
|
|
serviceConfig = {
|
|
|
|
User = "misskey";
|
|
|
|
WorkingDirectory = "/home/misskey/misskey";
|
2023-03-24 08:19:03 +00:00
|
|
|
ExecStartPre = "${pkgs.nodePackages.pnpm}/bin/pnpm migrate";
|
|
|
|
ExecStart = "${pkgs.nodePackages.pnpm}/bin/pnpm start";
|
2022-11-02 08:40:25 +00:00
|
|
|
#TimeoutSec = 60;
|
|
|
|
#StandardOutput = "syslog";
|
|
|
|
#StandardError = "syslog";
|
|
|
|
#SyslogIdentifier = "misskey";
|
|
|
|
#Restart = "always";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."${misskeyDomain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
locations = {
|
|
|
|
"/" = {
|
2022-11-03 06:44:02 +00:00
|
|
|
proxyPass = "http://127.0.0.1:${toString ports.misskey}";
|
2022-11-02 08:40:25 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2022-12-04 13:45:43 +00:00
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "misskey";
|
|
|
|
ensurePermissions."DATABASE misskey" = "ALL PRIVILEGES";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
ensureDatabases = ["misskey"];
|
2022-11-02 08:40:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.redis.servers."misskey" = {
|
|
|
|
enable = true;
|
2022-11-03 06:44:02 +00:00
|
|
|
port = ports.misskey-redis;
|
2022-11-02 08:40:25 +00:00
|
|
|
};
|
2023-01-07 11:59:13 +00:00
|
|
|
|
|
|
|
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}"
|
|
|
|
];
|
|
|
|
|
2023-03-25 09:33:20 +00:00
|
|
|
systemd.services."misskey-files-sync" = {
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script = let
|
|
|
|
bsdtar = "${pkgs.libarchive}/bin/bsdtar";
|
|
|
|
rclone = "${pkgs.rclone}/bin/rclone";
|
|
|
|
in ''
|
|
|
|
pushd /home/misskey
|
|
|
|
pushd /home/misskey/misskey-files
|
|
|
|
${bsdtar} cvf ../Media.tar .
|
|
|
|
popd
|
|
|
|
${rclone} copy Media.tar Storage-Media-Crypt:Media.tar
|
|
|
|
rm Media.tar
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
serviceConfig.User = "misskey";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers."misskey-files-sync" = {
|
|
|
|
wantedBy = ["timers.target"];
|
|
|
|
partOf = ["misskey-files-sync.service"];
|
|
|
|
timerConfig = {
|
|
|
|
OnStartupSec = "60";
|
|
|
|
OnCalendar = "4h";
|
|
|
|
};
|
2023-01-07 11:59:13 +00:00
|
|
|
};
|
2022-11-02 08:40:25 +00:00
|
|
|
}
|