1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-19 07:59:24 +03:00
nixpkgs/nixos/modules/services/web-servers/agate.nix

166 lines
4 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}:
2022-02-07 16:03:44 +00:00
with lib;
let
cfg = config.services.agate;
in
{
options = {
services.agate = {
enable = mkEnableOption "Agate Server";
2022-02-07 16:03:44 +00:00
package = mkPackageOption pkgs "agate" { };
2022-02-07 16:03:44 +00:00
addresses = mkOption {
type = types.listOf types.str;
default = [ "0.0.0.0:1965" ];
description = ''
2022-02-07 16:03:44 +00:00
Addresses to listen on, IP:PORT, if you haven't disabled forwarding
only set IPv4.
'';
};
contentDir = mkOption {
default = "/var/lib/agate/content";
type = types.path;
description = "Root of the content directory.";
2022-02-07 16:03:44 +00:00
};
certificatesDir = mkOption {
default = "/var/lib/agate/certificates";
type = types.path;
description = "Root of the certificate directory.";
2022-02-07 16:03:44 +00:00
};
hostnames = mkOption {
default = [ ];
type = types.listOf types.str;
description = ''
2022-02-07 16:03:44 +00:00
Domain name of this Gemini server, enables checking hostname and port
2022-12-17 19:31:14 -05:00
in requests. (multiple occurrences means basic vhosts)
2022-02-07 16:03:44 +00:00
'';
};
language = mkOption {
default = null;
type = types.nullOr types.str;
description = "RFC 4646 Language code for text/gemini documents.";
2022-02-07 16:03:44 +00:00
};
onlyTls_1_3 = mkOption {
default = false;
type = types.bool;
description = "Only use TLSv1.3 (default also allows TLSv1.2).";
2022-02-07 16:03:44 +00:00
};
extraArgs = mkOption {
type = types.listOf types.str;
default = [ "" ];
example = [ "--log-ip" ];
description = "Extra arguments to use running agate.";
2022-02-07 16:03:44 +00:00
};
};
};
config = mkIf cfg.enable {
# available for generating certs by hand
# it can be a bit arduous with openssl
environment.systemPackages = [ cfg.package ];
systemd.services.agate = {
description = "Agate";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [
"network.target"
"network-online.target"
];
2022-02-07 16:03:44 +00:00
script =
let
prefixKeyList =
key: list:
concatMap (v: [
key
v
]) list;
2022-02-07 16:03:44 +00:00
addresses = prefixKeyList "--addr" cfg.addresses;
hostnames = prefixKeyList "--hostname" cfg.hostnames;
in
''
exec ${cfg.package}/bin/agate ${
escapeShellArgs (
[
"--content"
"${cfg.contentDir}"
"--certs"
"${cfg.certificatesDir}"
]
++ addresses
++ (optionals (cfg.hostnames != [ ]) hostnames)
++ (optionals (cfg.language != null) [
"--lang"
cfg.language
])
++ (optionals cfg.onlyTls_1_3 [ "--only-tls13" ])
++ (optionals (cfg.extraArgs != [ ]) cfg.extraArgs)
2022-02-07 16:03:44 +00:00
)
}
'';
serviceConfig = {
Restart = "always";
RestartSec = "5s";
DynamicUser = true;
StateDirectory = "agate";
# Security options:
AmbientCapabilities = "";
CapabilityBoundingSet = "";
# ProtectClock= adds DeviceAllow=char-rtc r
DeviceAllow = "";
LockPersonality = true;
PrivateTmp = true;
PrivateDevices = true;
PrivateUsers = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
RestrictNamespaces = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
];
2022-02-07 16:03:44 +00:00
RestrictRealtime = true;
SystemCallArchitectures = "native";
SystemCallErrorNumber = "EPERM";
SystemCallFilter = [
"@system-service"
"~@cpu-emulation"
"~@debug"
"~@keyring"
"~@memlock"
"~@obsolete"
"~@privileged"
"~@setuid"
];
};
};
};
}