···4646 '';
4747 };
48484949+ services.unifi.openPorts = mkOption {
5050+ type = types.bool;
5151+ default = true;
5252+ description = ''
5353+ Whether or not to open the minimum required ports on the firewall.
5454+5555+ This is necessary to allow firmware upgrades and device discovery to
5656+ work. For remote login, you should additionally open (or forward) port
5757+ 8443.
5858+ '';
5959+ };
6060+4961 };
50625163 config = mkIf cfg.enable {
···5668 home = "${stateDir}";
5769 };
58707171+ networking.firewall = mkIf cfg.openPorts {
7272+ # https://help.ubnt.com/hc/en-us/articles/204910084-UniFi-Change-Default-Ports-for-Controller-and-UAPs
7373+ allowedTCPPorts = [
7474+ 8080 # Port for UAP to inform controller.
7575+ 8880 # Port for HTTP portal redirect, if guest portal is enabled.
7676+ 8843 # Port for HTTPS portal redirect, ditto.
7777+ ];
7878+ allowedUDPPorts = [
7979+ 3478 # UDP port used for STUN.
8080+ 10001 # UDP port used for device discovery.
8181+ ];
8282+ };
8383+5984 # We must create the binary directories as bind mounts instead of symlinks
6085 # This is because the controller resolves all symlinks to absolute paths
6186 # to be used as the working directory.
···8010581106 preStart = ''
82107 # Ensure privacy of state and data.
8383- chown unifi "${stateDir}" "${dataDir}"
8484- chmod 0700 "${stateDir}" "${dataDir}"
108108+ chown unifi "${stateDir}" "${stateDir}/data"
109109+ chmod 0700 "${stateDir}" "${stateDir}/data"
8511086111 # Create the volatile webapps
87112 rm -rf "${stateDir}/webapps"