diff options
| author | tv <tv@krebsco.de> | 2026-11-19 16:48:27 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 16:48:27 +0000 |
| commit | 87b5f6d490d6d18108ef4f7b82b606e77523c26a (patch) | |
| tree | f8a05f57c83b388f4e1a3bca787fef5cd06fe37d /modules | |
| parent | 3328b1744241ddbe8d360c93f5be49ee86c107be (diff) | |
continuum: add module
hrm.continuum.instances.<name> makes a service continuum-<name> from
settings, which are continuum's options, written as TOML into the store.
The service runs as a dynamic user with a state directory and nothing
but the network. It restarts always, as continuum exits with status 0
when a transport stops.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/continuum.nix | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/modules/continuum.nix b/modules/continuum.nix new file mode 100644 index 0000000..1236088 --- /dev/null +++ b/modules/continuum.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: let + cfg = config.hrm.continuum; + format = pkgs.formats.toml {}; +in { + options.hrm.continuum.instances = lib.mkOption { + default = {}; + description = '' + continuum instances. Each is a service continuum-<name> with the state + directory /var/lib/continuum-<name>. + ''; + type = lib.types.attrsOf (lib.types.submodule { + options.settings = lib.mkOption { + default = {}; + description = '' + The instance's configuration: continuum's options by their long + names, see docs/configuration.md and docs/example.toml in continuum. + Text may hold placeholders like ''${env:STATE_DIRECTORY}, which + continuum fills in when it starts. In a Nix string, escape them: + "\''${env:STATE_DIRECTORY}/node.key". Unescaped, Nix takes + env:STATE_DIRECTORY for a URL and drops the braces. + ''; + type = lib.types.submodule { + freeformType = format.type; + }; + }; + }); + }; + + config.systemd.services = lib.mapAttrs' (name: instance: + lib.nameValuePair "continuum-${name}" { + description = "continuum ${name}"; + wantedBy = [ "multi-user.target" ]; + wants = [ "network-online.target" ]; + after = [ "network-online.target" ]; + serviceConfig = { + ExecStart = "${pkgs.continuum}/bin/continuum --config ${ + format.generate "continuum-${name}.toml" instance.settings + }"; + # continuum exits with status 0 when a transport stops, too. + Restart = "always"; + RestartSec = "5s"; + + DynamicUser = true; + StateDirectory = "continuum-${name}"; + StateDirectoryMode = "0700"; + + # It only needs the network and its state directory. + ProtectSystem = "strict"; + ProtectHome = true; + PrivateTmp = true; + PrivateDevices = true; + NoNewPrivileges = true; + RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" "AF_NETLINK" ]; + CapabilityBoundingSet = ""; + SystemCallFilter = [ "@system-service" ]; + }; + } + ) cfg.instances; +} |
