2008-11-18 19:00:15 +01:00
|
|
|
# Disnix server
|
2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2008-07-06 20:34:19 +02:00
|
|
|
|
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
cfg = config.services.disnix;
|
2010-11-01 18:33:54 +01: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 18:36:19 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-09-02 12:27:44 +02:00
|
|
|
|
2008-11-18 19:00:15 +01:00
|
|
|
options = {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
services.disnix = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable Disnix";
|
2010-11-01 18:33:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
useWebServiceInterface = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the DisnixWebService interface running on Apache Tomcat";
|
|
|
|
};
|
2010-11-21 14:28:48 +01:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
publishInfrastructure = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to publish capabilities/properties of this machine in as attributes in the infrastructure option";
|
|
|
|
};
|
|
|
|
|
|
|
|
enableAuthentication = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to publish authentication credentials through the infrastructure attribute (not recommended in combination with Avahi)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
infrastructure = mkOption {
|
|
|
|
default = {};
|
|
|
|
description = "List of name value pairs containing properties for the infrastructure model";
|
|
|
|
};
|
|
|
|
|
2010-11-21 14:28:48 +01:00
|
|
|
publishAvahi = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to publish capabilities/properties as a Disnix service through Avahi";
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-11-18 19:00:15 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-11-18 19:00:15 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-11-18 19:00:15 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2008-11-18 19:00:15 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = mkIf cfg.enable {
|
2010-11-02 05:20:37 +01:00
|
|
|
environment.systemPackages = [ pkgs.disnix ] ++ optional cfg.useWebServiceInterface pkgs.DisnixWebService;
|
2008-11-18 19:00:15 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.dbus.enable = true;
|
|
|
|
services.dbus.packages = [ pkgs.disnix ];
|
2008-11-18 19:00:15 +01:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
services.avahi.enable = cfg.publishAvahi;
|
|
|
|
|
2010-11-01 18:33:54 +01:00
|
|
|
services.tomcat.enable = cfg.useWebServiceInterface;
|
2010-11-01 20:01:26 +01:00
|
|
|
services.tomcat.extraGroups = [ "disnix" ];
|
2010-11-01 18:33:54 +01:00
|
|
|
services.tomcat.javaOpts = "${optionalString cfg.useWebServiceInterface "-Djava.library.path=${pkgs.libmatthew_java}/lib/jni"} ";
|
2010-12-10 15:22:00 +01:00
|
|
|
services.tomcat.sharedLibs = optional cfg.useWebServiceInterface "${pkgs.DisnixWebService}/share/java/DisnixConnection.jar"
|
2010-11-01 18:33:54 +01:00
|
|
|
++ optional cfg.useWebServiceInterface "${pkgs.dbus_java}/share/java/dbus.jar";
|
2010-12-10 15:22:00 +01:00
|
|
|
services.tomcat.webapps = optional cfg.useWebServiceInterface pkgs.DisnixWebService;
|
2010-11-01 18:33:54 +01:00
|
|
|
|
2010-04-19 15:26:21 +02:00
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = "disnix";
|
|
|
|
gid = config.ids.gids.disnix;
|
|
|
|
};
|
2010-12-10 15:22:00 +01:00
|
|
|
|
|
|
|
services.disnix.infrastructure =
|
|
|
|
optionalAttrs (cfg.publishInfrastructure.enable)
|
|
|
|
( { hostname = config.networking.hostName;
|
|
|
|
targetHost = config.deployment.targetHost;
|
|
|
|
}
|
|
|
|
// optionalAttrs (config.nixpkgs.system != "") { system = config.nixpkgs.system; }
|
|
|
|
// optionalAttrs (cfg.useWebServiceInterface) { targetEPR = "http://${config.deployment.targetHost}:8080/DisnixWebService/services/DisnixWebService"; }
|
|
|
|
// optionalAttrs (config.services.httpd.enable) { documentRoot = config.services.httpd.documentRoot; }
|
|
|
|
// optionalAttrs (config.services.mysql.enable) { mysqlPort = config.services.mysql.port; }
|
|
|
|
// optionalAttrs (config.services.tomcat.enable) { tomcatPort = 8080; }
|
|
|
|
// optionalAttrs (cfg.publishInfrastructure.enableAuthentication) (
|
|
|
|
optionalAttrs (config.services.mysql.enable) { mysqlUsername = "root"; mysqlPassword = builtins.readFile config.services.mysql.rootPassword; })
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
|
|
|
jobs = {
|
|
|
|
disnix =
|
|
|
|
{ description = "Disnix server";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
startOn = "started dbus";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
script =
|
2010-11-01 18:33:54 +01:00
|
|
|
''
|
2010-11-01 20:01:26 +01:00
|
|
|
export PATH=/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin
|
|
|
|
export HOME=/root
|
|
|
|
|
2010-11-01 18:33:54 +01:00
|
|
|
${pkgs.disnix}/bin/disnix-service --activation-modules-dir=${disnix_activation_scripts}/libexec/disnix/activation-scripts
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
2010-12-10 15:22:00 +01:00
|
|
|
};
|
|
|
|
} // optionalAttrs cfg.publishAvahi {
|
|
|
|
disnixAvahi =
|
|
|
|
{ description = "Disnix Avahi publisher";
|
2010-11-21 14:28:48 +01:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
startOn = "started avahi-daemon";
|
2010-11-21 14:28:48 +01:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
exec =
|
|
|
|
''
|
|
|
|
${pkgs.avahi}/bin/avahi-publish-service disnix-$(${pkgs.nettools}/bin/hostname) _disnix._tcp 22 \
|
|
|
|
"hostname=\"$(${pkgs.nettools}/bin/hostname)\"" \
|
|
|
|
"system=\"$(uname -m)-linux\"" \
|
|
|
|
"mem=$(grep 'MemTotal:' /proc/meminfo | sed -e 's/kB//' -e 's/MemTotal://' -e 's/ //g')" \
|
|
|
|
${optionalString (cfg.useWebServiceInterface) ''"targetEPR=\"http://(${pkgs.nettools}/bin/hostname):8080/DisnixWebService/services/DisnixWebService\""''} \
|
|
|
|
${optionalString (config.services.httpd.enable) ''"documentRoot=\"${config.services.httpd.documentRoot}\""''} \
|
|
|
|
${optionalString (config.services.mysql.enable) ''"mysqlPort=3306"''} \
|
|
|
|
${optionalString (config.services.tomcat.enable) ''"tomcatPort=8080"''} \
|
|
|
|
"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))}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2008-11-18 19:00:15 +01:00
|
|
|
};
|
2008-07-06 20:34:19 +02:00
|
|
|
}
|