{pkgs, lib, config, ...}: with lib; let cfg = config.dysnomia; printProperties = properties: concatMapStrings (propertyName: let property = properties.${propertyName}; in if isList property then "${propertyName}=(${lib.concatMapStrings (elem: "\"${toString elem}\" ") (properties.${propertyName})})\n" else "${propertyName}=\"${toString property}\"\n" ) (builtins.attrNames properties); properties = pkgs.stdenv.mkDerivation { name = "dysnomia-properties"; buildCommand = '' cat > $out << "EOF" ${printProperties cfg.properties} EOF ''; }; containersDir = pkgs.stdenv.mkDerivation { name = "dysnomia-containers"; buildCommand = '' mkdir -p $out cd $out ${concatMapStrings (containerName: let containerProperties = cfg.containers.${containerName}; in '' cat > ${containerName} < $out ''; }}"); }; dysnomia.containers = lib.recursiveUpdate ({ process = {}; wrapper = {}; } // lib.optionalAttrs (config.services.httpd.enable) { apache-webapplication = { documentRoot = config.services.httpd.virtualHosts.localhost.documentRoot; }; } // lib.optionalAttrs (config.services.tomcat.axis2.enable) { axis2-webservice = {}; } // lib.optionalAttrs (config.services.ejabberd.enable) { ejabberd-dump = { ejabberdUser = config.services.ejabberd.user; }; } // lib.optionalAttrs (config.services.mysql.enable) { mysql-database = { mysqlPort = config.services.mysql.port; } // lib.optionalAttrs cfg.enableAuthentication { mysqlUsername = "root"; mysqlPassword = builtins.readFile (config.services.mysql.rootPassword); }; } // lib.optionalAttrs (config.services.postgresql.enable) { postgresql-database = { } // lib.optionalAttrs (cfg.enableAuthentication) { postgresqlUsername = "postgres"; }; } // lib.optionalAttrs (config.services.tomcat.enable) { tomcat-webapplication = { tomcatPort = 8080; }; } // lib.optionalAttrs (config.services.mongodb.enable) { mongo-database = {}; } // lib.optionalAttrs (config.services.svnserve.enable) { subversion-repository = { svnBaseDir = config.services.svnserve.svnBaseDir; }; }) cfg.extraContainerProperties; system.activationScripts.dysnomia = '' 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 ''; }; }