1 { config, lib, pkgs, ... }:
7 cfg = config.services.zope2;
9 zope2Opts = { name, ... }: {
15 description = lib.mdDoc "The name of the zope2 instance. If undefined, the name of the attribute set will be used.";
21 description = lib.mdDoc "Specify the number of threads that Zope's ZServer web server will use to service requests. ";
24 http_address = mkOption {
25 default = "localhost:8080";
27 description = lib.mdDoc "Give a port and address for the HTTP server.";
33 description = lib.mdDoc "The name of the effective user for the Zope process.";
36 clientHome = mkOption {
37 default = "/var/lib/zope2/${name}";
39 description = lib.mdDoc "Home directory of zope2 instance.";
48 blob-dir /var/lib/zope2/${name}/blobstorage
50 path /var/lib/zope2/${name}/filestorage/Data.fs
56 description = lib.mdDoc "Extra zope.conf";
60 type = types.listOf types.package;
61 description = lib.mdDoc "The list of packages you want to make available to the zope2 instance.";
75 services.zope2.instances = mkOption {
77 type = with types; attrsOf (submodule zope2Opts);
78 example = literalExpression ''
81 http_address = "127.0.0.1:8080";
88 blob-dir /var/lib/zope2/plone01/blobstorage
90 path /var/lib/zope2/plone01/filestorage/Data.fs
98 description = lib.mdDoc "zope2 instances to be created automatically by the system.";
102 ###### implementation
104 config = mkIf (cfg.instances != {}) {
106 users.users.zope2 = {
110 users.groups.zope2 = {};
115 createZope2Instance = opts: name:
117 interpreter = pkgs.writeScript "interpreter"
122 if len(sys.argv) > 1:
123 _options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
125 for (_opt, _val) in _options:
133 __import__("runpy").run_module(
134 _val, {}, "__main__", alter_sys=True)
144 __import__("code").interact(banner="", local=globals())
146 env = pkgs.buildEnv {
147 name = "zope2-${name}-env";
150 pkgs.python27Packages.recursivePthLoader
151 pkgs.python27Packages."plone.recipe.zope2instance"
152 ] ++ attrValues pkgs.python27.modules
156 echo "#!$out/bin/python" > $out/bin/interpreter
157 cat ${interpreter} >> $out/bin/interpreter
160 conf = pkgs.writeText "zope2-${name}-conf"
162 %define INSTANCEHOME ${env}
163 instancehome $INSTANCEHOME
164 %define CLIENTHOME ${opts.clientHome}/${opts.name}
165 clienthome $CLIENTHOME
168 security-policy-implementation C
170 default-zpublisher-encoding utf-8
171 zserver-threads ${toString opts.threads}
172 effective-user ${opts.user}
174 pid-filename ${opts.clientHome}/${opts.name}/pid
175 lock-filename ${opts.clientHome}/${opts.name}/lock
176 python-check-interval 1000
177 enable-product-installation off
180 zope_i18n_compile_mo_files false
186 path /var/log/zope2/${name}.log
194 path /var/log/zope2/${name}-Z2.log
200 address ${opts.http_address}
205 name temporary storage for sessioning
207 mount-point /temp_folder
208 container-class Products.TemporaryFolder.TemporaryContainer
213 ctlScript = pkgs.writeScript "zope2-${name}-ctl-script"
218 import plone.recipe.zope2instance.ctl
220 if __name__ == '__main__':
221 sys.exit(plone.recipe.zope2instance.ctl.main(
226 ctl = pkgs.writeScript "zope2-${name}-ctl"
228 #!${pkgs.bash}/bin/bash -e
229 export PYTHONHOME=${env}
230 exec ${ctlScript} "$@"
233 #description = "${name} instance";
234 after = [ "network.target" ]; # with RelStorage also add "postgresql.service"
235 wantedBy = [ "multi-user.target" ];
236 path = opts.packages;
239 mkdir -p /var/log/zope2/
240 touch /var/log/zope2/${name}.log
241 touch /var/log/zope2/${name}-Z2.log
242 chown ${opts.user} /var/log/zope2/${name}.log
243 chown ${opts.user} /var/log/zope2/${name}-Z2.log
245 mkdir -p ${opts.clientHome}/filestorage ${opts.clientHome}/blobstorage
246 mkdir -p ${opts.clientHome}/${opts.name}
247 chown ${opts.user} ${opts.clientHome} -R
249 ${ctl} adduser admin admin
252 serviceConfig.Type = "forking";
253 serviceConfig.ExecStart = "${ctl} start";
254 serviceConfig.ExecStop = "${ctl} stop";
255 serviceConfig.ExecReload = "${ctl} restart";
258 in listToAttrs (map (name: { name = "zope2-${name}"; value = createZope2Instance (builtins.getAttr name cfg.instances) name; }) (builtins.attrNames cfg.instances));