Skip to content

Commit 2252ce1

Browse files
committed
nixos-modules/microvm/virtiofsd/default: replace string-templating supervisordConfigFile with generators.toINI
1 parent 5bfa7dc commit 2252ce1

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

nixos-modules/microvm/virtiofsd/default.nix

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,54 @@ in
1919
microvm.binScripts = lib.mkIf requiresVirtiofsd {
2020
virtiofsd-run =
2121
let
22-
supervisordConfig = pkgs.writeText "${config.networking.hostName}-virtiofsd-supervisord.conf" ''
23-
[supervisord]
24-
nodaemon=true
22+
supervisordConfig = {
23+
supervisord.nodaemon = true;
2524

26-
[eventlistener:notify]
27-
command=${pkgs.writers.writePython3 "supervisord-event-handler" { } (
28-
pkgs.substituteAll {
29-
src = ./supervisord-event-handler.py;
30-
virtiofsdCount = builtins.length virtiofsShares;
31-
}
32-
)}
33-
events=PROCESS_STATE
25+
"eventlistener:notify" = {
26+
command = pkgs.writers.writePython3 "supervisord-event-handler" { } (
27+
pkgs.substituteAll {
28+
src = ./supervisord-event-handler.py;
29+
virtiofsdCount = builtins.length virtiofsShares;
30+
}
31+
);
32+
events = "PROCESS_STATE";
33+
};
34+
} // builtins.listToAttrs (
35+
map ({ proto, tag, socket, source, ... }: {
36+
name = "program:virtiofsd-${tag}";
37+
value = {
38+
stderr_syslog = true;
39+
stdout_syslog = true;
40+
autorestart = true;
41+
command = pkgs.writeShellScript "virtiofsd-${tag}" ''
42+
if [ $(id -u) = 0 ]; then
43+
OPT_RLIMIT="--rlimit-nofile 1048576"
44+
else
45+
OPT_RLIMIT=""
46+
fi
47+
exec ${lib.getExe pkgs.virtiofsd} \
48+
--socket-path=${lib.escapeShellArg socket} \
49+
--socket-group=${group} \
50+
--shared-dir=${lib.escapeShellArg source} \
51+
$OPT_RLIMIT \
52+
--thread-pool-size ${toString config.microvm.virtiofsd.threadPoolSize} \
53+
--posix-acl --xattr \
54+
${lib.optionalString (config.microvm.virtiofsd.inodeFileHandles != null)
55+
"--inode-file-handles=${config.microvm.virtiofsd.inodeFileHandles}"
56+
} \
57+
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs}
58+
'';
59+
};
60+
}) virtiofsShares
61+
);
62+
63+
supervisordConfigFile =
64+
pkgs.writeText "${config.networking.hostName}-virtiofsd-supervisord.conf" (
65+
lib.generators.toINI {} supervisordConfig
66+
);
3467

35-
${lib.concatMapStrings ({ proto, tag, socket, source, ... }: ''
36-
[program:virtiofsd-${tag}]
37-
stderr_syslog=true
38-
stdout_syslog=true
39-
autorestart=true
40-
command=${pkgs.writeShellScript "virtiofsd-${tag}" ''
41-
if [ $(id -u) = 0 ]; then
42-
OPT_RLIMIT="--rlimit-nofile 1048576"
43-
else
44-
OPT_RLIMIT=""
45-
fi
46-
exec ${lib.getExe pkgs.virtiofsd} \
47-
--socket-path=${lib.escapeShellArg socket} \
48-
--socket-group=${group} \
49-
--shared-dir=${lib.escapeShellArg source} \
50-
$OPT_RLIMIT \
51-
--thread-pool-size ${toString config.microvm.virtiofsd.threadPoolSize} \
52-
--posix-acl --xattr \
53-
${lib.optionalString (config.microvm.virtiofsd.inodeFileHandles != null)
54-
"--inode-file-handles=${config.microvm.virtiofsd.inodeFileHandles}"
55-
} \
56-
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs}
57-
''}
58-
'' ) virtiofsShares}
59-
'';
6068
in ''
61-
exec ${supervisord} --configuration ${supervisordConfig}
69+
exec ${supervisord} --configuration ${supervisordConfigFile}
6270
'';
6371

6472
virtiofsd-reload = ''

0 commit comments

Comments
 (0)