disnix-module: split dysnomia's functionality into a separate module so that it can be used without Disnix and remove the hacky/obsolete avahi publisher

+233 -93
+1
nixos/modules/module-list.nix
··· 219 219 ./services/misc/confd.nix 220 220 ./services/misc/devmon.nix 221 221 ./services/misc/dictd.nix 222 + ./services/misc/dysnomia.nix 222 223 ./services/misc/disnix.nix 223 224 ./services/misc/docker-registry.nix 224 225 ./services/misc/emby.nix
+15 -93
nixos/modules/services/misc/disnix.nix
··· 36 36 default = false; 37 37 description = "Whether to enable the DisnixWebService interface running on Apache Tomcat"; 38 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"; 39 + 40 + package = mkOption { 41 + type = types.path; 42 + description = "The Disnix package"; 43 + default = pkgs.disnix; 60 44 }; 61 45 62 46 }; 63 47 64 48 }; 65 - 66 49 67 50 ###### implementation 68 51 69 52 config = mkIf cfg.enable { 70 - environment.systemPackages = [ pkgs.disnix pkgs.dysnomia ] ++ optional cfg.useWebServiceInterface pkgs.DisnixWebService; 53 + dysnomia.enable = true; 54 + 55 + environment.systemPackages = [ pkgs.disnix ] ++ optional cfg.useWebServiceInterface pkgs.DisnixWebService; 71 56 72 57 services.dbus.enable = true; 73 58 services.dbus.packages = [ pkgs.disnix ]; 74 59 75 - services.avahi.enable = cfg.publishAvahi; 76 - 77 60 services.tomcat.enable = cfg.useWebServiceInterface; 78 61 services.tomcat.extraGroups = [ "disnix" ]; 79 62 services.tomcat.javaOpts = "${optionalString cfg.useWebServiceInterface "-Djava.library.path=${pkgs.libmatthew_java}/lib/jni"} "; 80 63 services.tomcat.sharedLibs = optional cfg.useWebServiceInterface "${pkgs.DisnixWebService}/share/java/DisnixConnection.jar" 81 - ++ optional cfg.useWebServiceInterface "${pkgs.dbus_java}/share/java/dbus.jar"; 64 + ++ optional cfg.useWebServiceInterface "${pkgs.dbus_java}/share/java/dbus.jar"; 82 65 services.tomcat.webapps = optional cfg.useWebServiceInterface pkgs.DisnixWebService; 83 66 84 67 users.extraGroups = singleton ··· 86 69 gid = config.ids.gids.disnix; 87 70 }; 88 71 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 (config.services.ejabberd.enable) { ejabberdUser = config.services.ejabberd.user; } 114 - // optionalAttrs (cfg.publishInfrastructure.enableAuthentication) ( 115 - optionalAttrs (config.services.mysql.enable) { mysqlUsername = "root"; mysqlPassword = readFile config.services.mysql.rootPassword; }) 116 - ) 117 - ; 118 - 119 - services.disnix.publishInfrastructure.enable = cfg.publishAvahi; 120 - 121 72 systemd.services = { 122 73 disnix = { 123 74 description = "Disnix server"; ··· 133 84 134 85 restartIfChanged = false; 135 86 136 - path = [ pkgs.nix pkgs.disnix dysnomia "/run/current-system/sw" ]; 87 + path = [ config.nix.package cfg.package config.dysnomia.package "/run/current-system/sw" ]; 137 88 138 89 environment = { 139 90 HOME = "/root"; 140 - }; 141 - 142 - preStart = '' 143 - mkdir -p /etc/systemd-mutable/system 144 - if [ ! -f /etc/systemd-mutable/system/dysnomia.target ] 145 - then 146 - ( echo "[Unit]" 147 - echo "Description=Services that are activated and deactivated by Dysnomia" 148 - echo "After=final.target" 149 - ) > /etc/systemd-mutable/system/dysnomia.target 150 - fi 151 - ''; 152 - 153 - script = "disnix-service"; 91 + } 92 + // (if config.environment.variables ? DYSNOMIA_CONTAINERS_PATH then { inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH; } else {}) 93 + // (if config.environment.variables ? DYSNOMIA_MODULES_PATH then { inherit (config.environment.variables) DYSNOMIA_MODULES_PATH; } else {}); 94 + 95 + serviceConfig.ExecStart = "${cfg.package}/bin/disnix-service"; 154 96 }; 155 - } // optionalAttrs cfg.publishAvahi { 156 - disnixAvahi = { 157 - description = "Disnix Avahi publisher"; 158 - wants = [ "avahi-daemon.service" ]; 159 - wantedBy = [ "multi-user.target" ]; 160 97 161 - script = '' 162 - ${pkgs.avahi}/bin/avahi-publish-service disnix-${config.networking.hostName} _disnix._tcp 22 \ 163 - "mem=$(grep 'MemTotal:' /proc/meminfo | sed -e 's/kB//' -e 's/MemTotal://' -e 's/ //g')" \ 164 - ${concatMapStrings (infrastructureAttrName: 165 - let infrastructureAttrValue = getAttr infrastructureAttrName (cfg.infrastructure); 166 - in 167 - if isInt infrastructureAttrValue then 168 - ''${infrastructureAttrName}=${toString infrastructureAttrValue} \ 169 - '' 170 - else 171 - ''${infrastructureAttrName}=\"${infrastructureAttrValue}\" \ 172 - '' 173 - ) (attrNames (cfg.infrastructure))} 174 - ''; 175 - }; 176 98 }; 177 99 }; 178 100 }
+217
nixos/modules/services/misc/dysnomia.nix
··· 1 + {pkgs, lib, config, ...}: 2 + 3 + with lib; 4 + 5 + let 6 + cfg = config.dysnomia; 7 + 8 + printProperties = properties: 9 + concatMapStrings (propertyName: 10 + let 11 + property = properties."${propertyName}"; 12 + in 13 + if isList property then "${propertyName}=(${lib.concatMapStrings (elem: "\"${toString elem}\" ") (properties."${propertyName}")})\n" 14 + else "${propertyName}=\"${toString property}\"\n" 15 + ) (builtins.attrNames properties); 16 + 17 + properties = pkgs.stdenv.mkDerivation { 18 + name = "dysnomia-properties"; 19 + buildCommand = '' 20 + cat > $out << "EOF" 21 + ${printProperties cfg.properties} 22 + EOF 23 + ''; 24 + }; 25 + 26 + containersDir = pkgs.stdenv.mkDerivation { 27 + name = "dysnomia-containers"; 28 + buildCommand = '' 29 + mkdir -p $out 30 + cd $out 31 + 32 + ${concatMapStrings (containerName: 33 + let 34 + containerProperties = cfg.containers."${containerName}"; 35 + in 36 + '' 37 + cat > ${containerName} <<EOF 38 + ${printProperties containerProperties} 39 + type=${containerName} 40 + EOF 41 + '' 42 + ) (builtins.attrNames cfg.containers)} 43 + ''; 44 + }; 45 + 46 + linkMutableComponents = {containerName}: 47 + '' 48 + mkdir ${containerName} 49 + 50 + ${concatMapStrings (componentName: 51 + let 52 + component = cfg.components."${containerName}"."${componentName}"; 53 + in 54 + "ln -s ${component} ${containerName}/${componentName}\n" 55 + ) (builtins.attrNames (cfg.components."${containerName}" or {}))} 56 + ''; 57 + 58 + componentsDir = pkgs.stdenv.mkDerivation { 59 + name = "dysnomia-components"; 60 + buildCommand = '' 61 + mkdir -p $out 62 + cd $out 63 + 64 + ${concatMapStrings (containerName: 65 + let 66 + components = cfg.components."${containerName}"; 67 + in 68 + linkMutableComponents { inherit containerName; } 69 + ) (builtins.attrNames cfg.components)} 70 + ''; 71 + }; 72 + in 73 + { 74 + options = { 75 + dysnomia = { 76 + 77 + enable = mkOption { 78 + type = types.bool; 79 + default = false; 80 + description = "Whether to enable Dysnomia"; 81 + }; 82 + 83 + enableAuthentication = mkOption { 84 + type = types.bool; 85 + default = false; 86 + description = "Whether to publish privacy-sensitive authentication credentials"; 87 + }; 88 + 89 + package = mkOption { 90 + type = types.path; 91 + description = "The Dysnomia package"; 92 + }; 93 + 94 + properties = mkOption { 95 + description = "An attribute set in which each attribute represents a machine property. Optionally, these values can be shell substitutions."; 96 + default = {}; 97 + }; 98 + 99 + containers = mkOption { 100 + description = "An attribute set in which each key represents a container and each value an attribute set providing its configuration properties"; 101 + default = {}; 102 + }; 103 + 104 + components = mkOption { 105 + description = "An atttribute set in which each key represents a container and each value an attribute set in which each key represents a component and each value a derivation constructing its initial state"; 106 + default = {}; 107 + }; 108 + 109 + extraContainerProperties = mkOption { 110 + description = "An attribute set providing additional container settings in addition to the default properties"; 111 + default = {}; 112 + }; 113 + 114 + extraContainerPaths = mkOption { 115 + description = "A list of paths containing additional container configurations that are added to the search folders"; 116 + default = []; 117 + }; 118 + 119 + extraModulePaths = mkOption { 120 + description = "A list of paths containing additional modules that are added to the search folders"; 121 + default = []; 122 + }; 123 + }; 124 + }; 125 + 126 + config = mkIf cfg.enable { 127 + 128 + environment.etc = { 129 + "dysnomia/containers" = { 130 + source = containersDir; 131 + }; 132 + "dysnomia/components" = { 133 + source = componentsDir; 134 + }; 135 + "dysnomia/properties" = { 136 + source = properties; 137 + }; 138 + }; 139 + 140 + environment.variables = { 141 + DYSNOMIA_STATEDIR = "/var/state/dysnomia-nixos"; 142 + DYSNOMIA_CONTAINERS_PATH = "${lib.concatMapStrings (containerPath: "${containerPath}:") cfg.extraContainerPaths}/etc/dysnomia/containers"; 143 + DYSNOMIA_MODULES_PATH = "${lib.concatMapStrings (modulePath: "${modulePath}:") cfg.extraModulePaths}/etc/dysnomia/modules"; 144 + }; 145 + 146 + environment.systemPackages = [ cfg.package ]; 147 + 148 + dysnomia.package = pkgs.dysnomia.override (origArgs: { 149 + enableApacheWebApplication = config.services.httpd.enable; 150 + enableAxis2WebService = config.services.tomcat.axis2.enable; 151 + enableEjabberdDump = config.services.ejabberd.enable; 152 + enableMySQLDatabase = config.services.mysql.enable; 153 + enablePostgreSQLDatabase = config.services.postgresql.enable; 154 + enableSubversionRepository = config.services.svnserve.enable; 155 + enableTomcatWebApplication = config.services.tomcat.enable; 156 + enableMongoDatabase = config.services.mongodb.enable; 157 + }); 158 + 159 + dysnomia.properties = { 160 + hostname = config.networking.hostName; 161 + system = if config.nixpkgs.system == "" then builtins.currentSystem else config.nixpkgs.system; 162 + 163 + supportedTypes = (import "${pkgs.stdenv.mkDerivation { 164 + name = "supportedtypes"; 165 + buildCommand = '' 166 + ( echo -n "[ " 167 + cd ${cfg.package}/libexec/dysnomia 168 + for i in * 169 + do 170 + echo -n "\"$i\" " 171 + done 172 + echo -n " ]") > $out 173 + ''; 174 + }}"); 175 + }; 176 + 177 + dysnomia.containers = lib.recursiveUpdate ({ 178 + process = {}; 179 + wrapper = {}; 180 + } 181 + // lib.optionalAttrs (config.services.httpd.enable) { apache-webapplication = { 182 + documentRoot = config.services.httpd.documentRoot; 183 + }; } 184 + // lib.optionalAttrs (config.services.tomcat.axis2.enable) { axis2-webservice = {}; } 185 + // lib.optionalAttrs (config.services.ejabberd.enable) { ejabberd-dump = { 186 + ejabberdUser = config.services.ejabberd.user; 187 + }; } 188 + // lib.optionalAttrs (config.services.mysql.enable) { mysql-database = { 189 + mysqlPort = config.services.mysql.port; 190 + } // lib.optionalAttrs cfg.enableAuthentication { 191 + mysqlUsername = "root"; 192 + mysqlPassword = builtins.readFile (config.services.mysql.rootPassword); 193 + }; 194 + } 195 + // lib.optionalAttrs (config.services.postgresql.enable && cfg.enableAuthentication) { postgresql-database = { 196 + postgresqlUsername = "root"; 197 + }; } 198 + // lib.optionalAttrs (config.services.tomcat.enable) { tomcat-webapplication = { 199 + tomcatPort = 8080; 200 + }; } 201 + // lib.optionalAttrs (config.services.mongodb.enable) { mongo-database = {}; } 202 + // lib.optionalAttrs (config.services.svnserve.enable) { subversion-repository = { 203 + svnBaseDir = config.services.svnserve.svnBaseDir; 204 + }; }) cfg.extraContainerProperties; 205 + 206 + system.activationScripts.dysnomia = '' 207 + mkdir -p /etc/systemd-mutable/system 208 + if [ ! -f /etc/systemd-mutable/system/dysnomia.target ] 209 + then 210 + ( echo "[Unit]" 211 + echo "Description=Services that are activated and deactivated by Dysnomia" 212 + echo "After=final.target" 213 + ) > /etc/systemd-mutable/system/dysnomia.target 214 + fi 215 + ''; 216 + }; 217 + }