From 0652ee16e4ad122853dfd3dfa9dd14a80c8910b7 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 5 Aug 2014 16:00:10 -0500 Subject: [PATCH 1/5] unifi: Add derivation --- pkgs/servers/unifi/default.nix | 31 +++++++++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 pkgs/servers/unifi/default.nix diff --git a/pkgs/servers/unifi/default.nix b/pkgs/servers/unifi/default.nix new file mode 100644 index 000000000000..43162e4ca290 --- /dev/null +++ b/pkgs/servers/unifi/default.nix @@ -0,0 +1,31 @@ +{ stdenv, fetchurl, unzip }: + +stdenv.mkDerivation rec { + name = "unifi-controller-${version}"; + version = "3.2.1"; + + src = fetchurl { + url = "http://dl.ubnt.com/unifi/${version}/UniFi.unix.zip"; + sha256 = "0x7s5k9wxkw0rcs4c2mdrmmjpcfmbh5pvvpj8brrwnkgx072n53c"; + }; + + buildInputs = [ unzip ]; + + doConfigure = false; + + buildPhase = '' + rm -rf bin conf readme.txt + ''; + + installPhase = '' + mkdir -p $out + cp -ar * $out + ''; + + meta = with stdenv.lib; { + homepage = http://www.ubnt.com/; + description = "Controller for Ubiquiti UniFi accesspoints"; + license = licenses.unfree; + platforms = platforms.unix; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 463027b2ac50..3568e4a638d0 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7015,6 +7015,8 @@ let axis2 = callPackage ../servers/http/tomcat/axis2 { }; + unifi = callPackage ../servers/unifi { }; + virtuoso6 = callPackage ../servers/sql/virtuoso/6.x.nix { }; virtuoso7 = callPackage ../servers/sql/virtuoso/7.x.nix { }; From dfb596b49b24e09a6123ab901ded50210d322b17 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 5 Aug 2014 16:00:30 -0500 Subject: [PATCH 2/5] nixos/unifi: Add service module --- nixos/modules/misc/ids.nix | 1 + nixos/modules/module-list.nix | 1 + nixos/modules/services/networking/unifi.nix | 87 +++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 nixos/modules/services/networking/unifi.nix diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index 4ba81dadb315..853efcc09dc1 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -138,6 +138,7 @@ znc = 128; polipo = 129; mopidy = 130; + unifi = 131; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 2cbda50ba29d..ea647b43c9d2 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -233,6 +233,7 @@ ./services/networking/teamspeak3.nix ./services/networking/tftpd.nix ./services/networking/unbound.nix + ./services/networking/unifi.nix ./services/networking/vsftpd.nix ./services/networking/wakeonlan.nix ./services/networking/websockify.nix diff --git a/nixos/modules/services/networking/unifi.nix b/nixos/modules/services/networking/unifi.nix new file mode 100644 index 000000000000..cc9e2b934713 --- /dev/null +++ b/nixos/modules/services/networking/unifi.nix @@ -0,0 +1,87 @@ +{ config, lib, pkgs, ... }: +with lib; +let + cfg = config.services.unifi; + stateDir = "/var/lib/unifi"; + cmd = "@${pkgs.icedtea7_jre}/bin/java java -jar ${stateDir}/lib/ace.jar"; +in +{ + + options = { + + services.unifi.enable = mkOption { + type = types.uniq types.bool; + default = false; + description = '' + Whether or not to enable the unifi controller service. + ''; + }; + + }; + + config = mkIf cfg.enable { + + users.extraUsers.unifi = { + uid = config.ids.uids.unifi; + description = "UniFi controller daemon user"; + home = "${stateDir}"; + }; + + systemd.mounts = [ + { + unitConfig.StopWhenUnneeded = true; + requiredBy = [ "unifi.service" ]; + what = "${pkgs.unifi}/dl"; + where = "${stateDir}/dl"; + options = "bind"; + } + { + unitConfig.StopWhenUnneeded = true; + requiredBy = [ "unifi.service" ]; + what = "${pkgs.unifi}/lib"; + where = "${stateDir}/lib"; + options = "bind"; + } + { + unitConfig.StopWhenUnneeded = true; + requiredBy = [ "unifi.service" ]; + what = "${pkgs.mongodb}/bin"; + where = "${stateDir}/bin"; + options = "bind"; + } + ]; + + systemd.services.unifi = { + description = "UniFi controller daemon"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + preStart = '' + # Ensure privacy of state + chown unifi "${stateDir}" + chmod 0700 "${stateDir}" + + # Create the volatile webapps + mkdir -p "${stateDir}/webapps" + chown unifi "${stateDir}/webapps" + ln -s "${pkgs.unifi}/webapps/ROOT.war" "${stateDir}/webapps/ROOT.war" + ''; + + postStop = '' + rm "${stateDir}/webapps/ROOT.war" + ''; + + serviceConfig = { + Type = "simple"; + ExecStart = "${cmd} start"; + ExecStop = "${cmd} stop"; + User = "unifi"; + PermissionsStartOnly = true; + UMask = "0077"; + WorkingDirectory = "${stateDir}"; + }; + }; + + }; + +} From ede3e60a3c0b01b50d8a9ecc3c991f8f0208e8f0 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 5 Aug 2014 21:47:55 -0500 Subject: [PATCH 3/5] unifi: Add wkennington as a maintainer --- lib/maintainers.nix | 1 + pkgs/servers/unifi/default.nix | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/maintainers.nix b/lib/maintainers.nix index a4386b067b52..9c81ef6a37ec 100644 --- a/lib/maintainers.nix +++ b/lib/maintainers.nix @@ -108,6 +108,7 @@ winden = "Antonio Vargas Gonzalez "; wizeman = "Ricardo M. Correia "; wjlroe = "William Roe "; + wkennington = "William A. Kennington III "; wmertens = "Wout Mertens "; z77z = "Marco Maggesi "; zef = "Zef Hemel "; diff --git a/pkgs/servers/unifi/default.nix b/pkgs/servers/unifi/default.nix index 43162e4ca290..8aa15ee9f82f 100644 --- a/pkgs/servers/unifi/default.nix +++ b/pkgs/servers/unifi/default.nix @@ -27,5 +27,6 @@ stdenv.mkDerivation rec { description = "Controller for Ubiquiti UniFi accesspoints"; license = licenses.unfree; platforms = platforms.unix; + maintainers = with maintainers; [ wkennington ]; }; } From 12ad29226c4186e1e3a8633061e61a651a36a4a5 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 5 Aug 2014 22:09:15 -0500 Subject: [PATCH 4/5] nixos/unifi: Fix ordering of mount rules --- nixos/modules/services/networking/unifi.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/networking/unifi.nix b/nixos/modules/services/networking/unifi.nix index cc9e2b934713..b6f957ddde84 100644 --- a/nixos/modules/services/networking/unifi.nix +++ b/nixos/modules/services/networking/unifi.nix @@ -29,22 +29,25 @@ in systemd.mounts = [ { - unitConfig.StopWhenUnneeded = true; + bindsTo = [ "unifi.service" ]; requiredBy = [ "unifi.service" ]; + before = [ "unifi.service" ]; what = "${pkgs.unifi}/dl"; where = "${stateDir}/dl"; options = "bind"; } { - unitConfig.StopWhenUnneeded = true; + bindsTo = [ "unifi.service" ]; requiredBy = [ "unifi.service" ]; + before = [ "unifi.service" ]; what = "${pkgs.unifi}/lib"; where = "${stateDir}/lib"; options = "bind"; } { - unitConfig.StopWhenUnneeded = true; + bindsTo = [ "unifi.service" ]; requiredBy = [ "unifi.service" ]; + before = [ "unifi.service" ]; what = "${pkgs.mongodb}/bin"; where = "${stateDir}/bin"; options = "bind"; From 377454ff0ef8f2e643f37edb953760e0dc1503f4 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 5 Aug 2014 23:15:49 -0500 Subject: [PATCH 5/5] nixos/unifi: Explain and simplify the bind mount configuration --- nixos/modules/services/networking/unifi.nix | 42 ++++++++++----------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/nixos/modules/services/networking/unifi.nix b/nixos/modules/services/networking/unifi.nix index b6f957ddde84..634f760328f7 100644 --- a/nixos/modules/services/networking/unifi.nix +++ b/nixos/modules/services/networking/unifi.nix @@ -27,32 +27,30 @@ in home = "${stateDir}"; }; - systemd.mounts = [ - { + # We must create the binary directories as bind mounts instead of symlinks + # This is because the controller resolves all symlinks to absolute paths + # to be used as the working directory. + systemd.mounts = map ({ what, where }: { bindsTo = [ "unifi.service" ]; requiredBy = [ "unifi.service" ]; before = [ "unifi.service" ]; - what = "${pkgs.unifi}/dl"; - where = "${stateDir}/dl"; options = "bind"; - } - { - bindsTo = [ "unifi.service" ]; - requiredBy = [ "unifi.service" ]; - before = [ "unifi.service" ]; - what = "${pkgs.unifi}/lib"; - where = "${stateDir}/lib"; - options = "bind"; - } - { - bindsTo = [ "unifi.service" ]; - requiredBy = [ "unifi.service" ]; - before = [ "unifi.service" ]; - what = "${pkgs.mongodb}/bin"; - where = "${stateDir}/bin"; - options = "bind"; - } - ]; + what = what; + where = where; + }) [ + { + what = "${pkgs.unifi}/dl"; + where = "${stateDir}/dl"; + } + { + what = "${pkgs.unifi}/lib"; + where = "${stateDir}/lib"; + } + { + what = "${pkgs.mongodb}/bin"; + where = "${stateDir}/bin"; + } + ]; systemd.services.unifi = { description = "UniFi controller daemon";