8 cfg = config.services.dysnomia;
12 lib.concatMapStrings (
15 property = properties.${propertyName};
17 if lib.isList property then
19 lib.concatMapStrings (elem: "\"${toString elem}\" ") (properties.${propertyName})
22 "${propertyName}=\"${toString property}\"\n"
23 ) (builtins.attrNames properties);
25 properties = pkgs.stdenv.mkDerivation {
26 name = "dysnomia-properties";
29 ${printProperties cfg.properties}
34 containersDir = pkgs.stdenv.mkDerivation {
35 name = "dysnomia-containers";
40 ${lib.concatMapStrings (
43 containerProperties = cfg.containers.${containerName};
46 cat > ${containerName} <<EOF
47 ${printProperties containerProperties}
51 ) (builtins.attrNames cfg.containers)}
55 linkMutableComponents =
58 mkdir ${containerName}
60 ${lib.concatMapStrings (
63 component = cfg.components.${containerName}.${componentName};
65 "ln -s ${component} ${containerName}/${componentName}\n"
66 ) (builtins.attrNames (cfg.components.${containerName} or { }))}
69 componentsDir = pkgs.stdenv.mkDerivation {
70 name = "dysnomia-components";
75 ${lib.concatMapStrings (containerName: linkMutableComponents { inherit containerName; }) (
76 builtins.attrNames cfg.components
82 enableApacheWebApplication = config.services.httpd.enable;
83 enableAxis2WebService = config.services.tomcat.axis2.enable;
84 enableDockerContainer = config.virtualisation.docker.enable;
85 enableEjabberdDump = config.services.ejabberd.enable;
86 enableMySQLDatabase = config.services.mysql.enable;
87 enablePostgreSQLDatabase = config.services.postgresql.enable;
88 enableTomcatWebApplication = config.services.tomcat.enable;
89 enableMongoDatabase = config.services.mongodb.enable;
90 enableSubversionRepository = config.services.svnserve.enable;
91 enableInfluxDatabase = config.services.influxdb.enable;
98 enable = lib.mkOption {
99 type = lib.types.bool;
101 description = "Whether to enable Dysnomia";
104 enableAuthentication = lib.mkOption {
105 type = lib.types.bool;
107 description = "Whether to publish privacy-sensitive authentication credentials";
110 package = lib.mkOption {
111 type = lib.types.path;
112 description = "The Dysnomia package";
115 properties = lib.mkOption {
116 description = "An attribute set in which each attribute represents a machine property. Optionally, these values can be shell substitutions.";
118 type = lib.types.attrs;
121 containers = lib.mkOption {
122 description = "An attribute set in which each key represents a container and each value an attribute set providing its configuration properties";
124 type = lib.types.attrsOf lib.types.attrs;
127 components = lib.mkOption {
128 description = "An attribute 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";
130 type = lib.types.attrsOf lib.types.attrs;
133 extraContainerProperties = lib.mkOption {
134 description = "An attribute set providing additional container settings in addition to the default properties";
136 type = lib.types.attrs;
139 extraContainerPaths = lib.mkOption {
140 description = "A list of paths containing additional container configurations that are added to the search folders";
142 type = lib.types.listOf lib.types.path;
145 extraModulePaths = lib.mkOption {
146 description = "A list of paths containing additional modules that are added to the search folders";
148 type = lib.types.listOf lib.types.path;
151 enableLegacyModules = lib.mkOption {
152 type = lib.types.bool;
154 description = "Whether to enable Dysnomia legacy process and wrapper modules";
160 (lib.mkRenamedOptionModule [ "dysnomia" ] [ "services" "dysnomia" ])
163 config = lib.mkIf cfg.enable {
166 "dysnomia/containers" = {
167 source = containersDir;
169 "dysnomia/components" = {
170 source = componentsDir;
172 "dysnomia/properties" = {
177 environment.variables = {
178 DYSNOMIA_STATEDIR = "/var/state/dysnomia-nixos";
179 DYSNOMIA_CONTAINERS_PATH = "${
180 lib.concatMapStrings (containerPath: "${containerPath}:") cfg.extraContainerPaths
181 }/etc/dysnomia/containers";
182 DYSNOMIA_MODULES_PATH = "${
183 lib.concatMapStrings (modulePath: "${modulePath}:") cfg.extraModulePaths
184 }/etc/dysnomia/modules";
187 environment.systemPackages = [ cfg.package ];
189 services.dysnomia.package = pkgs.dysnomia.override (
192 // lib.optionalAttrs (cfg.enableLegacyModules) {
193 enableLegacy = builtins.trace ''
194 WARNING: Dysnomia has been configured to use the legacy 'process' and 'wrapper'
195 modules for compatibility reasons! If you rely on these modules, consider
196 migrating to better alternatives.
198 More information: https://raw.githubusercontent.com/svanderburg/dysnomia/f65a9a84827bcc4024d6b16527098b33b02e4054/README-legacy.md
200 If you have migrated already or don't rely on these Dysnomia modules, you can
201 disable legacy mode with the following NixOS configuration option:
203 dysnomia.enableLegacyModules = false;
205 In a future version of Dysnomia (and NixOS) the legacy option will go away!
210 services.dysnomia.properties = {
211 hostname = config.networking.hostName;
212 inherit (pkgs.stdenv.hostPlatform) system;
221 # These are not base modules, but they are still enabled because they work with technology that are always enabled in NixOS
224 "nixos-configuration"
226 ++ lib.optional (dysnomiaFlags.enableApacheWebApplication) "apache-webapplication"
227 ++ lib.optional (dysnomiaFlags.enableAxis2WebService) "axis2-webservice"
228 ++ lib.optional (dysnomiaFlags.enableDockerContainer) "docker-container"
229 ++ lib.optional (dysnomiaFlags.enableEjabberdDump) "ejabberd-dump"
230 ++ lib.optional (dysnomiaFlags.enableInfluxDatabase) "influx-database"
231 ++ lib.optional (dysnomiaFlags.enableMySQLDatabase) "mysql-database"
232 ++ lib.optional (dysnomiaFlags.enablePostgreSQLDatabase) "postgresql-database"
233 ++ lib.optional (dysnomiaFlags.enableTomcatWebApplication) "tomcat-webapplication"
234 ++ lib.optional (dysnomiaFlags.enableMongoDatabase) "mongo-database"
235 ++ lib.optional (dysnomiaFlags.enableSubversionRepository) "subversion-repository";
238 services.dysnomia.containers = lib.recursiveUpdate (
243 // lib.optionalAttrs (config.services.httpd.enable) {
244 apache-webapplication = {
245 documentRoot = config.services.httpd.virtualHosts.localhost.documentRoot;
248 // lib.optionalAttrs (config.services.tomcat.axis2.enable) { axis2-webservice = { }; }
249 // lib.optionalAttrs (config.services.ejabberd.enable) {
251 ejabberdUser = config.services.ejabberd.user;
254 // lib.optionalAttrs (config.services.mysql.enable) {
257 mysqlPort = config.services.mysql.settings.mysqld.port;
258 mysqlSocket = "/run/mysqld/mysqld.sock";
260 // lib.optionalAttrs cfg.enableAuthentication {
261 mysqlUsername = "root";
264 // lib.optionalAttrs (config.services.postgresql.enable) {
265 postgresql-database =
268 // lib.optionalAttrs (cfg.enableAuthentication) {
269 postgresqlUsername = "postgres";
272 // lib.optionalAttrs (config.services.tomcat.enable) {
273 tomcat-webapplication = {
277 // lib.optionalAttrs (config.services.mongodb.enable) { mongo-database = { }; }
278 // lib.optionalAttrs (config.services.influxdb.enable) {
280 influxdbUsername = config.services.influxdb.user;
281 influxdbDataDir = "${config.services.influxdb.dataDir}/data";
282 influxdbMetaDir = "${config.services.influxdb.dataDir}/meta";
285 // lib.optionalAttrs (config.services.svnserve.enable) {
286 subversion-repository = {
287 svnBaseDir = config.services.svnserve.svnBaseDir;
290 ) cfg.extraContainerProperties;
292 boot.extraSystemdUnitPaths = [ "/etc/systemd-mutable/system" ];
294 system.activationScripts.dysnomia = ''
295 mkdir -p /etc/systemd-mutable/system
296 if [ ! -f /etc/systemd-mutable/system/dysnomia.target ]
299 echo "Description=Services that are activated and deactivated by Dysnomia"
300 echo "After=final.target"
301 ) > /etc/systemd-mutable/system/dysnomia.target