git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #166894 from CameronNemo/nixos-mod-envoy

nixos/envoy: init

commit3838b7e07e8a79ece6cb249eb4bf0a2bfd6d388a authorpennae <82953136+pennae@users.noreply.github.com> dateThu 7 Apr 2022, 16:23 (5 years ago) parenta62b1ef1b4b16e
7 files changed+131−2
nixos/doc/manual/from_md/release-notes/rl-2205.section.xml+7 nixos/doc/manual/release-notes/rl-2205.section.md+2 nixos/modules/module-list.nix+1 nixos/modules/services/networking/envoy.nix+84 nixos/tests/all-tests.nix+1 nixos/tests/envoy.nix+33 pkgs/servers/http/envoy/default.nix+3−2
nixos/doc/manual/from_md/release-notes/rl-2205.section.xml+7
@@ -1538,6 +1538,13 @@
15381538 configuration.
15391539 </para>
15401540 </listitem>
1541+ <listitem>
1542+ <para>
1543+ A new module was added for the Envoy reverse proxy, providing
1544+ the options <literal>services.envoy.enable</literal> and
1545+ <literal>services.envoy.settings</literal>.
1546+ </para>
1547+ </listitem>
15411548 <listitem>
15421549 <para>
15431550 The option <literal>services.duplicati.dataDir</literal> has
nixos/doc/manual/release-notes/rl-2205.section.md+2
@@ -547,6 +547,8 @@ In addition to numerous new and upgraded packages, this release has the followin
547547
548548- The `services.stubby` module was converted to a [settings-style](https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md) configuration.
549549
550+- A new module was added for the Envoy reverse proxy, providing the options `services.envoy.enable` and `services.envoy.settings`.
551+
550552- The option `services.duplicati.dataDir` has been added to allow changing the location of duplicati's files.
551553
552554- The options `boot.extraModprobeConfig` and `boot.blacklistedKernelModules` now also take effect in the initrd by copying the file `/etc/modprobe.d/nixos.conf` into the initrd.
nixos/modules/module-list.nix+1
@@ -753,6 +753,7 @@
753753 ./services/networking/ncdns.nix
754754 ./services/networking/nomad.nix
755755 ./services/networking/ejabberd.nix
756+ ./services/networking/envoy.nix
756757 ./services/networking/epmd.nix
757758 ./services/networking/ergo.nix
758759 ./services/networking/ergochat.nix
nixos/modules/services/networking/envoy.nixnew file+84
@@ -0,0 +1,84 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.envoy;
7+ format = pkgs.formats.json { };
8+ conf = format.generate "envoy.json" cfg.settings;
9+ validateConfig = file:
10+ pkgs.runCommand "validate-envoy-conf" { } ''
11+ ${pkgs.envoy}/bin/envoy --log-level error --mode validate -c "${file}"
12+ cp "${file}" "$out"
13+ '';
14+
15+in
16+
17+{
18+ options.services.envoy = {
19+ enable = mkEnableOption "Envoy reverse proxy";
20+
21+ settings = mkOption {
22+ type = format.type;
23+ default = { };
24+ example = literalExpression ''
25+ {
26+ admin = {
27+ access_log_path = "/dev/null";
28+ address = {
29+ socket_address = {
30+ protocol = "TCP";
31+ address = "127.0.0.1";
32+ port_value = 9901;
33+ };
34+ };
35+ };
36+ static_resources = {
37+ listeners = [];
38+ clusters = [];
39+ };
40+ }
41+ '';
42+ description = ''
43+ Specify the configuration for Envoy in Nix.
44+ '';
45+ };
46+ };
47+
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" ];
55+ serviceConfig = {
56+ ExecStart = "${pkgs.envoy}/bin/envoy -c ${validateConfig conf}";
57+ DynamicUser = true;
58+ Restart = "no";
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;
70+ ProtectClock = true;
71+ ProtectControlGroups = true;
72+ ProtectHome = true;
73+ ProtectKernelLogs = true;
74+ ProtectKernelModules = true;
75+ ProtectKernelTunables = true;
76+ ProtectProc = "ptraceable";
77+ ProtectHostname = true;
78+ ProtectSystem = "strict";
79+ UMask = "0066";
80+ SystemCallFilter = "~@clock @module @mount @reboot @swap @obsolete @cpu-emulation";
81+ };
82+ };
83+ };
84+}
nixos/tests/all-tests.nix+1
@@ -142,6 +142,7 @@ in
142142 engelsystem = handleTest ./engelsystem.nix {};
143143 enlightenment = handleTest ./enlightenment.nix {};
144144 env = handleTest ./env.nix {};
145+ envoy = handleTest ./envoy.nix {};
145146 ergo = handleTest ./ergo.nix {};
146147 ergochat = handleTest ./ergochat.nix {};
147148 etc = pkgs.callPackage ../modules/system/etc/test.nix { inherit evalMinimalConfig; };
nixos/tests/envoy.nixnew file+33
@@ -0,0 +1,33 @@
1+import ./make-test-python.nix ({ pkgs, lib, ...} : {
2+ name = "envoy";
3+ meta = with pkgs.lib.maintainers; {
4+ maintainers = [ cameronnemo ];
5+ };
6+
7+ nodes.machine = { pkgs, ... }: {
8+ services.envoy.enable = true;
9+ services.envoy.settings = {
10+ admin = {
11+ access_log_path = "/dev/null";
12+ address = {
13+ socket_address = {
14+ protocol = "TCP";
15+ address = "127.0.0.1";
16+ port_value = 9901;
17+ };
18+ };
19+ };
20+ static_resources = {
21+ listeners = [];
22+ clusters = [];
23+ };
24+ };
25+ };
26+
27+ testScript = ''
28+ machine.start()
29+ machine.wait_for_unit("envoy.service")
30+ machine.wait_for_open_port(9901)
31+ machine.wait_until_succeeds("curl -fsS localhost:9901/ready")
32+ '';
33+})
pkgs/servers/http/envoy/default.nix+3−2
@@ -127,8 +127,9 @@ buildBazelPackage rec {
127127 ];
128128
129129 passthru.tests = {
130− # No tests for Envoy itself (yet), but it's tested as a core component of Pomerium.
131− inherit (nixosTests) pomerium;
130+ envoy = nixosTests.envoy;
131+ # tested as a core component of Pomerium
132+ pomerium = nixosTests.pomerium;
132133 };
133134
134135 meta = with lib; {