2008-11-18 10:00:15 -08:00
|
|
|
# Disnix server
|
2009-10-12 09:36:19 -07:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2008-07-06 11:34:19 -07:00
|
|
|
|
|
|
|
let
|
2009-10-12 09:36:19 -07:00
|
|
|
|
|
|
|
cfg = config.services.disnix;
|
2010-11-01 10:33:54 -07:00
|
|
|
|
|
|
|
disnix_activation_scripts = pkgs.disnix_activation_scripts.override (origArgs: {
|
|
|
|
enableApacheWebApplication = config.services.httpd.enable;
|
|
|
|
enableAxis2WebService = config.services.tomcat.axis2.enable;
|
|
|
|
enableEjabberdDump = config.services.ejabberd.enable;
|
|
|
|
enableMySQLDatabase = config.services.mysql.enable;
|
|
|
|
enableTomcatWebApplication = config.services.tomcat.enable;
|
|
|
|
});
|
2009-10-12 09:36:19 -07:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-09-02 03:27:44 -07:00
|
|
|
|
2008-11-18 10:00:15 -08:00
|
|
|
options = {
|
2009-10-12 09:36:19 -07:00
|
|
|
|
|
|
|
services.disnix = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable Disnix";
|
2010-11-01 10:33:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
useWebServiceInterface = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the DisnixWebService interface running on Apache Tomcat";
|
|
|
|
};
|
2010-11-21 05:28:48 -08:00
|
|
|
|
|
|
|
publishAvahi = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to publish capabilities/properties as a Disnix service through Avahi";
|
|
|
|
};
|
2009-10-12 09:36:19 -07:00
|
|
|
|
2008-11-18 10:00:15 -08:00
|
|
|
};
|
2009-10-12 09:36:19 -07:00
|
|
|
|
2008-11-18 10:00:15 -08:00
|
|
|
};
|
2009-10-12 09:36:19 -07:00
|
|
|
|
2008-11-18 10:00:15 -08:00
|
|
|
|
2009-10-12 09:36:19 -07:00
|
|
|
###### implementation
|
2008-11-18 10:00:15 -08:00
|
|
|
|
2009-10-12 09:36:19 -07:00
|
|
|
config = mkIf cfg.enable {
|
2008-07-06 11:34:19 -07:00
|
|
|
|
2010-11-01 21:20:37 -07:00
|
|
|
environment.systemPackages = [ pkgs.disnix ] ++ optional cfg.useWebServiceInterface pkgs.DisnixWebService;
|
2008-11-18 10:00:15 -08:00
|
|
|
|
2009-10-12 09:36:19 -07:00
|
|
|
services.dbus.enable = true;
|
|
|
|
services.dbus.packages = [ pkgs.disnix ];
|
2008-11-18 10:00:15 -08:00
|
|
|
|
2010-11-01 10:33:54 -07:00
|
|
|
services.tomcat.enable = cfg.useWebServiceInterface;
|
2010-11-01 12:01:26 -07:00
|
|
|
services.tomcat.extraGroups = [ "disnix" ];
|
2010-11-01 10:33:54 -07:00
|
|
|
services.tomcat.javaOpts = "${optionalString cfg.useWebServiceInterface "-Djava.library.path=${pkgs.libmatthew_java}/lib/jni"} ";
|
|
|
|
services.tomcat.sharedLibs = []
|
|
|
|
++ optional cfg.useWebServiceInterface "${pkgs.DisnixWebService}/share/java/DisnixConnection.jar"
|
|
|
|
++ optional cfg.useWebServiceInterface "${pkgs.dbus_java}/share/java/dbus.jar";
|
|
|
|
services.tomcat.webapps = [] ++ optional cfg.useWebServiceInterface pkgs.DisnixWebService;
|
|
|
|
|
2010-04-19 06:26:21 -07:00
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = "disnix";
|
|
|
|
gid = config.ids.gids.disnix;
|
|
|
|
};
|
|
|
|
|
2009-10-12 11:09:34 -07:00
|
|
|
jobs.disnix =
|
2009-10-12 09:36:19 -07:00
|
|
|
{ description = "Disnix server";
|
|
|
|
|
2009-11-06 14:19:17 -08:00
|
|
|
startOn = "started dbus";
|
2009-10-12 09:36:19 -07:00
|
|
|
|
|
|
|
script =
|
2010-11-01 10:33:54 -07:00
|
|
|
''
|
2010-11-01 12:01:26 -07:00
|
|
|
export PATH=/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin
|
|
|
|
export HOME=/root
|
|
|
|
|
2010-11-01 10:33:54 -07:00
|
|
|
${pkgs.disnix}/bin/disnix-service --activation-modules-dir=${disnix_activation_scripts}/libexec/disnix/activation-scripts
|
2009-10-12 09:36:19 -07:00
|
|
|
'';
|
|
|
|
};
|
2008-11-22 17:28:58 -08:00
|
|
|
|
2010-11-21 05:28:48 -08:00
|
|
|
} //
|
|
|
|
mkIf cfg.publishAvahi {
|
|
|
|
|
|
|
|
services.avahi.enable = true;
|
|
|
|
|
|
|
|
jobs.disnixAvahi =
|
|
|
|
{ description = "Disnix Avahi publisher";
|
|
|
|
|
|
|
|
startOn = "started avahi-daemon";
|
|
|
|
|
|
|
|
exec =
|
|
|
|
''
|
|
|
|
${pkgs.avahi}/bin/avahi-publish-service disnix-$(${pkgs.nettools}/bin/hostname) _disnix._tcp 22 \
|
|
|
|
"hostname=\"$(${pkgs.nettools}/bin/hostname)\"" \
|
2010-11-24 15:00:52 -08:00
|
|
|
"system=\"$(uname -m)-linux\"" \
|
2010-11-21 05:28:48 -08:00
|
|
|
"mem=$(grep 'MemTotal:' /proc/meminfo | sed -e 's/kB//' -e 's/MemTotal://' -e 's/ //g')" \
|
2010-11-21 08:04:26 -08:00
|
|
|
${optionalString (cfg.useWebServiceInterface) ''"targetEPR=\"http://(${pkgs.nettools}/bin/hostname):8080/DisnixWebService/services/DisnixWebService\""''} \
|
2010-11-21 05:28:48 -08:00
|
|
|
${optionalString (config.services.httpd.enable) ''"documentRoot=\"${config.services.httpd.documentRoot}\""''} \
|
|
|
|
${optionalString (config.services.mysql.enable) ''"mysqlPort=3306"''} \
|
|
|
|
${optionalString (config.services.tomcat.enable) ''"tomcatPort=8080"''} \
|
2010-11-24 15:00:52 -08:00
|
|
|
"supportedTypes=[$(for i in ${disnix_activation_scripts}/libexec/disnix/activation-scripts/*; do echo -n " \"$(basename $i)\""; done) ]" \
|
|
|
|
${concatMapStrings (deploymentAttrName: let deploymentAttrValue = getAttr deploymentAttrName (config.deployment); in ''${deploymentAttrName}=\"${deploymentAttrValue}\" '' ) (attrNames (config.deployment))}
|
2010-11-21 05:28:48 -08:00
|
|
|
'';
|
|
|
|
};
|
2008-11-18 10:00:15 -08:00
|
|
|
};
|
2008-07-06 11:34:19 -07:00
|
|
|
}
|