1 {pkgs, lib, config, ...}:
5 printProperties = properties:
6 lib.concatMapStrings (propertyName:
8 property = properties.${propertyName};
10 if lib.isList property then "${propertyName}=(${lib.concatMapStrings (elem: "\"${toString elem}\" ") (properties.${propertyName})})\n"
11 else "${propertyName}=\"${toString property}\"\n"
12 ) (builtins.attrNames properties);
14 properties = pkgs.stdenv.mkDerivation {
15 name = "dysnomia-properties";
18 ${printProperties cfg.properties}
23 containersDir = pkgs.stdenv.mkDerivation {
24 name = "dysnomia-containers";
29 ${lib.concatMapStrings (containerName:
31 containerProperties = cfg.containers.${containerName};
34 cat > ${containerName} <<EOF
35 ${printProperties containerProperties}
39 ) (builtins.attrNames cfg.containers)}
43 linkMutableComponents = {containerName}:
45 mkdir ${containerName}
47 ${lib.concatMapStrings (componentName:
49 component = cfg.components.${containerName}.${componentName};
51 "ln -s ${component} ${containerName}/${componentName}\n"
52 ) (builtins.attrNames (cfg.components.${containerName} or {}))}
55 componentsDir = pkgs.stdenv.mkDerivation {
56 name = "dysnomia-components";
61 ${lib.concatMapStrings (containerName:
62 linkMutableComponents { inherit containerName; }
63 ) (builtins.attrNames cfg.components)}
68 enableApacheWebApplication = config.services.httpd.enable;
69 enableAxis2WebService = config.services.tomcat.axis2.enable;
70 enableDockerContainer = config.virtualisation.docker.enable;
71 enableEjabberdDump = config.services.ejabberd.enable;
72 enableMySQLDatabase = config.services.mysql.enable;
73 enablePostgreSQLDatabase = config.services.postgresql.enable;
74 enableTomcatWebApplication = config.services.tomcat.enable;
75 enableMongoDatabase = config.services.mongodb.enable;
76 enableSubversionRepository = config.services.svnserve.enable;
77 enableInfluxDatabase = config.services.influxdb.enable;
84 enable = lib.mkOption {
85 type = lib.types.bool;
87 description = "Whether to enable Dysnomia";
90 enableAuthentication = lib.mkOption {
91 type = lib.types.bool;
93 description = "Whether to publish privacy-sensitive authentication credentials";
96 package = lib.mkOption {
97 type = lib.types.path;
98 description = "The Dysnomia package";
101 properties = lib.mkOption {
102 description = "An attribute set in which each attribute represents a machine property. Optionally, these values can be shell substitutions.";
104 type = lib.types.attrs;
107 containers = lib.mkOption {
108 description = "An attribute set in which each key represents a container and each value an attribute set providing its configuration properties";
110 type = lib.types.attrsOf lib.types.attrs;
113 components = lib.mkOption {
114 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";
116 type = lib.types.attrsOf lib.types.attrs;
119 extraContainerProperties = lib.mkOption {
120 description = "An attribute set providing additional container settings in addition to the default properties";
122 type = lib.types.attrs;
125 extraContainerPaths = lib.mkOption {
126 description = "A list of paths containing additional container configurations that are added to the search folders";
128 type = lib.types.listOf lib.types.path;
131 extraModulePaths = lib.mkOption {
132 description = "A list of paths containing additional modules that are added to the search folders";
134 type = lib.types.listOf lib.types.path;
137 enableLegacyModules = lib.mkOption {
138 type = lib.types.bool;
140 description = "Whether to enable Dysnomia legacy process and wrapper modules";
145 config = lib.mkIf cfg.enable {
148 "dysnomia/containers" = {
149 source = containersDir;
151 "dysnomia/components" = {
152 source = componentsDir;
154 "dysnomia/properties" = {
159 environment.variables = {
160 DYSNOMIA_STATEDIR = "/var/state/dysnomia-nixos";
161 DYSNOMIA_CONTAINERS_PATH = "${lib.concatMapStrings (containerPath: "${containerPath}:") cfg.extraContainerPaths}/etc/dysnomia/containers";
162 DYSNOMIA_MODULES_PATH = "${lib.concatMapStrings (modulePath: "${modulePath}:") cfg.extraModulePaths}/etc/dysnomia/modules";
165 environment.systemPackages = [ cfg.package ];
167 dysnomia.package = pkgs.dysnomia.override (origArgs: dysnomiaFlags // lib.optionalAttrs (cfg.enableLegacyModules) {
168 enableLegacy = builtins.trace ''
169 WARNING: Dysnomia has been configured to use the legacy 'process' and 'wrapper'
170 modules for compatibility reasons! If you rely on these modules, consider
171 migrating to better alternatives.
173 More information: https://raw.githubusercontent.com/svanderburg/dysnomia/f65a9a84827bcc4024d6b16527098b33b02e4054/README-legacy.md
175 If you have migrated already or don't rely on these Dysnomia modules, you can
176 disable legacy mode with the following NixOS configuration option:
178 dysnomia.enableLegacyModules = false;
180 In a future version of Dysnomia (and NixOS) the legacy option will go away!
184 dysnomia.properties = {
185 hostname = config.networking.hostName;
186 inherit (pkgs.stdenv.hostPlatform) system;
194 # These are not base modules, but they are still enabled because they work with technology that are always enabled in NixOS
197 "nixos-configuration"
199 ++ lib.optional (dysnomiaFlags.enableApacheWebApplication) "apache-webapplication"
200 ++ lib.optional (dysnomiaFlags.enableAxis2WebService) "axis2-webservice"
201 ++ lib.optional (dysnomiaFlags.enableDockerContainer) "docker-container"
202 ++ lib.optional (dysnomiaFlags.enableEjabberdDump) "ejabberd-dump"
203 ++ lib.optional (dysnomiaFlags.enableInfluxDatabase) "influx-database"
204 ++ lib.optional (dysnomiaFlags.enableMySQLDatabase) "mysql-database"
205 ++ lib.optional (dysnomiaFlags.enablePostgreSQLDatabase) "postgresql-database"
206 ++ lib.optional (dysnomiaFlags.enableTomcatWebApplication) "tomcat-webapplication"
207 ++ lib.optional (dysnomiaFlags.enableMongoDatabase) "mongo-database"
208 ++ lib.optional (dysnomiaFlags.enableSubversionRepository) "subversion-repository";
211 dysnomia.containers = lib.recursiveUpdate ({
215 // lib.optionalAttrs (config.services.httpd.enable) { apache-webapplication = {
216 documentRoot = config.services.httpd.virtualHosts.localhost.documentRoot;
218 // lib.optionalAttrs (config.services.tomcat.axis2.enable) { axis2-webservice = {}; }
219 // lib.optionalAttrs (config.services.ejabberd.enable) { ejabberd-dump = {
220 ejabberdUser = config.services.ejabberd.user;
222 // lib.optionalAttrs (config.services.mysql.enable) { mysql-database = {
223 mysqlPort = config.services.mysql.settings.mysqld.port;
224 mysqlSocket = "/run/mysqld/mysqld.sock";
225 } // lib.optionalAttrs cfg.enableAuthentication {
226 mysqlUsername = "root";
229 // lib.optionalAttrs (config.services.postgresql.enable) { postgresql-database = {
230 } // lib.optionalAttrs (cfg.enableAuthentication) {
231 postgresqlUsername = "postgres";
234 // lib.optionalAttrs (config.services.tomcat.enable) { tomcat-webapplication = {
237 // lib.optionalAttrs (config.services.mongodb.enable) { mongo-database = {}; }
238 // lib.optionalAttrs (config.services.influxdb.enable) {
240 influxdbUsername = config.services.influxdb.user;
241 influxdbDataDir = "${config.services.influxdb.dataDir}/data";
242 influxdbMetaDir = "${config.services.influxdb.dataDir}/meta";
245 // lib.optionalAttrs (config.services.svnserve.enable) { subversion-repository = {
246 svnBaseDir = config.services.svnserve.svnBaseDir;
247 }; }) cfg.extraContainerProperties;
249 boot.extraSystemdUnitPaths = [ "/etc/systemd-mutable/system" ];
251 system.activationScripts.dysnomia = ''
252 mkdir -p /etc/systemd-mutable/system
253 if [ ! -f /etc/systemd-mutable/system/dysnomia.target ]
256 echo "Description=Services that are activated and deactivated by Dysnomia"
257 echo "After=final.target"
258 ) > /etc/systemd-mutable/system/dysnomia.target