From df3566c9560b3305bd33faf4bc7580dc55f4f71e Mon Sep 17 00:00:00 2001 From: Badi Abdul-Wahid Date: Sun, 25 Mar 2018 16:49:54 -0400 Subject: [PATCH] unifi, nixos/unifi: support LTS (5.6.36) and release (5.7.20) Ubiquiti has both a LTS and current version of their Unifi controller software. The latter adds new features, but may drop support for some devices. This adds the capability to use either for the unifi module but defaults to the LTS version, which was the previous behavior. --- nixos/modules/services/networking/unifi.nix | 37 ++++++++++++++++++--- pkgs/servers/unifi/default.nix | 28 ++++++++++++---- pkgs/top-level/all-packages.nix | 1 + 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/nixos/modules/services/networking/unifi.nix b/nixos/modules/services/networking/unifi.nix index 8e5f0bfc070d..94958bfdd83e 100644 --- a/nixos/modules/services/networking/unifi.nix +++ b/nixos/modules/services/networking/unifi.nix @@ -4,22 +4,22 @@ let cfg = config.services.unifi; stateDir = "/var/lib/unifi"; cmd = '' - @${pkgs.jre}/bin/java java \ + @${cfg.jrePackage}/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"; + what = "${cfg.unifiPackage}/dl"; where = "${stateDir}/dl"; } { - what = "${pkgs.unifi}/lib"; + what = "${cfg.unifiPackage}/lib"; where = "${stateDir}/lib"; } { - what = "${pkgs.mongodb}/bin"; + what = "${cfg.mongodbPackage}/bin"; where = "${stateDir}/bin"; } { @@ -41,6 +41,33 @@ in ''; }; + services.unifi.jrePackage = mkOption { + type = types.package; + default = pkgs.jre8; + defaultText = "pkgs.jre8"; + description = '' + The JRE package to use. Check the release notes to ensure it is supported. + ''; + }; + + services.unifi.unifiPackage = mkOption { + type = types.package; + default = pkgs.unifiLTS; + defaultText = "pkgs.unifiLTS"; + description = '' + The unifi package to use. + ''; + }; + + services.unifi.mongodbPackage = mkOption { + type = types.package; + default = pkgs.mongodb; + defaultText = "pkgs.mongodb"; + description = '' + The mongodb package to use. + ''; + }; + services.unifi.dataDir = mkOption { type = types.str; default = "${stateDir}/data"; @@ -137,7 +164,7 @@ in rm -rf "${stateDir}/webapps" mkdir -p "${stateDir}/webapps" chown unifi "${stateDir}/webapps" - ln -s "${pkgs.unifi}/webapps/ROOT" "${stateDir}/webapps/ROOT" + ln -s "${cfg.unifiPackage}/webapps/ROOT" "${stateDir}/webapps/ROOT" ''; postStop = '' diff --git a/pkgs/servers/unifi/default.nix b/pkgs/servers/unifi/default.nix index e9d2fd07dc56..dac4bf6899a1 100644 --- a/pkgs/servers/unifi/default.nix +++ b/pkgs/servers/unifi/default.nix @@ -2,21 +2,37 @@ , dpkg , fetchurl , unzip +, useLTS ? false }: -stdenv.mkDerivation rec { - name = "unifi-controller-${version}"; - version = "5.6.36"; - src = fetchurl { +let + versions = { + stable = { + version = "5.7.20"; + sha256 = "1ylj4i5mcv6z9n32275ccdf1rqk74zilqsih3r6xzhm30pxrd8dd"; + }; + lts = { + version = "5.6.36"; + sha256 = "075q7vm56fdsjwh72y2cb1pirl2pxdkvqnhvd3bf1c2n64mvp6bi"; + }; + }; + selectedVersion = + let attr = if useLTS then "lts" else "stable"; + in versions."${attr}"; +in + +stdenv.mkDerivation { + name = "unifi-controller-${selectedVersion.version}"; + src = with selectedVersion; fetchurl { url = "https://dl.ubnt.com/unifi/${version}/unifi_sysvinit_all.deb"; - sha256 = "075q7vm56fdsjwh72y2cb1pirl2pxdkvqnhvd3bf1c2n64mvp6bi"; + inherit sha256; }; buildInputs = [ dpkg ]; unpackPhase = '' - dpkg-deb -x ${src} ./ + dpkg-deb -x $src ./ ''; doConfigure = false; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2bd29155a977..ef5a7c1d8ba9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -12909,6 +12909,7 @@ with pkgs; axis2 = callPackage ../servers/http/tomcat/axis2 { }; unifi = callPackage ../servers/unifi { }; + unifiLTS = callPackage ../servers/unifi { useLTS=true; }; virtuoso6 = callPackage ../servers/sql/virtuoso/6.x.nix { };