grace/dots
dotfiles/nix configs
git clone https://git.gae.moe/grace/dots
08de973
main
1{ config , pkgs , ... } : 2 3let 4ooye = pkgs . callPackage ../pkgs/ooye.nix { } ; 5in 6{ 7nixpkgs . config . permittedInsecurePackages = [ "olm-3.2.16" ] ; 8 9services . matrix-continuwuity = { 10enable = true ; 11package = pkgs . callPackage ../pkgs/continuwuity-legacy.nix { } ; 12settings . global = { 13server_name = "gae.moe" ; 14address = [ "0.0.0.0" ] ; 15port = [ 6167 ] ; 16allow_registration = false ; 17allow_federation = true ; 18well_known . client = "https://matrix.gae.moe" ; 19oauth . compatibility_mode = "exclusive" ; 20oauth . oidc = { 21discovery_url = "https://auth.gae.moe" ; 22client_id = "continuwuity" ; 23client_secret_file = "/run/credentials/continuwuity.service/oidc-client-secret" ; 24additional_scopes = [ "profile" ] ; 25} ; 26} ; 27} ; 28 29sops . secrets . continuwuity-oidc-client-secret = { 30sopsFile = ../secrets/dijkstra/continuwuity-oidc-client-secret.json ; 31format = "binary" ; 32restartUnits = [ "continuwuity.service" ] ; 33} ; 34 35systemd . services . continuwuity . serviceConfig . LoadCredential = [ 36"oidc-client-secret: ${ config . sops . secrets . continuwuity-oidc-client-secret . path } " 37] ; 38 39services . mautrix-discord = { 40enable = true ; 41dataDir = "/var/lib/mautrix-discord" ; 42settings = { 43homeserver = { 44address = "https://matrix.gae.moe" ; 45domain = "gae.moe" ; 46} ; 47appservice = { 48address = "http://127.0.0.1:29334" ; 49hostname = "127.0.0.1" ; 50} ; 51bridge . permissions . "@grace:gae.moe" = "admin" ; 52} ; 53} ; 54 55systemd . services . mautrix-discord = { 56wants = [ "continuwuity.service" ] ; 57after = [ "continuwuity.service" ] ; 58} ; 59 60users . groups . ooye = { } ; 61users . users . ooye = { 62isSystemUser = true ; 63group = "ooye" ; 64home = "/var/lib/ooye" ; 65} ; 66 67systemd . tmpfiles . rules = [ "d /var/lib/ooye 0700 ooye ooye -" ] ; 68 69environment . systemPackages = [ 70( pkgs . writeShellScriptBin "ooye-configure" '' 71set -eu 72umask 077 73cd /var/lib/ooye 74${ ooye } /bin/ooye-setup 75touch .configured 76'' ) 77] ; 78 79systemd . services . ooye = { 80description = "Out Of Your Element Matrix-Discord bridge" ; 81wantedBy = [ "multi-user.target" ] ; 82wants = [ "network-online.target" ] ; 83after = [ 84"network-online.target" 85"continuwuity.service" 86] ; 87unitConfig . ConditionPathExists = "/var/lib/ooye/.configured" ; 88serviceConfig = { 89User = "ooye" ; 90Group = "ooye" ; 91WorkingDirectory = "/var/lib/ooye" ; 92StateDirectory = "ooye" ; 93StateDirectoryMode = "0700" ; 94ExecStart = " ${ ooye } /bin/ooye" ; 95Restart = "on-failure" ; 96RestartSec = 10 ; 97UMask = "0077" ; 98NoNewPrivileges = true ; 99PrivateTmp = true ; 100ProtectSystem = "strict" ; 101ProtectHome = true ; 102} ; 103} ; 104 105systemd . services . backup-matrix = { 106description = "Back up Matrix and Discord bridge state with services stopped" ; 107unitConfig . RequiresMountsFor = [ "/mnt/backup" ] ; 108path = [ 109pkgs . rsync 110pkgs . util-linux 111pkgs . coreutils 112pkgs . systemd 113] ; 114serviceConfig = { 115Type = "oneshot" ; 116UMask = "0077" ; 117} ; 118script = '' 119set -eu 120mountpoint -q /mnt/backup 121install -d -m 0700 /mnt/backup/matrix 122active="" 123for unit in ooye.service mautrix-discord.service continuwuity.service; do 124if systemctl is-active --quiet "$unit"; then 125active="$active $unit" 126fi 127done 128trap 'if [ -n "$active" ]; then systemctl start $active; fi' EXIT 129systemctl stop ooye.service mautrix-discord.service continuwuity.service 130if [ -d /var/lib/continuwuity ]; then 131rsync -a --delete /var/lib/continuwuity/ /mnt/backup/matrix/continuwuity/ 132fi 133rsync -a --delete /var/lib/ooye/ /mnt/backup/matrix/ooye/ 134if [ -d /var/lib/mautrix-discord ]; then 135rsync -a --delete /var/lib/mautrix-discord/ /mnt/backup/matrix/mautrix-discord/ 136fi 137'' ; 138} ; 139 140systemd . timers . backup-matrix = { 141wantedBy = [ "timers.target" ] ; 142timerConfig = { 143OnCalendar = "daily" ; 144Persistent = true ; 145} ; 146} ; 147}