···149149 # not be started by default on the installation CD because the
150150 # default root password is empty.
151151 services.openssh.enable = true;
152152-153153- jobs.openssh.startOn = lib.mkOverride 50 "";
152152+ systemd.services.openssh.wantedBy = lib.mkOverride 50 [];
154153155154 boot.loader.grub.enable = false;
156155 boot.loader.generationsDir.enable = false;
···164164 # not be started by default on the installation CD because the
165165 # default root password is empty.
166166 services.openssh.enable = true;
167167- jobs.openssh.startOn = lib.mkOverride 50 "";
167167+ systemd.services.openssh.wantedBy = lib.mkOverride 50 [];
168168169169 # cpufrequtils fails to build on non-pc
170170 powerManagement.enable = false;
···127127 extraGroups = cfg.extraGroups;
128128 };
129129130130- jobs.tomcat =
131131- { description = "Apache Tomcat server";
130130+ systemd.services.tomcat = {
131131+ description = "Apache Tomcat server";
132132+ wantedBy = [ "multi-user.target" ];
133133+ after = [ "network-interfaces.target" ];
134134+ serviceConfig.Type = "daemon";
132135133133- startOn = "started network-interfaces";
134134- stopOn = "stopping network-interfaces";
136136+ preStart = ''
137137+ # Create the base directory
138138+ mkdir -p ${cfg.baseDir}
135139136136- daemonType = "daemon";
140140+ # Create a symlink to the bin directory of the tomcat component
141141+ ln -sfn ${tomcat}/bin ${cfg.baseDir}/bin
137142138138- preStart =
139139- ''
140140- # Create the base directory
141141- mkdir -p ${cfg.baseDir}
143143+ # Create a conf/ directory
144144+ mkdir -p ${cfg.baseDir}/conf
145145+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/conf
142146143143- # Create a symlink to the bin directory of the tomcat component
144144- ln -sfn ${tomcat}/bin ${cfg.baseDir}/bin
147147+ # Symlink the config files in the conf/ directory (except for catalina.properties and server.xml)
148148+ for i in $(ls ${tomcat}/conf | grep -v catalina.properties | grep -v server.xml)
149149+ do
150150+ ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i`
151151+ done
152152+153153+ # Create subdirectory for virtual hosts
154154+ mkdir -p ${cfg.baseDir}/virtualhosts
155155+156156+ # Create a modified catalina.properties file
157157+ # Change all references from CATALINA_HOME to CATALINA_BASE and add support for shared libraries
158158+ sed -e 's|''${catalina.home}|''${catalina.base}|g' \
159159+ -e 's|shared.loader=|shared.loader=''${catalina.base}/shared/lib/*.jar|' \
160160+ ${tomcat}/conf/catalina.properties > ${cfg.baseDir}/conf/catalina.properties
145161146146- # Create a conf/ directory
147147- mkdir -p ${cfg.baseDir}/conf
148148- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/conf
162162+ # Create a modified server.xml which also includes all virtual hosts
163163+ sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\ ${
164164+ toString (map (virtualHost: ''<Host name=\"${virtualHost.name}\" appBase=\"virtualhosts/${virtualHost.name}/webapps\" unpackWARs=\"true\" autoDeploy=\"true\" xmlValidation=\"false\" xmlNamespaceAware=\"false\" >${if cfg.logPerVirtualHost then ''<Valve className=\"org.apache.catalina.valves.AccessLogValve\" directory=\"logs/${virtualHost.name}\" prefix=\"${virtualHost.name}_access_log.\" pattern=\"combined\" resolveHosts=\"false\"/>'' else ""}</Host>'') cfg.virtualHosts)}" \
165165+ ${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
149166150150- # Symlink the config files in the conf/ directory (except for catalina.properties and server.xml)
151151- for i in $(ls ${tomcat}/conf | grep -v catalina.properties | grep -v server.xml)
152152- do
153153- ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i`
154154- done
167167+ # Create a logs/ directory
168168+ mkdir -p ${cfg.baseDir}/logs
169169+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs
170170+ ${if cfg.logPerVirtualHost then
171171+ toString (map (h: ''
172172+ mkdir -p ${cfg.baseDir}/logs/${h.name}
173173+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/${h.name}
174174+ '') cfg.virtualHosts) else ''''}
155175156156- # Create subdirectory for virtual hosts
157157- mkdir -p ${cfg.baseDir}/virtualhosts
176176+ # Create a temp/ directory
177177+ mkdir -p ${cfg.baseDir}/temp
178178+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/temp
158179159159- # Create a modified catalina.properties file
160160- # Change all references from CATALINA_HOME to CATALINA_BASE and add support for shared libraries
161161- sed -e 's|''${catalina.home}|''${catalina.base}|g' \
162162- -e 's|shared.loader=|shared.loader=''${catalina.base}/shared/lib/*.jar|' \
163163- ${tomcat}/conf/catalina.properties > ${cfg.baseDir}/conf/catalina.properties
180180+ # Create a lib/ directory
181181+ mkdir -p ${cfg.baseDir}/lib
182182+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/lib
164183165165- # Create a modified server.xml which also includes all virtual hosts
166166- sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\ ${
167167- toString (map (virtualHost: ''<Host name=\"${virtualHost.name}\" appBase=\"virtualhosts/${virtualHost.name}/webapps\" unpackWARs=\"true\" autoDeploy=\"true\" xmlValidation=\"false\" xmlNamespaceAware=\"false\" >${if cfg.logPerVirtualHost then ''<Valve className=\"org.apache.catalina.valves.AccessLogValve\" directory=\"logs/${virtualHost.name}\" prefix=\"${virtualHost.name}_access_log.\" pattern=\"combined\" resolveHosts=\"false\"/>'' else ""}</Host>'') cfg.virtualHosts)}" \
168168- ${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
184184+ # Create a shared/lib directory
185185+ mkdir -p ${cfg.baseDir}/shared/lib
186186+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/shared/lib
169187170170- # Create a logs/ directory
171171- mkdir -p ${cfg.baseDir}/logs
172172- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs
173173- ${if cfg.logPerVirtualHost then
174174- toString (map (h: ''
175175- mkdir -p ${cfg.baseDir}/logs/${h.name}
176176- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/${h.name}
177177- '') cfg.virtualHosts) else ''''}
188188+ # Create a webapps/ directory
189189+ mkdir -p ${cfg.baseDir}/webapps
190190+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/webapps
178191179179- # Create a temp/ directory
180180- mkdir -p ${cfg.baseDir}/temp
181181- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/temp
192192+ # Symlink all the given common libs files or paths into the lib/ directory
193193+ for i in ${tomcat} ${toString cfg.commonLibs}
194194+ do
195195+ if [ -f $i ]
196196+ then
197197+ # If the given web application is a file, symlink it into the common/lib/ directory
198198+ ln -sfn $i ${cfg.baseDir}/lib/`basename $i`
199199+ elif [ -d $i ]
200200+ then
201201+ # If the given web application is a directory, then iterate over the files
202202+ # in the special purpose directories and symlink them into the tomcat tree
182203183183- # Create a lib/ directory
184184- mkdir -p ${cfg.baseDir}/lib
185185- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/lib
204204+ for j in $i/lib/*
205205+ do
206206+ ln -sfn $j ${cfg.baseDir}/lib/`basename $j`
207207+ done
208208+ fi
209209+ done
186210187187- # Create a shared/lib directory
188188- mkdir -p ${cfg.baseDir}/shared/lib
189189- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/shared/lib
211211+ # Symlink all the given shared libs files or paths into the shared/lib/ directory
212212+ for i in ${toString cfg.sharedLibs}
213213+ do
214214+ if [ -f $i ]
215215+ then
216216+ # If the given web application is a file, symlink it into the common/lib/ directory
217217+ ln -sfn $i ${cfg.baseDir}/shared/lib/`basename $i`
218218+ elif [ -d $i ]
219219+ then
220220+ # If the given web application is a directory, then iterate over the files
221221+ # in the special purpose directories and symlink them into the tomcat tree
190222191191- # Create a webapps/ directory
192192- mkdir -p ${cfg.baseDir}/webapps
193193- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/webapps
223223+ for j in $i/shared/lib/*
224224+ do
225225+ ln -sfn $j ${cfg.baseDir}/shared/lib/`basename $j`
226226+ done
227227+ fi
228228+ done
194229195195- # Symlink all the given common libs files or paths into the lib/ directory
196196- for i in ${tomcat} ${toString cfg.commonLibs}
197197- do
198198- if [ -f $i ]
199199- then
200200- # If the given web application is a file, symlink it into the common/lib/ directory
201201- ln -sfn $i ${cfg.baseDir}/lib/`basename $i`
202202- elif [ -d $i ]
203203- then
204204- # If the given web application is a directory, then iterate over the files
205205- # in the special purpose directories and symlink them into the tomcat tree
230230+ # Symlink all the given web applications files or paths into the webapps/ directory
231231+ for i in ${toString cfg.webapps}
232232+ do
233233+ if [ -f $i ]
234234+ then
235235+ # If the given web application is a file, symlink it into the webapps/ directory
236236+ ln -sfn $i ${cfg.baseDir}/webapps/`basename $i`
237237+ elif [ -d $i ]
238238+ then
239239+ # If the given web application is a directory, then iterate over the files
240240+ # in the special purpose directories and symlink them into the tomcat tree
206241207207- for j in $i/lib/*
208208- do
209209- ln -sfn $j ${cfg.baseDir}/lib/`basename $j`
210210- done
211211- fi
212212- done
242242+ for j in $i/webapps/*
243243+ do
244244+ ln -sfn $j ${cfg.baseDir}/webapps/`basename $j`
245245+ done
213246214214- # Symlink all the given shared libs files or paths into the shared/lib/ directory
215215- for i in ${toString cfg.sharedLibs}
216216- do
217217- if [ -f $i ]
247247+ # Also symlink the configuration files if they are included
248248+ if [ -d $i/conf/Catalina ]
218249 then
219219- # If the given web application is a file, symlink it into the common/lib/ directory
220220- ln -sfn $i ${cfg.baseDir}/shared/lib/`basename $i`
221221- elif [ -d $i ]
222222- then
223223- # If the given web application is a directory, then iterate over the files
224224- # in the special purpose directories and symlink them into the tomcat tree
225225-226226- for j in $i/shared/lib/*
250250+ for j in $i/conf/Catalina/*
227251 do
228228- ln -sfn $j ${cfg.baseDir}/shared/lib/`basename $j`
252252+ mkdir -p ${cfg.baseDir}/conf/Catalina/localhost
253253+ ln -sfn $j ${cfg.baseDir}/conf/Catalina/localhost/`basename $j`
229254 done
230255 fi
231231- done
256256+ fi
257257+ done
258258+259259+ ${toString (map (virtualHost: ''
260260+ # Create webapps directory for the virtual host
261261+ mkdir -p ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps
262262+263263+ # Modify ownership
264264+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps
265265+266266+ # Symlink all the given web applications files or paths into the webapps/ directory
267267+ # of this virtual host
268268+ for i in "${if virtualHost ? webapps then toString virtualHost.webapps else ""}"
269269+ do
270270+ if [ -f $i ]
271271+ then
272272+ # If the given web application is a file, symlink it into the webapps/ directory
273273+ ln -sfn $i ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $i`
274274+ elif [ -d $i ]
275275+ then
276276+ # If the given web application is a directory, then iterate over the files
277277+ # in the special purpose directories and symlink them into the tomcat tree
278278+279279+ for j in $i/webapps/*
280280+ do
281281+ ln -sfn $j ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $j`
282282+ done
283283+284284+ # Also symlink the configuration files if they are included
285285+ if [ -d $i/conf/Catalina ]
286286+ then
287287+ for j in $i/conf/Catalina/*
288288+ do
289289+ mkdir -p ${cfg.baseDir}/conf/Catalina/${virtualHost.name}
290290+ ln -sfn $j ${cfg.baseDir}/conf/Catalina/${virtualHost.name}/`basename $j`
291291+ done
292292+ fi
293293+ fi
294294+ done
295295+296296+ ''
297297+ ) cfg.virtualHosts) }
298298+299299+ # Create a work/ directory
300300+ mkdir -p ${cfg.baseDir}/work
301301+ chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/work
302302+303303+ ${if cfg.axis2.enable then
304304+ ''
305305+ # Copy the Axis2 web application
306306+ cp -av ${pkgs.axis2}/webapps/axis2 ${cfg.baseDir}/webapps
307307+308308+ # Turn off addressing, which causes many errors
309309+ sed -i -e 's%<module ref="addressing"/>%<!-- <module ref="addressing"/> -->%' ${cfg.baseDir}/webapps/axis2/WEB-INF/conf/axis2.xml
232310233233- # Symlink all the given web applications files or paths into the webapps/ directory
234234- for i in ${toString cfg.webapps}
311311+ # Modify permissions on the Axis2 application
312312+ chown -R ${cfg.user}:${cfg.group} ${cfg.baseDir}/webapps/axis2
313313+314314+ # Symlink all the given web service files or paths into the webapps/axis2/WEB-INF/services directory
315315+ for i in ${toString cfg.axis2.services}
235316 do
236317 if [ -f $i ]
237318 then
238238- # If the given web application is a file, symlink it into the webapps/ directory
239239- ln -sfn $i ${cfg.baseDir}/webapps/`basename $i`
319319+ # If the given web service is a file, symlink it into the webapps/axis2/WEB-INF/services
320320+ ln -sfn $i ${cfg.baseDir}/webapps/axis2/WEB-INF/services/`basename $i`
240321 elif [ -d $i ]
241322 then
242323 # If the given web application is a directory, then iterate over the files
243324 # in the special purpose directories and symlink them into the tomcat tree
244325245245- for j in $i/webapps/*
326326+ for j in $i/webapps/axis2/WEB-INF/services/*
246327 do
247247- ln -sfn $j ${cfg.baseDir}/webapps/`basename $j`
328328+ ln -sfn $j ${cfg.baseDir}/webapps/axis2/WEB-INF/services/`basename $j`
248329 done
249330250331 # Also symlink the configuration files if they are included
···252333 then
253334 for j in $i/conf/Catalina/*
254335 do
255255- mkdir -p ${cfg.baseDir}/conf/Catalina/localhost
256336 ln -sfn $j ${cfg.baseDir}/conf/Catalina/localhost/`basename $j`
257337 done
258338 fi
259339 fi
260340 done
341341+ ''
342342+ else ""}
343343+ '';
261344262262- ${toString (map (virtualHost: ''
263263- # Create webapps directory for the virtual host
264264- mkdir -p ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps
345345+ script = ''
346346+ ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c 'CATALINA_BASE=${cfg.baseDir} JAVA_HOME=${cfg.jdk} JAVA_OPTS="${cfg.javaOpts}" CATALINA_OPTS="${cfg.catalinaOpts}" ${tomcat}/bin/startup.sh'
347347+ '';
265348266266- # Modify ownership
267267- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps
349349+ postStop = ''
350350+ echo "Stopping tomcat..."
351351+ CATALINA_BASE=${cfg.baseDir} JAVA_HOME=${cfg.jdk} ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c ${tomcat}/bin/shutdown.sh
352352+ '';
268353269269- # Symlink all the given web applications files or paths into the webapps/ directory
270270- # of this virtual host
271271- for i in "${if virtualHost ? webapps then toString virtualHost.webapps else ""}"
272272- do
273273- if [ -f $i ]
274274- then
275275- # If the given web application is a file, symlink it into the webapps/ directory
276276- ln -sfn $i ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $i`
277277- elif [ -d $i ]
278278- then
279279- # If the given web application is a directory, then iterate over the files
280280- # in the special purpose directories and symlink them into the tomcat tree
281281-282282- for j in $i/webapps/*
283283- do
284284- ln -sfn $j ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $j`
285285- done
286286-287287- # Also symlink the configuration files if they are included
288288- if [ -d $i/conf/Catalina ]
289289- then
290290- for j in $i/conf/Catalina/*
291291- do
292292- mkdir -p ${cfg.baseDir}/conf/Catalina/${virtualHost.name}
293293- ln -sfn $j ${cfg.baseDir}/conf/Catalina/${virtualHost.name}/`basename $j`
294294- done
295295- fi
296296- fi
297297- done
298298-299299- ''
300300- ) cfg.virtualHosts) }
301301-302302- # Create a work/ directory
303303- mkdir -p ${cfg.baseDir}/work
304304- chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/work
305305-306306- ${if cfg.axis2.enable then
307307- ''
308308- # Copy the Axis2 web application
309309- cp -av ${pkgs.axis2}/webapps/axis2 ${cfg.baseDir}/webapps
310310-311311- # Turn off addressing, which causes many errors
312312- sed -i -e 's%<module ref="addressing"/>%<!-- <module ref="addressing"/> -->%' ${cfg.baseDir}/webapps/axis2/WEB-INF/conf/axis2.xml
313313-314314- # Modify permissions on the Axis2 application
315315- chown -R ${cfg.user}:${cfg.group} ${cfg.baseDir}/webapps/axis2
316316-317317- # Symlink all the given web service files or paths into the webapps/axis2/WEB-INF/services directory
318318- for i in ${toString cfg.axis2.services}
319319- do
320320- if [ -f $i ]
321321- then
322322- # If the given web service is a file, symlink it into the webapps/axis2/WEB-INF/services
323323- ln -sfn $i ${cfg.baseDir}/webapps/axis2/WEB-INF/services/`basename $i`
324324- elif [ -d $i ]
325325- then
326326- # If the given web application is a directory, then iterate over the files
327327- # in the special purpose directories and symlink them into the tomcat tree
328328-329329- for j in $i/webapps/axis2/WEB-INF/services/*
330330- do
331331- ln -sfn $j ${cfg.baseDir}/webapps/axis2/WEB-INF/services/`basename $j`
332332- done
333333-334334- # Also symlink the configuration files if they are included
335335- if [ -d $i/conf/Catalina ]
336336- then
337337- for j in $i/conf/Catalina/*
338338- do
339339- ln -sfn $j ${cfg.baseDir}/conf/Catalina/localhost/`basename $j`
340340- done
341341- fi
342342- fi
343343- done
344344- ''
345345- else ""}
346346- '';
347347-348348- script = ''
349349- ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c 'CATALINA_BASE=${cfg.baseDir} JAVA_HOME=${cfg.jdk} JAVA_OPTS="${cfg.javaOpts}" CATALINA_OPTS="${cfg.catalinaOpts}" ${tomcat}/bin/startup.sh'
350350- '';
351351-352352- postStop =
353353- ''
354354- echo "Stopping tomcat..."
355355- CATALINA_BASE=${cfg.baseDir} JAVA_HOME=${cfg.jdk} ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c ${tomcat}/bin/shutdown.sh
356356- '';
357357-358358- };
354354+ };
359355360356 };
361357
···11-{ config, lib, pkgs, ... }:
22-33-with lib;
44-with import ../boot/systemd-unit-options.nix { inherit config lib; };
55-66-let
77-88- userExists = u:
99- (u == "") || any (uu: uu.name == u) (attrValues config.users.extraUsers);
1010-1111- groupExists = g:
1212- (g == "") || any (gg: gg.name == g) (attrValues config.users.extraGroups);
1313-1414- makeJobScript = name: content: "${pkgs.writeScriptBin name content}/bin/${name}";
1515-1616- # From a job description, generate an systemd unit file.
1717- makeUnit = job:
1818-1919- let
2020- hasMain = job.script != "" || job.exec != "";
2121-2222- env = job.environment;
2323-2424- preStartScript = makeJobScript "${job.name}-pre-start"
2525- ''
2626- #! ${pkgs.stdenv.shell} -e
2727- ${job.preStart}
2828- '';
2929-3030- startScript = makeJobScript "${job.name}-start"
3131- ''
3232- #! ${pkgs.stdenv.shell} -e
3333- ${if job.script != "" then job.script else ''
3434- exec ${job.exec}
3535- ''}
3636- '';
3737-3838- postStartScript = makeJobScript "${job.name}-post-start"
3939- ''
4040- #! ${pkgs.stdenv.shell} -e
4141- ${job.postStart}
4242- '';
4343-4444- preStopScript = makeJobScript "${job.name}-pre-stop"
4545- ''
4646- #! ${pkgs.stdenv.shell} -e
4747- ${job.preStop}
4848- '';
4949-5050- postStopScript = makeJobScript "${job.name}-post-stop"
5151- ''
5252- #! ${pkgs.stdenv.shell} -e
5353- ${job.postStop}
5454- '';
5555- in {
5656-5757- inherit (job) description requires before partOf environment path restartIfChanged unitConfig;
5858-5959- after =
6060- (if job.startOn == "stopped udevtrigger" then [ "systemd-udev-settle.service" ] else
6161- if job.startOn == "started udev" then [ "systemd-udev.service" ] else
6262- if job.startOn == "started network-interfaces" then [ "network-interfaces.target" ] else
6363- if job.startOn == "started networking" then [ "network.target" ] else
6464- if job.startOn == "ip-up" then [] else
6565- if job.startOn == "" || job.startOn == "startup" then [] else
6666- builtins.trace "Warning: job ‘${job.name}’ has unknown startOn value ‘${job.startOn}’." []
6767- ) ++ job.after;
6868-6969- wants =
7070- (if job.startOn == "stopped udevtrigger" then [ "systemd-udev-settle.service" ] else []
7171- ) ++ job.wants;
7272-7373- wantedBy =
7474- (if job.startOn == "" then [] else
7575- if job.startOn == "ip-up" then [ "ip-up.target" ] else
7676- [ "multi-user.target" ]) ++ job.wantedBy;
7777-7878- serviceConfig =
7979- job.serviceConfig
8080- // optionalAttrs (job.preStart != "" && (job.script != "" || job.exec != ""))
8181- { ExecStartPre = preStartScript; }
8282- // optionalAttrs (job.preStart != "" && job.script == "" && job.exec == "")
8383- { ExecStart = preStartScript; }
8484- // optionalAttrs (job.script != "" || job.exec != "")
8585- { ExecStart = startScript; }
8686- // optionalAttrs (job.postStart != "")
8787- { ExecStartPost = postStartScript; }
8888- // optionalAttrs (job.preStop != "")
8989- { ExecStop = preStopScript; }
9090- // optionalAttrs (job.postStop != "")
9191- { ExecStopPost = postStopScript; }
9292- // (if job.script == "" && job.exec == "" then { Type = "oneshot"; RemainAfterExit = true; } else
9393- if job.daemonType == "fork" || job.daemonType == "daemon" then { Type = "forking"; GuessMainPID = true; } else
9494- if job.daemonType == "none" then { } else
9595- throw "invalid daemon type `${job.daemonType}'")
9696- // optionalAttrs (!job.task && !(job.script == "" && job.exec == "") && job.respawn)
9797- { Restart = "always"; }
9898- // optionalAttrs job.task
9999- { Type = "oneshot"; RemainAfterExit = false; };
100100- };
101101-102102-103103- jobOptions = serviceOptions // {
104104-105105- name = mkOption {
106106- # !!! The type should ensure that this could be a filename.
107107- type = types.str;
108108- example = "sshd";
109109- description = ''
110110- Name of the job, mapped to the systemd unit
111111- <literal><replaceable>name</replaceable>.service</literal>.
112112- '';
113113- };
114114-115115- startOn = mkOption {
116116- #type = types.str;
117117- default = "";
118118- description = ''
119119- The Upstart event that triggers this job to be started. Some
120120- are mapped to systemd dependencies; otherwise you will get a
121121- warning. If empty, the job will not start automatically.
122122- '';
123123- };
124124-125125- stopOn = mkOption {
126126- type = types.str;
127127- default = "starting shutdown";
128128- description = ''
129129- Ignored; this was the Upstart event that triggers this job to be stopped.
130130- '';
131131- };
132132-133133- postStart = mkOption {
134134- type = types.lines;
135135- default = "";
136136- description = ''
137137- Shell commands executed after the job is started (i.e. after
138138- the job's main process is started), but before the job is
139139- considered “running”.
140140- '';
141141- };
142142-143143- preStop = mkOption {
144144- type = types.lines;
145145- default = "";
146146- description = ''
147147- Shell commands executed before the job is stopped
148148- (i.e. before systemd kills the job's main process). This can
149149- be used to cleanly shut down a daemon.
150150- '';
151151- };
152152-153153- postStop = mkOption {
154154- type = types.lines;
155155- default = "";
156156- description = ''
157157- Shell commands executed after the job has stopped
158158- (i.e. after the job's main process has terminated).
159159- '';
160160- };
161161-162162- exec = mkOption {
163163- type = types.str;
164164- default = "";
165165- description = ''
166166- Command to start the job's main process. If empty, the
167167- job has no main process, but can still have pre/post-start
168168- and pre/post-stop scripts, and is considered “running”
169169- until it is stopped.
170170- '';
171171- };
172172-173173- respawn = mkOption {
174174- type = types.bool;
175175- default = true;
176176- description = ''
177177- Whether to restart the job automatically if its process
178178- ends unexpectedly.
179179- '';
180180- };
181181-182182- task = mkOption {
183183- type = types.bool;
184184- default = false;
185185- description = ''
186186- Whether this job is a task rather than a service. Tasks
187187- are executed only once, while services are restarted when
188188- they exit.
189189- '';
190190- };
191191-192192- daemonType = mkOption {
193193- type = types.str;
194194- default = "none";
195195- description = ''
196196- Determines how systemd detects when a daemon should be
197197- considered “running”. The value <literal>none</literal> means
198198- that the daemon is considered ready immediately. The value
199199- <literal>fork</literal> means that the daemon will fork once.
200200- The value <literal>daemon</literal> means that the daemon will
201201- fork twice. The value <literal>stop</literal> means that the
202202- daemon will raise the SIGSTOP signal to indicate readiness.
203203- '';
204204- };
205205-206206- setuid = mkOption {
207207- type = types.addCheck types.str userExists;
208208- default = "";
209209- description = ''
210210- Run the daemon as a different user.
211211- '';
212212- };
213213-214214- setgid = mkOption {
215215- type = types.addCheck types.str groupExists;
216216- default = "";
217217- description = ''
218218- Run the daemon as a different group.
219219- '';
220220- };
221221-222222- path = mkOption {
223223- default = [];
224224- description = ''
225225- Packages added to the job's <envar>PATH</envar> environment variable.
226226- Both the <filename>bin</filename> and <filename>sbin</filename>
227227- subdirectories of each package are added.
228228- '';
229229- };
230230-231231- };
232232-233233-234234- upstartJob = { name, config, ... }: {
235235-236236- options = {
237237-238238- unit = mkOption {
239239- default = makeUnit config;
240240- description = "Generated definition of the systemd unit corresponding to this job.";
241241- };
242242-243243- };
244244-245245- config = {
246246-247247- # The default name is the name extracted from the attribute path.
248248- name = mkDefault name;
249249-250250- };
251251-252252- };
253253-254254-in
255255-256256-{
257257-258258- ###### interface
259259-260260- options = {
261261-262262- jobs = mkOption {
263263- default = {};
264264- description = ''
265265- This option is a legacy method to define system services,
266266- dating from the era where NixOS used Upstart instead of
267267- systemd. You should use <option>systemd.services</option>
268268- instead. Services defined using <option>jobs</option> are
269269- mapped automatically to <option>systemd.services</option>, but
270270- may not work perfectly; in particular, most
271271- <option>startOn</option> conditions are not supported.
272272- '';
273273- type = types.loaOf types.optionSet;
274274- options = [ jobOptions upstartJob ];
275275- };
276276-277277- };
278278-279279-280280- ###### implementation
281281-282282- config = {
283283-284284- systemd.services =
285285- flip mapAttrs' config.jobs (name: job:
286286- nameValuePair job.name job.unit);
287287-288288- };
289289-290290-}
-8
nixos/modules/tasks/filesystems/btrfs.nix
···3131 ''
3232 btrfs device scan
3333 '';
3434-3535- # !!! This is broken. There should be a udev rule to do this when
3636- # new devices are discovered.
3737- jobs.udev.postStart =
3838- ''
3939- ${pkgs.btrfs-progs}/bin/btrfs device scan
4040- '';
4141-4234 };
4335}