From 13a3b25ee8a24ac6d7a5e0b7cb5021d89b09e365 Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 28 Mar 2025 14:22:35 -0400 Subject: [PATCH] Update nix module and config examples for socket activation --- blahd/config.example.toml | 2 -- contrib/module.nix | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/blahd/config.example.toml b/blahd/config.example.toml index b96691a..7f4e062 100644 --- a/blahd/config.example.toml +++ b/blahd/config.example.toml @@ -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] diff --git a/contrib/module.nix b/contrib/module.nix index 5c05313..8e90e67 100644 --- a/contrib/module.nix +++ b/contrib/module.nix @@ -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; + }; }; }