grace/dots

dotfiles/nix configs

git clone https://git.gae.moe/grace/dots

Grace Yoderflake rewrite + a bunch\ni keep holding onto changes forever this is not how you use vcs08de973

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