1 {pkgs, lib, config, ...}:
8 printProperties = properties:
9 concatMapStrings (propertyName:
11 property = properties.${propertyName};
13 if isList property then "${propertyName}=(${lib.concatMapStrings (elem: "\"${toString elem}\" ") (properties.${propertyName})})\n"
14 else "${propertyName}=\"${toString property}\"\n"
15 ) (builtins.attrNames properties);
17 properties = pkgs.stdenv.mkDerivation {
18 name = "dysnomia-properties";
21 ${printProperties cfg.properties}
26 containersDir = pkgs.stdenv.mkDerivation {
27 name = "dysnomia-containers";
32 ${concatMapStrings (containerName:
34 containerProperties = cfg.containers.${containerName};
37 cat > ${containerName} <<EOF
38 ${printProperties containerProperties}
42 ) (builtins.attrNames cfg.containers)}
46 linkMutableComponents = {containerName}:
48 mkdir ${containerName}
50 ${concatMapStrings (componentName:
52 component = cfg.components.${containerName}.${componentName};
54 "ln -s ${component} ${containerName}/${componentName}\n"
55 ) (builtins.attrNames (cfg.components.${containerName} or {}))}
58 componentsDir = pkgs.stdenv.mkDerivation {
59 name = "dysnomia-components";
64 ${concatMapStrings (containerName:
65 linkMutableComponents { inherit containerName; }
66 ) (builtins.attrNames cfg.components)}
71 enableApacheWebApplication = config.services.httpd.enable;
72 enableAxis2WebService = config.services.tomcat.axis2.enable;
73 enableDockerContainer = config.virtualisation.docker.enable;
74 enableEjabberdDump = config.services.ejabberd.enable;
75 enableMySQLDatabase = config.services.mysql.enable;
76 enablePostgreSQLDatabase = config.services.postgresql.enable;
77 enableTomcatWebApplication = config.services.tomcat.enable;
78 enableMongoDatabase = config.services.mongodb.enable;
79 enableSubversionRepository = config.services.svnserve.enable;
80 enableInfluxDatabase = config.services.influxdb.enable;
90 description = lib.mdDoc "Whether to enable Dysnomia";
93 enableAuthentication = mkOption {
96 description = lib.mdDoc "Whether to publish privacy-sensitive authentication credentials";
101 description = lib.mdDoc "The Dysnomia package";
104 properties = mkOption {
105 description = lib.mdDoc "An attribute set in which each attribute represents a machine property. Optionally, these values can be shell substitutions.";
110 containers = mkOption {
111 description = lib.mdDoc "An attribute set in which each key represents a container and each value an attribute set providing its configuration properties";
113 type = types.attrsOf types.attrs;
116 components = mkOption {
117 description = lib.mdDoc "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";
119 type = types.attrsOf types.attrs;
122 extraContainerProperties = mkOption {
123 description = lib.mdDoc "An attribute set providing additional container settings in addition to the default properties";
128 extraContainerPaths = mkOption {
129 description = lib.mdDoc "A list of paths containing additional container configurations that are added to the search folders";
131 type = types.listOf types.path;
134 extraModulePaths = mkOption {
135 description = lib.mdDoc "A list of paths containing additional modules that are added to the search folders";
137 type = types.listOf types.path;
140 enableLegacyModules = mkOption {
143 description = lib.mdDoc "Whether to enable Dysnomia legacy process and wrapper modules";
148 config = mkIf cfg.enable {
151 "dysnomia/containers" = {
152 source = containersDir;
154 "dysnomia/components" = {
155 source = componentsDir;
157 "dysnomia/properties" = {
162 environment.variables = {
163 DYSNOMIA_STATEDIR = "/var/state/dysnomia-nixos";
164 DYSNOMIA_CONTAINERS_PATH = "${lib.concatMapStrings (containerPath: "${containerPath}:") cfg.extraContainerPaths}/etc/dysnomia/containers";
165 DYSNOMIA_MODULES_PATH = "${lib.concatMapStrings (modulePath: "${modulePath}:") cfg.extraModulePaths}/etc/dysnomia/modules";
168 environment.systemPackages = [ cfg.package ];
170 dysnomia.package = pkgs.dysnomia.override (origArgs: dysnomiaFlags // lib.optionalAttrs (cfg.enableLegacyModules) {
171 enableLegacy = builtins.trace ''
172 WARNING: Dysnomia has been configured to use the legacy 'process' and 'wrapper'
173 modules for compatibility reasons! If you rely on these modules, consider
174 migrating to better alternatives.
176 More information: https://raw.githubusercontent.com/svanderburg/dysnomia/f65a9a84827bcc4024d6b16527098b33b02e4054/README-legacy.md
178 If you have migrated already or don't rely on these Dysnomia modules, you can
179 disable legacy mode with the following NixOS configuration option:
181 dysnomia.enableLegacyModules = false;
183 In a future version of Dysnomia (and NixOS) the legacy option will go away!
187 dysnomia.properties = {
188 hostname = config.networking.hostName;
189 inherit (pkgs.stdenv.hostPlatform) system;
197 # These are not base modules, but they are still enabled because they work with technology that are always enabled in NixOS
200 "nixos-configuration"
202 ++ optional (dysnomiaFlags.enableApacheWebApplication) "apache-webapplication"
203 ++ optional (dysnomiaFlags.enableAxis2WebService) "axis2-webservice"
204 ++ optional (dysnomiaFlags.enableDockerContainer) "docker-container"
205 ++ optional (dysnomiaFlags.enableEjabberdDump) "ejabberd-dump"
206 ++ optional (dysnomiaFlags.enableInfluxDatabase) "influx-database"
207 ++ optional (dysnomiaFlags.enableMySQLDatabase) "mysql-database"
208 ++ optional (dysnomiaFlags.enablePostgreSQLDatabase) "postgresql-database"
209 ++ optional (dysnomiaFlags.enableTomcatWebApplication) "tomcat-webapplication"
210 ++ optional (dysnomiaFlags.enableMongoDatabase) "mongo-database"
211 ++ optional (dysnomiaFlags.enableSubversionRepository) "subversion-repository";
214 dysnomia.containers = lib.recursiveUpdate ({
218 // lib.optionalAttrs (config.services.httpd.enable) { apache-webapplication = {
219 documentRoot = config.services.httpd.virtualHosts.localhost.documentRoot;
221 // lib.optionalAttrs (config.services.tomcat.axis2.enable) { axis2-webservice = {}; }
222 // lib.optionalAttrs (config.services.ejabberd.enable) { ejabberd-dump = {
223 ejabberdUser = config.services.ejabberd.user;
225 // lib.optionalAttrs (config.services.mysql.enable) { mysql-database = {
226 mysqlPort = config.services.mysql.port;
227 mysqlSocket = "/run/mysqld/mysqld.sock";
228 } // lib.optionalAttrs cfg.enableAuthentication {
229 mysqlUsername = "root";
232 // lib.optionalAttrs (config.services.postgresql.enable) { postgresql-database = {
233 } // lib.optionalAttrs (cfg.enableAuthentication) {
234 postgresqlUsername = "postgres";
237 // lib.optionalAttrs (config.services.tomcat.enable) { tomcat-webapplication = {
240 // lib.optionalAttrs (config.services.mongodb.enable) { mongo-database = {}; }
241 // lib.optionalAttrs (config.services.influxdb.enable) {
243 influxdbUsername = config.services.influxdb.user;
244 influxdbDataDir = "${config.services.influxdb.dataDir}/data";
245 influxdbMetaDir = "${config.services.influxdb.dataDir}/meta";
248 // lib.optionalAttrs (config.services.svnserve.enable) { subversion-repository = {
249 svnBaseDir = config.services.svnserve.svnBaseDir;
250 }; }) cfg.extraContainerProperties;
252 boot.extraSystemdUnitPaths = [ "/etc/systemd-mutable/system" ];
254 system.activationScripts.dysnomia = ''
255 mkdir -p /etc/systemd-mutable/system
256 if [ ! -f /etc/systemd-mutable/system/dysnomia.target ]
259 echo "Description=Services that are activated and deactivated by Dysnomia"
260 echo "After=final.target"
261 ) > /etc/systemd-mutable/system/dysnomia.target