summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorSimon Lackerbauer <simon@lackerbauer.com>2017-06-26 13:15:03 +0200
committerRobin Gloster <mail@glob.in>2017-08-04 02:12:31 +0200
commit1075919413bcaa1a0ed01ea9b9028276ba0cb313 (patch)
treeb2e9d2b5a5cc75cb8c32102a25e94a6ab9927b94 /nixos
parent3b472d78a846b7ae029bb5192f1be9b5d870f4af (diff)
downloadnixlib-1075919413bcaa1a0ed01ea9b9028276ba0cb313.tar
nixlib-1075919413bcaa1a0ed01ea9b9028276ba0cb313.tar.gz
nixlib-1075919413bcaa1a0ed01ea9b9028276ba0cb313.tar.bz2
nixlib-1075919413bcaa1a0ed01ea9b9028276ba0cb313.tar.lz
nixlib-1075919413bcaa1a0ed01ea9b9028276ba0cb313.tar.xz
nixlib-1075919413bcaa1a0ed01ea9b9028276ba0cb313.tar.zst
nixlib-1075919413bcaa1a0ed01ea9b9028276ba0cb313.zip
unifi: add options to control JVM heap size
Our controller was acting very sluggish at times and increasing
available RAM for the JVM fixes this.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/networking/unifi.nix31
1 files changed, 28 insertions, 3 deletions
diff --git a/nixos/modules/services/networking/unifi.nix b/nixos/modules/services/networking/unifi.nix
index a8cff638d3b2..8e5f0bfc070d 100644
--- a/nixos/modules/services/networking/unifi.nix
+++ b/nixos/modules/services/networking/unifi.nix
@@ -3,7 +3,12 @@ with lib;
 let
   cfg = config.services.unifi;
   stateDir = "/var/lib/unifi";
-  cmd = "@${pkgs.jre}/bin/java java -jar ${stateDir}/lib/ace.jar";
+  cmd = ''
+    @${pkgs.jre}/bin/java java \
+        ${optionalString (cfg.initialJavaHeapSize != null) "-Xms${(toString cfg.initialJavaHeapSize)}m"} \
+        ${optionalString (cfg.maximumJavaHeapSize != null) "-Xmx${(toString cfg.maximumJavaHeapSize)}m"} \
+        -jar ${stateDir}/lib/ace.jar
+  '';
   mountPoints = [
     {
       what = "${pkgs.unifi}/dl";
@@ -58,6 +63,26 @@ in
       '';
     };
 
+    services.unifi.initialJavaHeapSize = mkOption {
+      type = types.nullOr types.int;
+      default = null;
+      example = 1024;
+      description = ''
+        Set the initial heap size for the JVM in MB. If this option isn't set, the
+        JVM will decide this value at runtime.
+      '';
+    };
+
+    services.unifi.maximumJavaHeapSize = mkOption {
+      type = types.nullOr types.int;
+      default = null;
+      example = 4096;
+      description = ''
+        Set the maximimum heap size for the JVM in MB. If this option isn't set, the
+        JVM will decide this value at runtime.
+      '';
+    };
+
   };
 
   config = mkIf cfg.enable {
@@ -121,8 +146,8 @@ in
 
       serviceConfig = {
         Type = "simple";
-        ExecStart = "${cmd} start";
-        ExecStop = "${cmd} stop";
+        ExecStart = "${(removeSuffix "\n" cmd)} start";
+        ExecStop = "${(removeSuffix "\n" cmd)} stop";
         User = "unifi";
         PermissionsStartOnly = true;
         UMask = "0077";