From c8c2f69cc4a6714facbdbc6a8bf15c7f39249362 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Wed, 15 Jan 2020 09:52:39 +0000 Subject: [PATCH] fix(lib/k8s): mkSecretOption, improve errors if name or key not passed --- lib/k8s.nix | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/k8s.nix b/lib/k8s.nix index 97b3266..8cac0b1 100644 --- a/lib/k8s.nix +++ b/lib/k8s.nix @@ -3,27 +3,29 @@ with lib; rec { + # TODO: refactor into mkOptionType mkSecretOption = {description ? "", default ? {}, allowNull ? true}: mkOption { inherit description; type = (if allowNull then types.nullOr else id) (types.submodule { options = { - name = mkOption { + name = mkOption ({ description = "Name of the secret where secret is stored"; type = types.str; - default = default.name or null; - }; + default = default.name; + } // (optionalAttrs (default ? "name") { + default = default.name; + })); - key = mkOption { + key = mkOption ({ description = "Name of the key where secret is stored"; type = types.str; - default = default.key or null; - }; + } // (optionalAttrs (default ? "key") { + default = default.key; + })); }; }); - default = {}; - } // (optionalAttrs (default == null) { - default = null; - })); + default = if default == null then null else {}; + }; secretToEnv = value: { valueFrom.secretKeyRef = {