diff options
author | Eric Litak <elitak@gmail.com> | 2016-03-29 05:27:51 -0700 |
---|---|---|
committer | Eric Litak <elitak@gmail.com> | 2016-04-01 02:45:11 -0700 |
commit | 0de2d2fbcdcea47292662d2509f5d06c81288e48 (patch) | |
tree | a5c3854bb3da98c8e590a5f384128a039a217382 /nixos | |
parent | f1beff232dc734e909f089f79b630420b20e795a (diff) | |
download | nixlib-0de2d2fbcdcea47292662d2509f5d06c81288e48.tar nixlib-0de2d2fbcdcea47292662d2509f5d06c81288e48.tar.gz nixlib-0de2d2fbcdcea47292662d2509f5d06c81288e48.tar.bz2 nixlib-0de2d2fbcdcea47292662d2509f5d06c81288e48.tar.lz nixlib-0de2d2fbcdcea47292662d2509f5d06c81288e48.tar.xz nixlib-0de2d2fbcdcea47292662d2509f5d06c81288e48.tar.zst nixlib-0de2d2fbcdcea47292662d2509f5d06c81288e48.zip |
mfi: init at 2.1.11
This package has some outdated dependencies, so old versions of mongodb and v8 had to be re-added as well.
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/misc/ids.nix | 2 | ||||
-rw-r--r-- | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/services/networking/mfi.nix | 90 |
3 files changed, 93 insertions, 0 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index 2b5008b9ca8f..1e14fe655fc0 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -258,6 +258,7 @@ hydra-queue-runner = 235; hydra-www = 236; syncthing = 237; + mfi = 238; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! @@ -487,6 +488,7 @@ octoprint = 230; radicale = 234; syncthing = 237; + #mfi = 238; # unused # When adding a gid, make sure it doesn't match an existing # uid. Users and groups with the same name should have equal diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 9462d72996fc..f5352eb6ed0f 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -333,6 +333,7 @@ ./services/networking/lambdabot.nix ./services/networking/libreswan.nix ./services/networking/mailpile.nix + ./services/networking/mfi.nix ./services/networking/mjpg-streamer.nix ./services/networking/minidlna.nix ./services/networking/miniupnpd.nix diff --git a/nixos/modules/services/networking/mfi.nix b/nixos/modules/services/networking/mfi.nix new file mode 100644 index 000000000000..5afb83ed022f --- /dev/null +++ b/nixos/modules/services/networking/mfi.nix @@ -0,0 +1,90 @@ +{ config, lib, pkgs, utils, ... }: +with lib; +let + name = "Ubiquiti mFi Controller"; + cfg = config.services.mfi; + stateDir = "/var/lib/mfi"; + # XXX 2 runtime exceptions using jre8: JSPException on GET / ; can't initialize ./data/keystore on first run. + cmd = "@${pkgs.jre7}/bin/java java -jar ${stateDir}/lib/ace.jar"; + mountPoints = [ + { what = "${pkgs.mfi}/dl"; where = "${stateDir}/dl"; } + { what = "${pkgs.mfi}/lib"; where = "${stateDir}/lib"; } + { what = "${pkgs.mongodb248}/bin"; where = "${stateDir}/bin"; } + ]; + systemdMountPoints = map (m: "${utils.escapeSystemdPath m.where}.mount") mountPoints; + ports = [ 6080 6880 6443 6843 ]; +in +{ + options = { + services.mfi = { + enable = mkEnableOption name; + openPorts = mkOption { + type = types.bool; + default = true; + description = "Whether to open TCP ports ${concatMapStrings (a: "${toString a} ") ports}for the services."; + }; + }; + }; + + config = mkIf cfg.enable { + + networking.firewall.allowedTCPPorts = mkIf config.services.mfi.openPorts ports; + + users.users.mfi = { + uid = config.ids.uids.mfi; + description = "mFi controller daemon user"; + home = "${stateDir}"; + }; + + # 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 = [ "mfi.service" ]; + partOf = [ "mfi.service" ]; + unitConfig.RequiresMountsFor = stateDir; + options = "bind"; + what = what; + where = where; + }) mountPoints; + + systemd.services.mfi = { + description = "mFi controller daemon"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ] ++ systemdMountPoints; + partOf = systemdMountPoints; + bindsTo = systemdMountPoints; + unitConfig.RequiresMountsFor = stateDir; + + preStart = '' + # Clear ./webapps each run. + rm -rf "${stateDir}/webapps" + mkdir -p "${stateDir}/webapps" + ln -s "${pkgs.mfi}/webapps/ROOT.war" "${stateDir}/webapps" + + # Copy initial config only once. + test -e "${stateDir}/conf" || cp -ar "${pkgs.mfi}/conf" "${stateDir}/conf" + test -e "${stateDir}/data" || cp -ar "${pkgs.mfi}/data" "${stateDir}/data" + + # Fix Permissions. + # (Bind-mounts cause errors; ignore exit codes) + chown -fR mfi: "${stateDir}" || true + chmod -fR u=rwX,go= "${stateDir}" || true + ''; + + postStop = '' + rm -rf "${stateDir}/webapps" + ''; + + serviceConfig = { + Type = "simple"; + ExecStart = "${cmd} start"; + ExecStop = "${cmd} stop"; + User = "mfi"; + PermissionsStartOnly = true; + UMask = "0077"; + WorkingDirectory = "${stateDir}"; + }; + }; + }; +} |