1 { lib, pkgs, config, ... }:
4 inherit (lib) mkEnableOption mkPackageOption mkOption types;
6 cfg = config.services.c2fmzq-server;
9 type = with lib.types; attrsOf (nullOr (oneOf [ bool int str ]));
10 generate = lib.cli.toGNUCommandLineShell {
12 "--${k}=${if v then "true" else "false"}"
17 options.services.c2fmzq-server = {
18 enable = mkEnableOption "c2fmzq-server";
22 default = "127.0.0.1";
23 description = "The local address to use.";
29 description = "The local port to use.";
32 passphraseFile = mkOption {
34 example = "/run/secrets/c2fmzq/pwfile";
35 description = "Path to file containing the database passphrase";
38 package = mkPackageOption pkgs "c2fmzq" { };
41 type = types.submodule {
42 freeformType = argsFormat.type;
48 default = "${cfg.bindIP}:${toString cfg.port}";
53 default = "%S/c2fmzq-server/data";
54 description = "Path of the database";
58 type = types.ints.between 1 3;
60 description = "The level of logging verbosity: 1:Error 2:Info 3:Debug";
65 Configuration for c2FmZQ-server passed as CLI arguments.
66 Run {command}`c2FmZQ-server help` for supported values.
70 allow-new-accounts = true;
71 auto-approve-new-accounts = true;
72 encrypt-metadata = true;
78 config = lib.mkIf cfg.enable {
79 systemd.services.c2fmzq-server = {
80 description = "c2FmZQ-server";
81 documentation = [ "https://github.com/c2FmZQ/c2FmZQ/blob/main/README.md" ];
82 wantedBy = [ "multi-user.target" ];
83 wants = [ "network-online.target" ];
84 after = [ "network.target" "network-online.target" ];
87 ExecStart = "${lib.getExe cfg.package} ${argsFormat.generate cfg.settings}";
88 AmbientCapabilities = "";
89 CapabilityBoundingSet = "";
91 Environment = "C2FMZQ_PASSPHRASE_FILE=%d/passphrase-file";
93 IPAddressAllow = cfg.bindIP;
94 IPAddressDeny = "any";
95 LoadCredential = "passphrase-file:${cfg.passphraseFile}";
96 LockPersonality = true;
97 MemoryDenyWriteExecute = true;
98 NoNewPrivileges = true;
99 PrivateDevices = true;
104 ProtectControlGroups = true;
106 ProtectHostname = true;
107 ProtectKernelLogs = true;
108 ProtectKernelModules = true;
109 ProtectKernelTunables = true;
110 ProtectProc = "invisible";
111 ProtectSystem = "strict";
113 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
114 RestrictNamespaces = true;
115 RestrictRealtime = true;
116 RestrictSUIDSGID = true;
117 SocketBindAllow = cfg.port;
118 SocketBindDeny = "any";
119 StateDirectory = "c2fmzq-server";
120 SystemCallArchitectures = "native";
121 SystemCallFilter = [ "@system-service" "~@privileged @obsolete" ];
127 doc = ./c2fmzq-server.md;
128 maintainers = with lib.maintainers; [ hmenke ];