1 { config, lib, pkgs, ... }:
4 inherit (lib) getExe mkIf mkOption mkEnableOption types;
6 cfg = config.services.mollysocket;
7 configuration = format.generate "mollysocket.conf" cfg.settings;
8 format = pkgs.formats.toml { };
9 package = pkgs.writeShellScriptBin "mollysocket" ''
10 MOLLY_CONF=${configuration} exec ${getExe pkgs.mollysocket} "$@"
13 options.services.mollysocket = {
14 enable = mkEnableOption ''
15 [MollySocket](https://github.com/mollyim/mollysocket) for getting Signal
16 notifications via UnifiedPush
22 Configuration for MollySocket. Available options are listed
23 [here](https://github.com/mollyim/mollysocket#configuration).
25 type = types.submodule {
26 freeformType = format.type;
29 default = "127.0.0.1";
30 description = "Listening address of the web server";
36 description = "Listening port of the web server";
40 allowed_endpoints = mkOption {
42 description = "List of UnifiedPush servers";
43 example = [ "https://ntfy.sh" ];
44 type = with types; listOf str;
47 allowed_uuids = mkOption {
49 description = "UUIDs of Signal accounts that may use this server";
50 example = [ "abcdef-12345-tuxyz-67890" ];
51 type = with types; listOf str;
57 environmentFile = mkOption {
60 Environment file (see {manpage}`systemd.exec(5)` "EnvironmentFile="
61 section for the syntax) passed to the service. This option can be
62 used to safely include secrets in the configuration.
64 example = "/run/secrets/mollysocket";
65 type = with types; nullOr path;
70 description = "Set the {env}`RUST_LOG` environment variable";
76 config = mkIf cfg.enable {
77 environment.systemPackages = [
81 # see https://github.com/mollyim/mollysocket/blob/main/mollysocket.service
82 systemd.services.mollysocket = {
83 description = "MollySocket";
84 wantedBy = [ "multi-user.target" ];
85 after = [ "network-online.target" ];
86 wants = [ "network-online.target" ];
87 environment.RUST_LOG = cfg.logLevel;
89 EnvironmentFile = cfg.environmentFile;
90 ExecStart = "${getExe package} server";
91 KillSignal = "SIGINT";
92 Restart = "on-failure";
93 StateDirectory = "mollysocket";
95 WorkingDirectory = "/var/lib/mollysocket";
98 DevicePolicy = "closed";
100 LockPersonality = true;
101 MemoryDenyWriteExecute = true;
102 NoNewPrivileges = true;
103 PrivateDevices = true;
108 ProtectControlGroups = true;
110 ProtectHostname = true;
111 ProtectKernelLogs = true;
112 ProtectKernelModules = true;
113 ProtectKernelTunables = true;
114 ProtectProc = "invisible";
115 ProtectSystem = "strict";
117 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
118 RestrictNamespaces = true;
119 RestrictRealtime = true;
120 RestrictSUIDSGID = true;
121 SystemCallArchitectures = "native";
122 SystemCallFilter = [ "@system-service" "~@resources" "~@privileged" ];
128 meta.maintainers = with lib.maintainers; [ dotlambda ];