1 { config, lib, pkgs, ... }:
6 cfg = config.services.uptermd;
11 enable = mkEnableOption "uptermd";
13 openFirewall = mkOption {
17 Whether to open the firewall for the port in {option}`services.uptermd.port`.
25 Port the server will listen on.
29 listenAddress = mkOption {
32 example = "127.0.0.1";
34 Address the server will listen on.
39 type = types.nullOr types.path;
41 example = "/run/keys/upterm_host_ed25519_key";
43 Path to SSH host key. If not defined, an ed25519 keypair is generated automatically.
47 extraFlags = mkOption {
48 type = types.listOf types.str;
50 example = [ "--debug" ];
52 Extra flags passed to the uptermd command.
58 config = mkIf cfg.enable {
59 networking.firewall = mkIf cfg.openFirewall {
60 allowedTCPPorts = [ cfg.port ];
63 systemd.services.uptermd = {
64 description = "Upterm Daemon";
65 wantedBy = [ "multi-user.target" ];
66 after = [ "network.target" ];
68 path = [ pkgs.openssh ];
70 preStart = mkIf (cfg.hostKey == null) ''
71 if ! [ -f ssh_host_ed25519_key ]; then
74 -f ssh_host_ed25519_key \
80 StateDirectory = "uptermd";
81 WorkingDirectory = "/var/lib/uptermd";
82 ExecStart = "${pkgs.upterm}/bin/uptermd --ssh-addr ${cfg.listenAddress}:${toString cfg.port} --private-key ${if cfg.hostKey == null then "ssh_host_ed25519_key" else cfg.hostKey} ${concatStringsSep " " cfg.extraFlags}";
85 AmbientCapabilities = mkIf (cfg.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
86 CapabilityBoundingSet = mkIf (cfg.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
87 PrivateUsers = cfg.port >= 1024;
89 LockPersonality = true;
90 MemoryDenyWriteExecute = true;
91 PrivateDevices = true;
93 ProtectControlGroups = true;
95 ProtectHostname = true;
96 ProtectKernelLogs = true;
97 ProtectKernelModules = true;
98 ProtectKernelTunables = true;
99 ProtectProc = "invisible";
100 # AF_UNIX is for ssh-keygen, which relies on nscd to resolve the uid to a user
101 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
102 RestrictNamespaces = true;
103 RestrictRealtime = true;
104 SystemCallArchitectures = "native";
105 SystemCallFilter = "@system-service";