Skip to content

Commit

Permalink
nixos-modules/microvm/virtiofsd/default: replace string-templating su…
Browse files Browse the repository at this point in the history
…pervisordConfigFile with generators.toINI
  • Loading branch information
astro committed Dec 1, 2024
1 parent aa5835f commit 74aa783
Showing 1 changed file with 45 additions and 37 deletions.
82 changes: 45 additions & 37 deletions nixos-modules/microvm/virtiofsd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,54 @@ in
microvm.binScripts = lib.mkIf requiresVirtiofsd {
virtiofsd-run =
let
supervisordConfig = pkgs.writeText "${config.networking.hostName}-virtiofsd-supervisord.conf" ''
[supervisord]
nodaemon=true
supervisordConfig = {
supervisord.nodaemon = true;

[eventlistener:notify]
command=${pkgs.writers.writePython3 "supervisord-event-handler" { } (
pkgs.substituteAll {
src = ./supervisord-event-handler.py;
virtiofsdCount = builtins.length virtiofsShares;
}
)}
events=PROCESS_STATE
"eventlistener:notify" = {
command = pkgs.writers.writePython3 "supervisord-event-handler" { } (
pkgs.substituteAll {
src = ./supervisord-event-handler.py;
virtiofsdCount = builtins.length virtiofsShares;
}
);
events = "PROCESS_STATE";
};
} // builtins.listToAttrs (
map ({ proto, tag, socket, source, ... }: {
name = "program:virtiofsd-${tag}";
value = {
stderr_syslog = true;
stdout_syslog = true;
autorestart = true;
command = pkgs.writeShellScript "virtiofsd-${tag}" ''
if [ $(id -u) = 0 ]; then
OPT_RLIMIT="--rlimit-nofile 1048576"
else
OPT_RLIMIT=""
fi
exec ${lib.getExe pkgs.virtiofsd} \
--socket-path=${lib.escapeShellArg socket} \
--socket-group=${group} \
--shared-dir=${lib.escapeShellArg source} \
$OPT_RLIMIT \
--thread-pool-size ${toString config.microvm.virtiofsd.threadPoolSize} \
--posix-acl --xattr \
${lib.optionalString (config.microvm.virtiofsd.inodeFileHandles != null)
"--inode-file-handles=${config.microvm.virtiofsd.inodeFileHandles}"
} \
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs}
'';
};
}) virtiofsShares
);

supervisordConfigFile =
pkgs.writeText "${config.networking.hostName}-virtiofsd-supervisord.conf" (
lib.generators.toINI {} supervisordConfig
);

${lib.concatMapStrings ({ proto, tag, socket, source, ... }: ''
[program:virtiofsd-${tag}]
stderr_syslog=true
stdout_syslog=true
autorestart=true
command=${pkgs.writeShellScript "virtiofsd-${tag}" ''
if [ $(id -u) = 0 ]; then
OPT_RLIMIT="--rlimit-nofile 1048576"
else
OPT_RLIMIT=""
fi
exec ${lib.getExe pkgs.virtiofsd} \
--socket-path=${lib.escapeShellArg socket} \
--socket-group=${group} \
--shared-dir=${lib.escapeShellArg source} \
$OPT_RLIMIT \
--thread-pool-size ${toString config.microvm.virtiofsd.threadPoolSize} \
--posix-acl --xattr \
${lib.optionalString (config.microvm.virtiofsd.inodeFileHandles != null)
"--inode-file-handles=${config.microvm.virtiofsd.inodeFileHandles}"
} \
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs}
''}
'' ) virtiofsShares}
'';
in ''
exec ${supervisord} --configuration ${supervisordConfig}
exec ${supervisord} --configuration ${supervisordConfigFile}
'';

virtiofsd-reload = ''
Expand Down

0 comments on commit 74aa783

Please sign in to comment.