From 37792e5766ced355c8c93140a108950300b67fe1 Mon Sep 17 00:00:00 2001 From: linj Date: Tue, 15 Mar 2022 01:10:55 +0800 Subject: nixos/dendrite: add an option loadCredential systemd-247 provides a mechanism called LoadCredential for secrets and it is better than environment file. See the section of Environment= in the manual of systemd.exec for more information. Some options in config.yaml need values to be strings, which currently can be used with environmentFile but not loadCredential. But it's possible to use loadCredential for those options, e.g. we can substitute their values in ExecStart, but not in ExecStartPre due to [1]. [1]: https://github.com/systemd/systemd/issues/19604 --- nixos/modules/services/misc/dendrite.nix | 19 +++++++++++++++++-- nixos/tests/dendrite.nix | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/misc/dendrite.nix b/nixos/modules/services/misc/dendrite.nix index ac5df9951b3..54052084b33 100644 --- a/nixos/modules/services/misc/dendrite.nix +++ b/nixos/modules/services/misc/dendrite.nix @@ -74,6 +74,18 @@ in dendrite is running. ''; }; + loadCredential = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + example = [ "private_key:/path/to/my_private_key" ]; + description = '' + This can be used to pass secrets to the systemd service without adding them to + the nix store. + To use the example setting, see the example of + . + See the LoadCredential section of systemd.exec manual for more information. + ''; + }; settings = lib.mkOption { type = lib.types.submodule { freeformType = settingsFormat.type; @@ -88,8 +100,10 @@ in ''; }; private_key = lib.mkOption { - type = lib.types.path; - example = "${workingDir}/matrix_key.pem"; + type = lib.types.either + lib.types.path + (lib.types.strMatching "^\\$CREDENTIALS_DIRECTORY/.+"); + example = "$CREDENTIALS_DIRECTORY/private_key"; description = '' The path to the signing private key file, used to sign requests and events. @@ -256,6 +270,7 @@ in RuntimeDirectoryMode = "0700"; LimitNOFILE = 65535; EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; + LoadCredential = cfg.loadCredential; ExecStartPre = '' ${pkgs.envsubst}/bin/envsubst \ -i ${configurationYaml} \ diff --git a/nixos/tests/dendrite.nix b/nixos/tests/dendrite.nix index d4a5bb13226..1ff415433b4 100644 --- a/nixos/tests/dendrite.nix +++ b/nixos/tests/dendrite.nix @@ -17,10 +17,11 @@ import ./make-test-python.nix ( homeserver = { pkgs, ... }: { services.dendrite = { enable = true; + loadCredential = [ "test_private_key:${private_key}" ]; openRegistration = true; settings = { global.server_name = "test-dendrite-server.com"; - global.private_key = private_key; + global.private_key = "$CREDENTIALS_DIRECTORY/test_private_key"; client_api.registration_disabled = false; }; }; -- cgit 1.4.1