|
| 1 | +{ lib, pkgs, config, options, ... |
| 2 | +}: |
| 3 | +let |
| 4 | + cfg = config.services.discussd; |
| 5 | + athena-pkgs = import ../pkgs { inherit pkgs; }; |
| 6 | +in |
| 7 | +{ |
| 8 | + options.services.discussd = (let |
| 9 | + mkOption = lib.mkOption; |
| 10 | + mkEnableOption = lib.mkEnableOption; |
| 11 | + types = lib.types; |
| 12 | + in { |
| 13 | + enable = mkEnableOption "discussd"; |
| 14 | + openFirewall = mkOption { |
| 15 | + description = "open firewall for discuss (if service enabled)"; |
| 16 | + default = true; |
| 17 | + type = types.bool; |
| 18 | + }; |
| 19 | + }); |
| 20 | + |
| 21 | + config = lib.mkIf cfg.enable { |
| 22 | + users.groups.discuss = { }; |
| 23 | + users.users.discuss = { |
| 24 | + description = "Discuss server"; |
| 25 | + isSystemUser = true; |
| 26 | + group = "discuss"; |
| 27 | + }; |
| 28 | + |
| 29 | + # systemd unit |
| 30 | + systemd.services."discussd@" = { |
| 31 | + description = "Discuss server"; |
| 32 | + documentation = [ "man:discussd(8)" ]; |
| 33 | + requires = [ "discussd.socket" ]; |
| 34 | + serviceConfig = { |
| 35 | + #Type = "simple"; |
| 36 | + #NotifyAccess = "main"; |
| 37 | + #Restart = "always"; |
| 38 | + User = "discuss"; |
| 39 | + StandardInput = "socket"; |
| 40 | + PrivateTmp = true; |
| 41 | + PrivateUsers = true; |
| 42 | + ExecStart = "${athena-pkgs.discuss}/sbin/discussd"; |
| 43 | + }; |
| 44 | + }; |
| 45 | + systemd.sockets.discussd = { |
| 46 | + description = "discussd listening socket"; |
| 47 | + documentation = [ "man:discussd(8)" ]; |
| 48 | + socketConfig = { |
| 49 | + ListenStream = 2100; |
| 50 | + Accept = true; |
| 51 | + }; |
| 52 | + wantedBy= [ "sockets.target" ]; |
| 53 | + }; |
| 54 | + networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [2100]; |
| 55 | + }; |
| 56 | +} |
0 commit comments