2008-11-18 19:00:15 +01:00
|
|
|
# Disnix server
|
2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2008-07-06 20:34:19 +02:00
|
|
|
|
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
cfg = config.services.disnix;
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2013-06-27 15:32:49 +02:00
|
|
|
dysnomia = pkgs.dysnomia.override (origArgs: {
|
2010-11-01 18:33:54 +01:00
|
|
|
enableApacheWebApplication = config.services.httpd.enable;
|
|
|
|
enableAxis2WebService = config.services.tomcat.axis2.enable;
|
|
|
|
enableEjabberdDump = config.services.ejabberd.enable;
|
|
|
|
enableMySQLDatabase = config.services.mysql.enable;
|
2010-12-22 14:32:51 +01:00
|
|
|
enablePostgreSQLDatabase = config.services.postgresql.enable;
|
|
|
|
enableSubversionRepository = config.services.svnserve.enable;
|
2010-11-01 18:33:54 +01:00
|
|
|
enableTomcatWebApplication = config.services.tomcat.enable;
|
2013-11-07 10:54:53 +01:00
|
|
|
enableMongoDatabase = config.services.mongodb.enable;
|
2010-11-01 18:33:54 +01:00
|
|
|
});
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2008-11-18 19:00:15 +01:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.disnix = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable Disnix";
|
2010-11-01 18:33:54 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-11-01 18:33:54 +01:00
|
|
|
useWebServiceInterface = mkOption {
|
|
|
|
default = false;
|
2012-02-06 23:49:41 +01:00
|
|
|
description = "Whether to enable the DisnixWebService interface running on Apache Tomcat";
|
2010-11-01 18:33:54 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
publishInfrastructure = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
2012-02-06 23:49:41 +01:00
|
|
|
description = "Whether to publish capabilities/properties of this machine in as attributes in the infrastructure option";
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2012-02-06 23:49:41 +01:00
|
|
|
enableAuthentication = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to publish authentication credentials through the infrastructure attribute (not recommended in combination with Avahi)";
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
};
|
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
infrastructure = mkOption {
|
|
|
|
default = {};
|
2012-02-06 23:49:41 +01:00
|
|
|
description = "List of name value pairs containing properties for the infrastructure model";
|
2010-12-10 15:22:00 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-11-21 14:28:48 +01:00
|
|
|
publishAvahi = mkOption {
|
|
|
|
default = false;
|
2012-02-06 23:49:41 +01:00
|
|
|
description = "Whether to publish capabilities/properties as a Disnix service through Avahi";
|
2010-11-21 14:28:48 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-11-18 19:00:15 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2008-11-18 19:00:15 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +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 {
|
2015-06-12 18:18:42 +02:00
|
|
|
environment.systemPackages = [ pkgs.disnix pkgs.dysnomia ] ++ 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"
|
2012-02-06 23:49:41 +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;
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
services.disnix.infrastructure =
|
|
|
|
optionalAttrs (cfg.publishInfrastructure.enable)
|
|
|
|
( { hostname = config.networking.hostName;
|
2012-04-11 15:46:49 +02:00
|
|
|
#targetHost = config.deployment.targetHost;
|
2012-02-06 23:49:41 +01:00
|
|
|
system = if config.nixpkgs.system == "" then builtins.currentSystem else config.nixpkgs.system;
|
|
|
|
|
|
|
|
supportedTypes = (import "${pkgs.stdenv.mkDerivation {
|
|
|
|
name = "supportedtypes";
|
|
|
|
buildCommand = ''
|
|
|
|
( echo -n "[ "
|
2013-06-27 15:32:49 +02:00
|
|
|
cd ${dysnomia}/libexec/dysnomia
|
2012-02-06 23:49:41 +01:00
|
|
|
for i in *
|
|
|
|
do
|
|
|
|
echo -n "\"$i\" "
|
|
|
|
done
|
|
|
|
echo -n " ]") > $out
|
|
|
|
'';
|
|
|
|
}}");
|
2010-12-10 15:22:00 +01:00
|
|
|
}
|
2012-04-11 15:46:49 +02:00
|
|
|
#// optionalAttrs (cfg.useWebServiceInterface) { targetEPR = "http://${config.deployment.targetHost}:8080/DisnixWebService/services/DisnixWebService"; }
|
2010-12-10 15:22:00 +01:00
|
|
|
// 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; }
|
2012-02-06 23:49:41 +01:00
|
|
|
// optionalAttrs (config.services.svnserve.enable) { svnBaseDir = config.services.svnserve.svnBaseDir; }
|
|
|
|
// optionalAttrs (cfg.publishInfrastructure.enableAuthentication) (
|
2013-11-12 13:48:19 +01:00
|
|
|
optionalAttrs (config.services.mysql.enable) { mysqlUsername = "root"; mysqlPassword = readFile config.services.mysql.rootPassword; })
|
2012-02-06 23:49:41 +01:00
|
|
|
)
|
2010-12-10 15:22:00 +01:00
|
|
|
;
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-12-11 00:58:57 +01:00
|
|
|
services.disnix.publishInfrastructure.enable = cfg.publishAvahi;
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
jobs = {
|
|
|
|
disnix =
|
|
|
|
{ description = "Disnix server";
|
2013-06-03 01:34:22 +02:00
|
|
|
|
2015-11-26 18:21:19 +01:00
|
|
|
wants = [ "dysnomia.target" ];
|
2013-06-03 01:34:22 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "dbus.service" ]
|
2013-06-27 15:32:49 +02:00
|
|
|
++ optional config.services.httpd.enable "httpd.service"
|
|
|
|
++ optional config.services.mysql.enable "mysql.service"
|
2014-06-09 23:46:30 +02:00
|
|
|
++ optional config.services.postgresql.enable "postgresql.service"
|
2013-06-27 15:32:49 +02:00
|
|
|
++ optional config.services.tomcat.enable "tomcat.service"
|
2013-11-07 10:54:53 +01:00
|
|
|
++ optional config.services.svnserve.enable "svnserve.service"
|
|
|
|
++ optional config.services.mongodb.enable "mongodb.service";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2012-03-18 03:10:39 +01:00
|
|
|
restartIfChanged = false;
|
2013-06-27 15:32:49 +02:00
|
|
|
|
2015-02-26 18:29:09 +01:00
|
|
|
path = [ pkgs.nix pkgs.disnix dysnomia "/run/current-system/sw" ];
|
2013-11-07 10:54:53 +01:00
|
|
|
|
|
|
|
environment = {
|
|
|
|
HOME = "/root";
|
|
|
|
};
|
2015-11-26 18:21:19 +01:00
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p /etc/systemd-mutable/system
|
|
|
|
if [ ! -f /etc/systemd-mutable/system/dysnomia.target ]
|
|
|
|
then
|
|
|
|
( echo "[Unit]"
|
|
|
|
echo "Description=Services that are activated and deactivated by Dysnomia"
|
|
|
|
echo "After=final.target"
|
|
|
|
) > /etc/systemd-mutable/system/dysnomia.target
|
|
|
|
fi
|
|
|
|
'';
|
2013-11-07 10:54:53 +01:00
|
|
|
|
|
|
|
exec = "disnix-service";
|
2010-12-10 15:22:00 +01:00
|
|
|
};
|
|
|
|
} // optionalAttrs cfg.publishAvahi {
|
|
|
|
disnixAvahi =
|
|
|
|
{ description = "Disnix Avahi publisher";
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-12-10 15:22:00 +01:00
|
|
|
startOn = "started avahi-daemon";
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2012-02-06 23:49:41 +01:00
|
|
|
exec =
|
2010-12-10 15:22:00 +01:00
|
|
|
''
|
2010-12-11 00:58:57 +01:00
|
|
|
${pkgs.avahi}/bin/avahi-publish-service disnix-${config.networking.hostName} _disnix._tcp 22 \
|
2012-02-06 23:49:41 +01:00
|
|
|
"mem=$(grep 'MemTotal:' /proc/meminfo | sed -e 's/kB//' -e 's/MemTotal://' -e 's/ //g')" \
|
|
|
|
${concatMapStrings (infrastructureAttrName:
|
|
|
|
let infrastructureAttrValue = getAttr infrastructureAttrName (cfg.infrastructure);
|
|
|
|
in
|
2013-11-12 13:48:19 +01:00
|
|
|
if isInt infrastructureAttrValue then
|
2012-02-06 23:49:41 +01:00
|
|
|
''${infrastructureAttrName}=${toString infrastructureAttrValue} \
|
|
|
|
''
|
|
|
|
else
|
2010-12-11 00:58:57 +01:00
|
|
|
''${infrastructureAttrName}=\"${infrastructureAttrValue}\" \
|
|
|
|
''
|
2012-02-06 23:49:41 +01:00
|
|
|
) (attrNames (cfg.infrastructure))}
|
2010-12-10 15:22:00 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2008-11-18 19:00:15 +01:00
|
|
|
};
|
2008-07-06 20:34:19 +02:00
|
|
|
}
|