···46 '';
47 };
4800000000000049 };
5051 config = mkIf cfg.enable {
···56 home = "${stateDir}";
57 };
58000000000000059 # We must create the binary directories as bind mounts instead of symlinks
60 # This is because the controller resolves all symlinks to absolute paths
61 # to be used as the working directory.
···8081 preStart = ''
82 # Ensure privacy of state and data.
83- chown unifi "${stateDir}" "${dataDir}"
84- chmod 0700 "${stateDir}" "${dataDir}"
8586 # Create the volatile webapps
87 rm -rf "${stateDir}/webapps"
···46 '';
47 };
4849+ services.unifi.openPorts = mkOption {
50+ type = types.bool;
51+ default = true;
52+ description = ''
53+ Whether or not to open the minimum required ports on the firewall.
54+55+ This is necessary to allow firmware upgrades and device discovery to
56+ work. For remote login, you should additionally open (or forward) port
57+ 8443.
58+ '';
59+ };
60+61 };
6263 config = mkIf cfg.enable {
···68 home = "${stateDir}";
69 };
7071+ networking.firewall = mkIf cfg.openPorts {
72+ # https://help.ubnt.com/hc/en-us/articles/204910084-UniFi-Change-Default-Ports-for-Controller-and-UAPs
73+ allowedTCPPorts = [
74+ 8080 # Port for UAP to inform controller.
75+ 8880 # Port for HTTP portal redirect, if guest portal is enabled.
76+ 8843 # Port for HTTPS portal redirect, ditto.
77+ ];
78+ allowedUDPPorts = [
79+ 3478 # UDP port used for STUN.
80+ 10001 # UDP port used for device discovery.
81+ ];
82+ };
83+84 # We must create the binary directories as bind mounts instead of symlinks
85 # This is because the controller resolves all symlinks to absolute paths
86 # to be used as the working directory.
···105106 preStart = ''
107 # Ensure privacy of state and data.
108+ chown unifi "${stateDir}" "${stateDir}/data"
109+ chmod 0700 "${stateDir}" "${stateDir}/data"
110111 # Create the volatile webapps
112 rm -rf "${stateDir}/webapps"