From e233e7d385036ee811e911fcf599ae9eb4274ddf Mon Sep 17 00:00:00 2001 From: eyjhb Date: Wed, 14 Aug 2024 12:14:48 +0200 Subject: [PATCH 1/2] nixos/teeworlds: add option `environmentFile` for injecting secrets --- nixos/modules/services/games/teeworlds.nix | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/games/teeworlds.nix b/nixos/modules/services/games/teeworlds.nix index b21fe008896a..77942c46a083 100644 --- a/nixos/modules/services/games/teeworlds.nix +++ b/nixos/modules/services/games/teeworlds.nix @@ -368,6 +368,33 @@ in ''; }; }; + + environmentFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + example = "/var/lib/teeworlds/teeworlds.env"; + description = '' + Environment file as defined in {manpage}`systemd.exec(5)`. + + Secrets may be passed to the service without adding them to the world-readable + Nix store, by specifying placeholder variables as the option value in Nix and + setting these variables accordingly in the environment file. + + ``` + # snippet of teeworlds-related config + services.teeworlds.password = "$TEEWORLDS_PASSWORD"; + ``` + + ``` + # content of the environment file + TEEWORLDS_PASSWORD=verysecretpassword + ``` + + Note that this file needs to be available on the host on which + `teeworlds` is running. + ''; + }; + }; }; @@ -383,7 +410,15 @@ in serviceConfig = { DynamicUser = true; - ExecStart = "${cfg.package}/bin/teeworlds_srv -f ${teeworldsConf}"; + RuntimeDirectory = "teeworlds"; + RuntimeDirectoryMode = "0700"; + EnvironmentFile = lib.mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]; + ExecStartPre = '' + ${pkgs.envsubst}/bin/envsubst \ + -i ${teeworldsConf} \ + -o /run/teeworlds/teeworlds.yaml + ''; + ExecStart = "${cfg.package}/bin/teeworlds_srv -f /run/teeworlds/teeworlds.yaml"; # Hardening CapabilityBoundingSet = false; From a719f91a85a2c303f00fa72e98b6acdf3ee56528 Mon Sep 17 00:00:00 2001 From: eyjhb Date: Tue, 10 Sep 2024 11:40:24 +0200 Subject: [PATCH 2/2] nixos/teeworlds: use `lib.getExe` instead of hardcoded path --- nixos/modules/services/games/teeworlds.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/games/teeworlds.nix b/nixos/modules/services/games/teeworlds.nix index 77942c46a083..f12647149573 100644 --- a/nixos/modules/services/games/teeworlds.nix +++ b/nixos/modules/services/games/teeworlds.nix @@ -418,7 +418,7 @@ in -i ${teeworldsConf} \ -o /run/teeworlds/teeworlds.yaml ''; - ExecStart = "${cfg.package}/bin/teeworlds_srv -f /run/teeworlds/teeworlds.yaml"; + ExecStart = "${lib.getExe cfg.package} -f /run/teeworlds/teeworlds.yaml"; # Hardening CapabilityBoundingSet = false;