at 15.09-beta 6.2 kB view raw
1# Disnix server 2{ config, lib, pkgs, ... }: 3 4with lib; 5 6let 7 8 cfg = config.services.disnix; 9 10 dysnomia = pkgs.dysnomia.override (origArgs: { 11 enableApacheWebApplication = config.services.httpd.enable; 12 enableAxis2WebService = config.services.tomcat.axis2.enable; 13 enableEjabberdDump = config.services.ejabberd.enable; 14 enableMySQLDatabase = config.services.mysql.enable; 15 enablePostgreSQLDatabase = config.services.postgresql.enable; 16 enableSubversionRepository = config.services.svnserve.enable; 17 enableTomcatWebApplication = config.services.tomcat.enable; 18 enableMongoDatabase = config.services.mongodb.enable; 19 }); 20in 21 22{ 23 24 ###### interface 25 26 options = { 27 28 services.disnix = { 29 30 enable = mkOption { 31 default = false; 32 description = "Whether to enable Disnix"; 33 }; 34 35 useWebServiceInterface = mkOption { 36 default = false; 37 description = "Whether to enable the DisnixWebService interface running on Apache Tomcat"; 38 }; 39 40 publishInfrastructure = { 41 enable = mkOption { 42 default = false; 43 description = "Whether to publish capabilities/properties of this machine in as attributes in the infrastructure option"; 44 }; 45 46 enableAuthentication = mkOption { 47 default = false; 48 description = "Whether to publish authentication credentials through the infrastructure attribute (not recommended in combination with Avahi)"; 49 }; 50 }; 51 52 infrastructure = mkOption { 53 default = {}; 54 description = "List of name value pairs containing properties for the infrastructure model"; 55 }; 56 57 publishAvahi = mkOption { 58 default = false; 59 description = "Whether to publish capabilities/properties as a Disnix service through Avahi"; 60 }; 61 62 }; 63 64 }; 65 66 67 ###### implementation 68 69 config = mkIf cfg.enable { 70 environment.systemPackages = [ pkgs.disnix pkgs.dysnomia ] ++ optional cfg.useWebServiceInterface pkgs.DisnixWebService; 71 72 services.dbus.enable = true; 73 services.dbus.packages = [ pkgs.disnix ]; 74 75 services.avahi.enable = cfg.publishAvahi; 76 77 services.tomcat.enable = cfg.useWebServiceInterface; 78 services.tomcat.extraGroups = [ "disnix" ]; 79 services.tomcat.javaOpts = "${optionalString cfg.useWebServiceInterface "-Djava.library.path=${pkgs.libmatthew_java}/lib/jni"} "; 80 services.tomcat.sharedLibs = optional cfg.useWebServiceInterface "${pkgs.DisnixWebService}/share/java/DisnixConnection.jar" 81 ++ optional cfg.useWebServiceInterface "${pkgs.dbus_java}/share/java/dbus.jar"; 82 services.tomcat.webapps = optional cfg.useWebServiceInterface pkgs.DisnixWebService; 83 84 users.extraGroups = singleton 85 { name = "disnix"; 86 gid = config.ids.gids.disnix; 87 }; 88 89 services.disnix.infrastructure = 90 optionalAttrs (cfg.publishInfrastructure.enable) 91 ( { hostname = config.networking.hostName; 92 #targetHost = config.deployment.targetHost; 93 system = if config.nixpkgs.system == "" then builtins.currentSystem else config.nixpkgs.system; 94 95 supportedTypes = (import "${pkgs.stdenv.mkDerivation { 96 name = "supportedtypes"; 97 buildCommand = '' 98 ( echo -n "[ " 99 cd ${dysnomia}/libexec/dysnomia 100 for i in * 101 do 102 echo -n "\"$i\" " 103 done 104 echo -n " ]") > $out 105 ''; 106 }}"); 107 } 108 #// optionalAttrs (cfg.useWebServiceInterface) { targetEPR = "http://${config.deployment.targetHost}:8080/DisnixWebService/services/DisnixWebService"; } 109 // optionalAttrs (config.services.httpd.enable) { documentRoot = config.services.httpd.documentRoot; } 110 // optionalAttrs (config.services.mysql.enable) { mysqlPort = config.services.mysql.port; } 111 // optionalAttrs (config.services.tomcat.enable) { tomcatPort = 8080; } 112 // optionalAttrs (config.services.svnserve.enable) { svnBaseDir = config.services.svnserve.svnBaseDir; } 113 // optionalAttrs (cfg.publishInfrastructure.enableAuthentication) ( 114 optionalAttrs (config.services.mysql.enable) { mysqlUsername = "root"; mysqlPassword = readFile config.services.mysql.rootPassword; }) 115 ) 116 ; 117 118 services.disnix.publishInfrastructure.enable = cfg.publishAvahi; 119 120 jobs = { 121 disnix = 122 { description = "Disnix server"; 123 124 wantedBy = [ "multi-user.target" ]; 125 after = [ "dbus.service" ] 126 ++ optional config.services.httpd.enable "httpd.service" 127 ++ optional config.services.mysql.enable "mysql.service" 128 ++ optional config.services.postgresql.enable "postgresql.service" 129 ++ optional config.services.tomcat.enable "tomcat.service" 130 ++ optional config.services.svnserve.enable "svnserve.service" 131 ++ optional config.services.mongodb.enable "mongodb.service"; 132 133 restartIfChanged = false; 134 135 path = [ pkgs.nix pkgs.disnix dysnomia "/run/current-system/sw" ]; 136 137 environment = { 138 HOME = "/root"; 139 }; 140 141 exec = "disnix-service"; 142 }; 143 } // optionalAttrs cfg.publishAvahi { 144 disnixAvahi = 145 { description = "Disnix Avahi publisher"; 146 147 startOn = "started avahi-daemon"; 148 149 exec = 150 '' 151 ${pkgs.avahi}/bin/avahi-publish-service disnix-${config.networking.hostName} _disnix._tcp 22 \ 152 "mem=$(grep 'MemTotal:' /proc/meminfo | sed -e 's/kB//' -e 's/MemTotal://' -e 's/ //g')" \ 153 ${concatMapStrings (infrastructureAttrName: 154 let infrastructureAttrValue = getAttr infrastructureAttrName (cfg.infrastructure); 155 in 156 if isInt infrastructureAttrValue then 157 ''${infrastructureAttrName}=${toString infrastructureAttrValue} \ 158 '' 159 else 160 ''${infrastructureAttrName}=\"${infrastructureAttrValue}\" \ 161 '' 162 ) (attrNames (cfg.infrastructure))} 163 ''; 164 }; 165 }; 166 }; 167}