lol

nixos/unifi: Clean up formatting

This removes "with lib", which advances #208242 a bit, and cleans up a few
formatting nits found by nixfmt.

+28 -29
+28 -29
nixos/modules/services/networking/unifi.nix
··· 1 1 { config, options, lib, pkgs, utils, ... }: 2 - with lib; 3 2 let 4 3 cfg = config.services.unifi; 5 4 stateDir = "/var/lib/unifi"; 6 5 cmd = '' 7 6 @${cfg.jrePackage}/bin/java java \ 8 - ${optionalString (lib.versionAtLeast (lib.getVersion cfg.jrePackage) "16") 7 + ${lib.optionalString (lib.versionAtLeast (lib.getVersion cfg.jrePackage) "16") 9 8 ("--add-opens java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED " 10 9 + "--add-opens java.base/sun.security.util=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED " 11 10 + "--add-opens java.rmi/sun.rmi.transport=ALL-UNNAMED")} \ 12 - ${optionalString (cfg.initialJavaHeapSize != null) "-Xms${(toString cfg.initialJavaHeapSize)}m"} \ 13 - ${optionalString (cfg.maximumJavaHeapSize != null) "-Xmx${(toString cfg.maximumJavaHeapSize)}m"} \ 11 + ${lib.optionalString (cfg.initialJavaHeapSize != null) "-Xms${(toString cfg.initialJavaHeapSize)}m"} \ 12 + ${lib.optionalString (cfg.maximumJavaHeapSize != null) "-Xmx${(toString cfg.maximumJavaHeapSize)}m"} \ 14 13 -jar ${stateDir}/lib/ace.jar 15 14 ''; 16 15 in ··· 18 17 19 18 options = { 20 19 21 - services.unifi.enable = mkOption { 22 - type = types.bool; 20 + services.unifi.enable = lib.mkOption { 21 + type = lib.types.bool; 23 22 default = false; 24 23 description = lib.mdDoc '' 25 24 Whether or not to enable the unifi controller service. 26 25 ''; 27 26 }; 28 27 29 - services.unifi.jrePackage = mkOption { 30 - type = types.package; 28 + services.unifi.jrePackage = lib.mkOption { 29 + type = lib.types.package; 31 30 default = if (lib.versionAtLeast (lib.getVersion cfg.unifiPackage) "7.5") then pkgs.jdk17_headless else if (lib.versionAtLeast (lib.getVersion cfg.unifiPackage) "7.3") then pkgs.jdk11 else pkgs.jre8; 32 - defaultText = literalExpression ''if (lib.versionAtLeast (lib.getVersion cfg.unifiPackage) "7.5") then pkgs.jdk17_headless else if (lib.versionAtLeast (lib.getVersion cfg.unifiPackage) "7.3" then pkgs.jdk11 else pkgs.jre8''; 31 + defaultText = lib.literalExpression ''if (lib.versionAtLeast (lib.getVersion cfg.unifiPackage) "7.5") then pkgs.jdk17_headless else if (lib.versionAtLeast (lib.getVersion cfg.unifiPackage) "7.3" then pkgs.jdk11 else pkgs.jre8''; 33 32 description = lib.mdDoc '' 34 33 The JRE package to use. Check the release notes to ensure it is supported. 35 34 ''; 36 35 }; 37 36 38 - services.unifi.unifiPackage = mkOption { 39 - type = types.package; 37 + services.unifi.unifiPackage = lib.mkOption { 38 + type = lib.types.package; 40 39 default = pkgs.unifi5; 41 - defaultText = literalExpression "pkgs.unifi5"; 40 + defaultText = lib.literalExpression "pkgs.unifi5"; 42 41 description = lib.mdDoc '' 43 42 The unifi package to use. 44 43 ''; 45 44 }; 46 45 47 - services.unifi.mongodbPackage = mkOption { 48 - type = types.package; 46 + services.unifi.mongodbPackage = lib.mkOption { 47 + type = lib.types.package; 49 48 default = pkgs.mongodb-4_4; 50 - defaultText = literalExpression "pkgs.mongodb"; 49 + defaultText = lib.literalExpression "pkgs.mongodb"; 51 50 description = lib.mdDoc '' 52 51 The mongodb package to use. Please note: unifi7 officially only supports mongodb up until 3.6 but works with 4.4. 53 52 ''; 54 53 }; 55 54 56 - services.unifi.openFirewall = mkOption { 57 - type = types.bool; 55 + services.unifi.openFirewall = lib.mkOption { 56 + type = lib.types.bool; 58 57 default = false; 59 58 description = lib.mdDoc '' 60 59 Whether or not to open the minimum required ports on the firewall. ··· 65 64 ''; 66 65 }; 67 66 68 - services.unifi.initialJavaHeapSize = mkOption { 69 - type = types.nullOr types.int; 67 + services.unifi.initialJavaHeapSize = lib.mkOption { 68 + type = with lib.types; nullOr int; 70 69 default = null; 71 70 example = 1024; 72 71 description = lib.mdDoc '' ··· 75 74 ''; 76 75 }; 77 76 78 - services.unifi.maximumJavaHeapSize = mkOption { 79 - type = types.nullOr types.int; 77 + services.unifi.maximumJavaHeapSize = lib.mkOption { 78 + type = with lib.types; nullOr int; 80 79 default = null; 81 80 example = 4096; 82 81 description = lib.mdDoc '' ··· 87 86 88 87 }; 89 88 90 - config = mkIf cfg.enable { 89 + config = lib.mkIf cfg.enable { 91 90 92 91 users.users.unifi = { 93 92 isSystemUser = true; ··· 97 96 }; 98 97 users.groups.unifi = {}; 99 98 100 - networking.firewall = mkIf cfg.openFirewall { 99 + networking.firewall = lib.mkIf cfg.openFirewall { 101 100 # https://help.ubnt.com/hc/en-us/articles/218506997 102 101 allowedTCPPorts = [ 103 102 8080 # Port for UAP to inform controller. ··· 123 122 124 123 serviceConfig = { 125 124 Type = "simple"; 126 - ExecStart = "${(removeSuffix "\n" cmd)} start"; 127 - ExecStop = "${(removeSuffix "\n" cmd)} stop"; 125 + ExecStart = "${(lib.removeSuffix "\n" cmd)} start"; 126 + ExecStop = "${(lib.removeSuffix "\n" cmd)} stop"; 128 127 Restart = "on-failure"; 129 128 TimeoutSec = "5min"; 130 129 User = "unifi"; ··· 166 165 StateDirectory = "unifi"; 167 166 RuntimeDirectory = "unifi"; 168 167 LogsDirectory = "unifi"; 169 - CacheDirectory= "unifi"; 168 + CacheDirectory = "unifi"; 170 169 171 170 TemporaryFileSystem = [ 172 171 # required as we want to create bind mounts below ··· 176 175 # We must create the binary directories as bind mounts instead of symlinks 177 176 # This is because the controller resolves all symlinks to absolute paths 178 177 # to be used as the working directory. 179 - BindPaths = [ 178 + BindPaths = [ 180 179 "/var/log/unifi:${stateDir}/logs" 181 180 "/run/unifi:${stateDir}/run" 182 181 "${cfg.unifiPackage}/dl:${stateDir}/dl" ··· 194 193 195 194 }; 196 195 imports = [ 197 - (mkRemovedOptionModule [ "services" "unifi" "dataDir" ] "You should move contents of dataDir to /var/lib/unifi/data" ) 198 - (mkRenamedOptionModule [ "services" "unifi" "openPorts" ] [ "services" "unifi" "openFirewall" ]) 196 + (lib.mkRemovedOptionModule [ "services" "unifi" "dataDir" ] "You should move contents of dataDir to /var/lib/unifi/data") 197 + (lib.mkRenamedOptionModule [ "services" "unifi" "openPorts" ] [ "services" "unifi" "openFirewall" ]) 199 198 ]; 200 199 }