mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 19:55:41 +03:00

After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
116 lines
3.2 KiB
Nix
116 lines
3.2 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.envoy;
|
|
format = pkgs.formats.json { };
|
|
conf = format.generate "envoy.json" cfg.settings;
|
|
validateConfig =
|
|
required: file:
|
|
pkgs.runCommand "validate-envoy-conf" { } ''
|
|
${cfg.package}/bin/envoy --log-level error --mode validate -c "${file}" ${
|
|
lib.optionalString (!required) "|| true"
|
|
}
|
|
cp "${file}" "$out"
|
|
'';
|
|
in
|
|
|
|
{
|
|
options.services.envoy = {
|
|
enable = lib.mkEnableOption "Envoy reverse proxy";
|
|
|
|
package = lib.mkPackageOption pkgs "envoy" { };
|
|
|
|
requireValidConfig = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = true;
|
|
description = ''
|
|
Whether a failure during config validation at build time is fatal.
|
|
When the config can't be checked during build time, for example when it includes
|
|
other files, disable this option.
|
|
'';
|
|
};
|
|
|
|
settings = lib.mkOption {
|
|
type = format.type;
|
|
default = { };
|
|
example = lib.literalExpression ''
|
|
{
|
|
admin = {
|
|
access_log_path = "/dev/null";
|
|
address = {
|
|
socket_address = {
|
|
protocol = "TCP";
|
|
address = "127.0.0.1";
|
|
port_value = 9901;
|
|
};
|
|
};
|
|
};
|
|
static_resources = {
|
|
listeners = [];
|
|
clusters = [];
|
|
};
|
|
}
|
|
'';
|
|
description = ''
|
|
Specify the configuration for Envoy in Nix.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
environment.systemPackages = [ cfg.package ];
|
|
systemd.services.envoy = {
|
|
description = "Envoy reverse proxy";
|
|
after = [ "network-online.target" ];
|
|
requires = [ "network-online.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
ExecStart = "${cfg.package}/bin/envoy -c ${validateConfig cfg.requireValidConfig conf}";
|
|
CacheDirectory = [ "envoy" ];
|
|
LogsDirectory = [ "envoy" ];
|
|
Restart = "no";
|
|
# Hardening
|
|
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
|
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
|
|
DeviceAllow = [ "" ];
|
|
DevicePolicy = "closed";
|
|
DynamicUser = true;
|
|
LockPersonality = true;
|
|
MemoryDenyWriteExecute = false; # at least wasmr needs WX permission
|
|
PrivateDevices = true;
|
|
PrivateUsers = false; # breaks CAP_NET_BIND_SERVICE
|
|
ProcSubset = "pid";
|
|
ProtectClock = true;
|
|
ProtectControlGroups = true;
|
|
ProtectHome = true;
|
|
ProtectHostname = true;
|
|
ProtectKernelLogs = true;
|
|
ProtectKernelModules = true;
|
|
ProtectKernelTunables = true;
|
|
ProtectProc = "ptraceable";
|
|
ProtectSystem = "strict";
|
|
RestrictAddressFamilies = [
|
|
"AF_UNIX"
|
|
"AF_INET"
|
|
"AF_INET6"
|
|
"AF_NETLINK"
|
|
"AF_XDP"
|
|
];
|
|
RestrictNamespaces = true;
|
|
RestrictRealtime = true;
|
|
SystemCallArchitectures = "native";
|
|
SystemCallErrorNumber = "EPERM";
|
|
SystemCallFilter = [
|
|
"@system-service"
|
|
"~@privileged"
|
|
"~@resources"
|
|
];
|
|
UMask = "0066";
|
|
};
|
|
};
|
|
};
|
|
}
|