Validate generated config file in the nixos module

This uses the usual pkgs.runCommand pattern to ensure that no
non-parseable config files can make it to the command line.
This commit is contained in:
Andreas Fuchs 2024-10-30 11:19:10 -04:00
parent a02c551a5e
commit dcf64f03fb

View file

@ -11,6 +11,10 @@ let
cfg = config.services.grapevine;
configFile = format.generate "config.toml" cfg.settings;
validateConfig = file: pkgs.runCommand "grapevine-checked-config" {} ''
${lib.getExe cfg.package} check-config -c ${lib.escapeShellArg file}
ln -s ${lib.escapeShellArg file} "$out"
'';
format = pkgs.formats.toml {};
in
@ -79,7 +83,7 @@ in
# Keep sorted
serviceConfig = {
DynamicUser = true;
ExecStart = "${lib.getExe cfg.package} serve --config ${configFile}";
ExecStart = "${lib.getExe cfg.package} serve --config ${validateConfig configFile}";
LockPersonality = true;
MemoryDenyWriteExecute = true;
PrivateDevices = true;