Self-host your own digital island

nixos 24.05

+4 -4
flake.lock
···
},
"nixpkgs_2": {
"locked": {
-
"lastModified": 1712867921,
-
"narHash": "sha256-edTFV4KldkCMdViC/rmpJa7oLIU8SE/S35lh/ukC7bg=",
+
"lastModified": 1717952948,
+
"narHash": "sha256-mJi4/gjiwQlSaxjA6AusXBN/6rQRaPCycR7bd8fydnQ=",
"owner": "nixos",
"repo": "nixpkgs",
-
"rev": "51651a540816273b67bc4dedea2d37d116c5f7fe",
+
"rev": "2819fffa7fa42156680f0d282c60d81e8fb185b7",
"type": "github"
},
"original": {
"owner": "nixos",
-
"ref": "nixos-23.11",
+
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
+1 -1
flake.nix
···
{
inputs = {
-
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
+
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixos-mailserver.url = "github:RyanGibb/nixos-mailserver/fork-23.11";
eon.url = "github:RyanGibb/eon";
eon.inputs.nixpkgs.follows = "nixpkgs";
-1
modules/default.nix
···
./gitea.nix
./dns.nix
./matrix/synapse.nix
-
./matrix/mautrix-signal.nix
./matrix/mautrix-instagram.nix
./matrix/mautrix-messenger.nix
./turn.nix
-197
modules/matrix/mautrix-signal.nix
···
-
{ lib, config, pkgs, ... }:
-
let
-
cfg = config.services.mautrix-signal;
-
dataDir = "/var/lib/mautrix-signal";
-
registrationFile = "${dataDir}/signal-registration.yaml";
-
settingsFile = "${dataDir}/config.json";
-
settingsFileUnsubstituted =
-
settingsFormat.generate "mautrix-signal-config-unsubstituted.json"
-
cfg.settings;
-
settingsFormat = pkgs.formats.json { };
-
appservicePort = 29328;
-
-
mkDefaults = lib.mapAttrsRecursive (n: v: lib.mkDefault v);
-
defaultConfig = {
-
homeserver.address = "http://localhost:8448";
-
signal = {
-
socket_path = config.services.signald.socketPath;
-
outgoing_attachment_dir = "/var/lib/signald/tmp";
-
};
-
appservice = {
-
hostname = "[::]";
-
port = appservicePort;
-
database.type = "sqlite3";
-
database.uri = "${dataDir}/mautrix-signal.db";
-
id = "signal";
-
bot.username = "signalbot";
-
bot.displayname = "Signal Bridge Bot";
-
as_token = "";
-
hs_token = "";
-
};
-
bridge = {
-
username_template = "signal_{{.}}";
-
double_puppet_server_map = { };
-
login_shared_secret_map = { };
-
permissions."*" = "relay";
-
};
-
logging = {
-
min_level = "info";
-
writers = lib.singleton {
-
type = "stdout";
-
format = "pretty-colored";
-
time_format = " ";
-
};
-
};
-
};
-
-
in {
-
options.services.mautrix-signal = {
-
enable = lib.mkEnableOption (lib.mdDoc
-
"mautrix-signal, a puppeting/relaybot bridge between Matrix and Signal.");
-
-
settings = lib.mkOption {
-
type = settingsFormat.type;
-
default = defaultConfig;
-
description = lib.mdDoc ''
-
{file}`config.yaml` configuration as a Nix attribute set.
-
Configuration options should match those described in
-
[example-config.yaml](https://github.com/mautrix/signal/blob/master/example-config.yaml).
-
'';
-
example = {
-
appservice = {
-
database = {
-
type = "postgres";
-
uri = "postgresql:///mautrix_signal?host=/run/postgresql";
-
};
-
id = "signal";
-
ephemeral_events = false;
-
};
-
bridge = {
-
history_sync = { request_full_sync = true; };
-
private_chat_portal_meta = true;
-
mute_bridging = true;
-
encryption = {
-
allow = true;
-
default = true;
-
require = true;
-
};
-
provisioning = { shared_secret = "disable"; };
-
permissions = { "example.com" = "user"; };
-
};
-
};
-
};
-
-
serviceDependencies = lib.mkOption {
-
type = with lib.types; listOf str;
-
default = lib.optional config.services.matrix-synapse.enable
-
config.services.matrix-synapse.serviceUnit;
-
defaultText = lib.literalExpression ''
-
optional config.services.matrix-synapse.enable config.services.matrix-synapse.serviceUnits
-
'';
-
description = lib.mdDoc ''
-
List of Systemd services to require and wait for when starting the application service.
-
'';
-
};
-
};
-
-
config = lib.mkIf cfg.enable {
-
-
services.signald.enable = true;
-
-
users.users.mautrix-signal = {
-
isSystemUser = true;
-
group = "mautrix-signal";
-
home = dataDir;
-
description = "Mautrix-Signal bridge user";
-
};
-
-
users.groups.mautrix-signal = { };
-
-
services.mautrix-signal.settings = lib.mkMerge (map mkDefaults [
-
defaultConfig
-
# Note: this is defined here to avoid the docs depending on `config`
-
{
-
homeserver.domain = config.services.matrix-synapse.settings.server_name;
-
}
-
]);
-
-
systemd.services.mautrix-signal = {
-
description = "Mautrix-Signal Service - A Signal bridge for Matrix";
-
-
requires = [ "signald.service" ];
-
# voice messages need `ffmpeg`
-
path = [ pkgs.ffmpeg ];
-
-
wantedBy = [ "multi-user.target" ];
-
wants = [ "network-online.target" ] ++ cfg.serviceDependencies;
-
after = [ "network-online.target" "signald.service" ]
-
++ cfg.serviceDependencies;
-
-
preStart = ''
-
# substitute the settings file by environment variables
-
# in this case read from EnvironmentFile
-
test -f '${settingsFile}' && rm -f '${settingsFile}'
-
old_umask=$(umask)
-
umask 0177
-
${pkgs.envsubst}/bin/envsubst \
-
-o '${settingsFile}' \
-
-i '${settingsFileUnsubstituted}'
-
umask $old_umask
-
-
# generate the appservice's registration file if absent
-
if [ ! -f '${registrationFile}' ]; then
-
${pkgs.mautrix-signal}/bin/mautrix-signal \
-
--generate-registration \
-
--config='${settingsFile}' \
-
--registration='${registrationFile}'
-
fi
-
chmod 640 ${registrationFile}
-
-
umask 0177
-
${pkgs.yq}/bin/yq -s '.[0].appservice.as_token = .[1].as_token
-
| .[0].appservice.hs_token = .[1].hs_token
-
| .[0]' '${settingsFile}' '${registrationFile}' \
-
> '${settingsFile}.tmp'
-
mv '${settingsFile}.tmp' '${settingsFile}'
-
umask $old_umask
-
'';
-
-
serviceConfig = {
-
SupplementaryGroups = [ "signald" ];
-
User = "mautrix-signal";
-
Group = "mautrix-signal";
-
StateDirectory = baseNameOf dataDir;
-
WorkingDirectory = dataDir;
-
ExecStart = ''
-
${pkgs.mautrix-signal}/bin/mautrix-signal \
-
--config='${settingsFile}' \
-
--registration='${registrationFile}'
-
'';
-
LockPersonality = true;
-
MemoryDenyWriteExecute = true;
-
NoNewPrivileges = true;
-
PrivateDevices = true;
-
PrivateTmp = true;
-
PrivateUsers = true;
-
ProtectClock = true;
-
ProtectControlGroups = true;
-
ProtectHome = true;
-
ProtectHostname = true;
-
ProtectKernelLogs = true;
-
ProtectKernelModules = true;
-
ProtectKernelTunables = true;
-
ProtectSystem = "strict";
-
Restart = "on-failure";
-
RestartSec = "30s";
-
RestrictRealtime = true;
-
RestrictSUIDSGID = true;
-
SystemCallArchitectures = "native";
-
SystemCallErrorNumber = "EPERM";
-
SystemCallFilter = [ "@system-service" ];
-
Type = "simple";
-
UMask = 27;
-
};
-
restartTriggers = [ settingsFileUnsubstituted ];
-
};
-
};
-
}
+3 -4
modules/matrix/synapse.nix
···
max_upload_size = "100M";
app_service_config_files = (optional cfg.matrix.bridges.whatsapp
"/var/lib/mautrix-whatsapp/whatsapp-registration.yaml")
-
++ (optional cfg.matrix.bridges.signal
-
"/var/lib/mautrix-signal/signal-registration.yaml")
++ (optional cfg.matrix.bridges.instagram
"/var/lib/mautrix-instagram/instagram-registration.yaml")
++ (optional cfg.matrix.bridges.messenger
···
[ "matrix-synapse-turn-shared-secret-generator.service" ];
systemd.services.matrix-synapse.serviceConfig.SupplementaryGroups =
+
# remove after https://github.com/NixOS/nixpkgs/pull/311681/files
(optional cfg.matrix.bridges.whatsapp
config.systemd.services.mautrix-whatsapp.serviceConfig.Group)
-
++ (optional cfg.matrix.bridges.signal
-
config.systemd.services.mautrix-signal.serviceConfig.Group)
++ (optional cfg.matrix.bridges.instagram
config.systemd.services.mautrix-instagram.serviceConfig.Group)
++ (optional cfg.matrix.bridges.messenger
···
settings.bridge.permissions."@${config.eilean.username}:${config.networking.domain}" =
"admin";
};
+
# using https://github.com/NixOS/nixpkgs/pull/277368
services.mautrix-signal = mkIf cfg.matrix.bridges.signal {
enable = true;
settings.homeserver.address =
···
settings.bridge.permissions."@${config.eilean.username}:${config.networking.domain}" =
"admin";
};
+
# TODO replace with upstreamed mautrix-meta
services.mautrix-instagram = mkIf cfg.matrix.bridges.instagram {
enable = true;
settings.homeserver.address =