2016-06-17 11:12:44 +02:00
|
|
|
{pkgs, lib, config, ...}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2018-08-06 01:25:38 +02:00
|
|
|
cfg = config.dysnomia;
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
printProperties = properties:
|
|
|
|
concatMapStrings (propertyName:
|
|
|
|
let
|
2019-08-13 23:52:01 +02:00
|
|
|
property = properties.${propertyName};
|
2016-06-17 11:12:44 +02:00
|
|
|
in
|
2019-08-13 23:52:01 +02:00
|
|
|
if isList property then "${propertyName}=(${lib.concatMapStrings (elem: "\"${toString elem}\" ") (properties.${propertyName})})\n"
|
2016-06-17 11:12:44 +02:00
|
|
|
else "${propertyName}=\"${toString property}\"\n"
|
|
|
|
) (builtins.attrNames properties);
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
properties = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "dysnomia-properties";
|
|
|
|
buildCommand = ''
|
|
|
|
cat > $out << "EOF"
|
|
|
|
${printProperties cfg.properties}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
containersDir = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "dysnomia-containers";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
|
|
|
cd $out
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
${concatMapStrings (containerName:
|
|
|
|
let
|
2019-08-13 23:52:01 +02:00
|
|
|
containerProperties = cfg.containers.${containerName};
|
2016-06-17 11:12:44 +02:00
|
|
|
in
|
|
|
|
''
|
|
|
|
cat > ${containerName} <<EOF
|
|
|
|
${printProperties containerProperties}
|
|
|
|
type=${containerName}
|
|
|
|
EOF
|
|
|
|
''
|
|
|
|
) (builtins.attrNames cfg.containers)}
|
|
|
|
'';
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
linkMutableComponents = {containerName}:
|
|
|
|
''
|
|
|
|
mkdir ${containerName}
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
${concatMapStrings (componentName:
|
|
|
|
let
|
2019-08-13 23:52:01 +02:00
|
|
|
component = cfg.components.${containerName}.${componentName};
|
2016-06-17 11:12:44 +02:00
|
|
|
in
|
|
|
|
"ln -s ${component} ${containerName}/${componentName}\n"
|
2019-08-13 23:52:01 +02:00
|
|
|
) (builtins.attrNames (cfg.components.${containerName} or {}))}
|
2016-06-17 11:12:44 +02:00
|
|
|
'';
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
componentsDir = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "dysnomia-components";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
|
|
|
cd $out
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
${concatMapStrings (containerName:
|
|
|
|
linkMutableComponents { inherit containerName; }
|
|
|
|
) (builtins.attrNames cfg.components)}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2018-08-06 01:25:38 +02:00
|
|
|
dysnomia = {
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable Dysnomia";
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
enableAuthentication = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to publish privacy-sensitive authentication credentials";
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
package = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = "The Dysnomia package";
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
properties = mkOption {
|
|
|
|
description = "An attribute set in which each attribute represents a machine property. Optionally, these values can be shell substitutions.";
|
|
|
|
default = {};
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
containers = mkOption {
|
|
|
|
description = "An attribute set in which each key represents a container and each value an attribute set providing its configuration properties";
|
|
|
|
default = {};
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
components = mkOption {
|
|
|
|
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";
|
|
|
|
default = {};
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
extraContainerProperties = mkOption {
|
|
|
|
description = "An attribute set providing additional container settings in addition to the default properties";
|
|
|
|
default = {};
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
extraContainerPaths = mkOption {
|
|
|
|
description = "A list of paths containing additional container configurations that are added to the search folders";
|
|
|
|
default = [];
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
extraModulePaths = mkOption {
|
|
|
|
description = "A list of paths containing additional modules that are added to the search folders";
|
|
|
|
default = [];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
config = mkIf cfg.enable {
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
environment.etc = {
|
|
|
|
"dysnomia/containers" = {
|
|
|
|
source = containersDir;
|
|
|
|
};
|
|
|
|
"dysnomia/components" = {
|
|
|
|
source = componentsDir;
|
|
|
|
};
|
|
|
|
"dysnomia/properties" = {
|
|
|
|
source = properties;
|
|
|
|
};
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
environment.variables = {
|
|
|
|
DYSNOMIA_STATEDIR = "/var/state/dysnomia-nixos";
|
|
|
|
DYSNOMIA_CONTAINERS_PATH = "${lib.concatMapStrings (containerPath: "${containerPath}:") cfg.extraContainerPaths}/etc/dysnomia/containers";
|
|
|
|
DYSNOMIA_MODULES_PATH = "${lib.concatMapStrings (modulePath: "${modulePath}:") cfg.extraModulePaths}/etc/dysnomia/modules";
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2016-06-17 11:12:44 +02:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2018-08-06 01:25:38 +02:00
|
|
|
dysnomia.package = pkgs.dysnomia.override (origArgs: {
|
2016-06-17 11:12:44 +02:00
|
|
|
enableApacheWebApplication = config.services.httpd.enable;
|
|
|
|
enableAxis2WebService = config.services.tomcat.axis2.enable;
|
|
|
|
enableEjabberdDump = config.services.ejabberd.enable;
|
|
|
|
enableMySQLDatabase = config.services.mysql.enable;
|
|
|
|
enablePostgreSQLDatabase = config.services.postgresql.enable;
|
|
|
|
enableSubversionRepository = config.services.svnserve.enable;
|
|
|
|
enableTomcatWebApplication = config.services.tomcat.enable;
|
|
|
|
enableMongoDatabase = config.services.mongodb.enable;
|
2019-09-09 23:28:10 +02:00
|
|
|
enableInfluxDatabase = config.services.influxdb.enable;
|
2016-06-17 11:12:44 +02:00
|
|
|
});
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2018-08-06 01:25:38 +02:00
|
|
|
dysnomia.properties = {
|
2016-06-17 11:12:44 +02:00
|
|
|
hostname = config.networking.hostName;
|
2018-04-05 21:22:45 +02:00
|
|
|
inherit (config.nixpkgs.localSystem) system;
|
2016-06-17 11:12:44 +02:00
|
|
|
|
|
|
|
supportedTypes = (import "${pkgs.stdenv.mkDerivation {
|
|
|
|
name = "supportedtypes";
|
|
|
|
buildCommand = ''
|
|
|
|
( echo -n "[ "
|
|
|
|
cd ${cfg.package}/libexec/dysnomia
|
|
|
|
for i in *
|
|
|
|
do
|
|
|
|
echo -n "\"$i\" "
|
|
|
|
done
|
|
|
|
echo -n " ]") > $out
|
|
|
|
'';
|
|
|
|
}}");
|
|
|
|
};
|
2018-03-26 20:51:07 +02:00
|
|
|
|
2018-08-06 01:25:38 +02:00
|
|
|
dysnomia.containers = lib.recursiveUpdate ({
|
2016-06-17 11:12:44 +02:00
|
|
|
process = {};
|
|
|
|
wrapper = {};
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs (config.services.httpd.enable) { apache-webapplication = {
|
2020-04-14 14:30:34 +02:00
|
|
|
documentRoot = config.services.httpd.virtualHosts.localhost.documentRoot;
|
2016-06-17 11:12:44 +02:00
|
|
|
}; }
|
|
|
|
// 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);
|
|
|
|
};
|
|
|
|
}
|
2017-12-20 21:45:07 +01:00
|
|
|
// lib.optionalAttrs (config.services.postgresql.enable) { postgresql-database = {
|
|
|
|
} // lib.optionalAttrs (cfg.enableAuthentication) {
|
|
|
|
postgresqlUsername = "postgres";
|
|
|
|
};
|
|
|
|
}
|
2016-06-17 11:12:44 +02:00
|
|
|
// 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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|