Update nix module and config examples for socket activation

This commit is contained in:
oxalica 2025-03-28 14:22:35 -04:00
parent 348c35720b
commit 13a3b25ee8
2 changed files with 20 additions and 3 deletions

View file

@ -24,8 +24,6 @@ address = "localhost:8080"
# Use systemd socket activation mechanism to get listener fd from envvars.
# See also sd_listen_fds(3) and systemd.socket(5).
# NB. Currently only TCP sockets are supported. UNIX domain socket support is
# blocked by axum 0.5, see https://github.com/tokio-rs/axum/pull/2941
#systemd = true
[server]

View file

@ -47,6 +47,17 @@ in
defaultText = literalMD "blahd package from its flake output";
};
listen = mkOption {
description = mdDoc ''
The address:port or an absolute UNIX socket path to listen on.
If not null, it sets {option}`services.blahd.settings.listen.systemd`
to `true`, and systemd socket activation is configured.
'';
type = types.nullOr types.str;
default = "/run/blahd/blahd.sock";
};
settings = mkOption {
description = ''
blahd configuration.
@ -70,14 +81,22 @@ in
systemd.packages = [ cfg.package ];
environment.systemPackages = [ cfg.package ];
systemd.sockets."blahd" = lib.mkIf (cfg.listen != null) {
wantedBy = [ "sockets.target" ];
listenStreams = [ cfg.listen ];
};
systemd.services."blahd" = lib.mkDefault {
overrideStrategy = "asDropin";
wantedBy = [ "multi-user.target" ];
restartIfChanged = true; # We support graceful shutdown.
stopIfChanged = false;
};
environment.etc."blahd/blahd.toml".source = cfg.settingsFile;
services.blahd.settings = lib.mkIf (cfg.listen != null) {
listen.systemd = true;
};
};
}