8 cfg = config.services.envoy;
9 format = pkgs.formats.json { };
10 conf = format.generate "envoy.json" cfg.settings;
13 pkgs.runCommand "validate-envoy-conf" { } ''
14 ${cfg.package}/bin/envoy --log-level error --mode validate -c "${file}" ${
15 lib.optionalString (!required) "|| true"
22 options.services.envoy = {
23 enable = lib.mkEnableOption "Envoy reverse proxy";
25 package = lib.mkPackageOption pkgs "envoy" { };
27 requireValidConfig = lib.mkOption {
28 type = lib.types.bool;
31 Whether a failure during config validation at build time is fatal.
32 When the config can't be checked during build time, for example when it includes
33 other files, disable this option.
37 settings = lib.mkOption {
40 example = lib.literalExpression ''
43 access_log_path = "/dev/null";
47 address = "127.0.0.1";
59 Specify the configuration for Envoy in Nix.
64 config = lib.mkIf cfg.enable {
65 environment.systemPackages = [ cfg.package ];
66 systemd.services.envoy = {
67 description = "Envoy reverse proxy";
68 after = [ "network-online.target" ];
69 requires = [ "network-online.target" ];
70 wantedBy = [ "multi-user.target" ];
72 ExecStart = "${cfg.package}/bin/envoy -c ${validateConfig cfg.requireValidConfig conf}";
73 CacheDirectory = [ "envoy" ];
74 LogsDirectory = [ "envoy" ];
77 AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
78 CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
80 DevicePolicy = "closed";
82 LockPersonality = true;
83 MemoryDenyWriteExecute = false; # at least wasmr needs WX permission
84 PrivateDevices = true;
85 PrivateUsers = false; # breaks CAP_NET_BIND_SERVICE
88 ProtectControlGroups = true;
90 ProtectHostname = true;
91 ProtectKernelLogs = true;
92 ProtectKernelModules = true;
93 ProtectKernelTunables = true;
94 ProtectProc = "ptraceable";
95 ProtectSystem = "strict";
96 RestrictAddressFamilies = [
103 RestrictNamespaces = true;
104 RestrictRealtime = true;
105 SystemCallArchitectures = "native";
106 SystemCallErrorNumber = "EPERM";