1 { config, lib, pkgs, ... }:
6 cfg = config.services.envoy;
7 format = pkgs.formats.json { };
8 conf = format.generate "envoy.json" cfg.settings;
10 pkgs.runCommand "validate-envoy-conf" { } ''
11 ${pkgs.envoy}/bin/envoy --log-level error --mode validate -c "${file}"
18 options.services.envoy = {
19 enable = mkEnableOption (lib.mdDoc "Envoy reverse proxy");
24 example = literalExpression ''
27 access_log_path = "/dev/null";
31 address = "127.0.0.1";
42 description = lib.mdDoc ''
43 Specify the configuration for Envoy in Nix.
48 config = mkIf cfg.enable {
49 environment.systemPackages = [ pkgs.envoy ];
50 systemd.services.envoy = {
51 description = "Envoy reverse proxy";
52 after = [ "network-online.target" ];
53 requires = [ "network-online.target" ];
54 wantedBy = [ "multi-user.target" ];
56 ExecStart = "${pkgs.envoy}/bin/envoy -c ${validateConfig conf}";
59 CacheDirectory = "envoy";
60 LogsDirectory = "envoy";
61 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
62 CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
63 RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK AF_XDP";
64 SystemCallArchitectures = "native";
65 LockPersonality = true;
66 RestrictNamespaces = true;
67 RestrictRealtime = true;
68 PrivateUsers = false; # breaks CAP_NET_BIND_SERVICE
69 PrivateDevices = true;
71 ProtectControlGroups = true;
73 ProtectKernelLogs = true;
74 ProtectKernelModules = true;
75 ProtectKernelTunables = true;
76 ProtectProc = "ptraceable";
77 ProtectHostname = true;
78 ProtectSystem = "strict";
80 SystemCallFilter = "~@clock @module @mount @reboot @swap @obsolete @cpu-emulation";