https://cs-syd.eu/posts/2024-07-29-announcing-autodocodec-nix
I’ve also often found myself wondering about the best way to integrate the Haskell-side option parsing with the Nix module options. This is a clean approach, but it forces you to commit generated code and add CI steps to make sure it stays in sync.
Even if you’re OK with committing generated code, I think it would still be very frustrating to have the module options go out of sync with the Haskell parser and to get option parsing failures while the deployed systemd service is starting. Could be great to add a --config-parse-only
way to run your service binary so that you could implement a Nix derivation that will check the given Nix configuration against the service binary getting run, so that you’d get configuration errors at nix build
time of your NixOS image, instead of at service start time (which could be after you’ve already run your database migrations, for instance).
Even if you’re OK with committing generated code, I think it would still be very frustrating to have the module options go out of sync with the Haskell parser and to get option parsing failures while the deployed systemd service is starting.
There’s a function for that:
Could be great to add a
--config-parse-only
way to run your service binary so that you could implement a Nix derivation that will check the given Nix configuration against the service binary getting run, so that you’d get configuration errors atnix build
time of your NixOS image, instead of at service start time (which could be after you’ve already run your database migrations, for instance).
That exists as --run-settings-check
:
Thanks for your response!
I like your framing of it as a golden test case, it’s so obvious in hindsight but hadn’t thought of it that way.
The --run-settings-check
would also be great to run as a derivation under system.checks
:
{
config.system.checks = [ ( pkgs.runCommand "My Service config check" {} ''
${cfg.package} --run-settings-check ${concatStringsSep " " cfg.args}
'')];
}
I’ll make sure to check out autodocodec-nix
the next time I’m writing a NixOS module for a Haskell service, thanks for sharing it!