From 642a31b0d074cdbd5e3e48e807289eb70ab808a3 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Fri, 29 Dec 2017 10:20:19 +0100 Subject: [PATCH] feat(lib): make explicit secretToEnv function that converts mkSecretOption to env --- default.nix | 2 +- lib.nix | 12 ++++++------ test/modules.nix | 8 +++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/default.nix b/default.nix index 431f328..018b8f9 100644 --- a/default.nix +++ b/default.nix @@ -14,7 +14,7 @@ let args = { inherit pkgs; name = "default"; - k8s = { inherit loadJSON loadYAML toYAML toBase64 octalToDecimal mkSecretOption; }; + k8s = { inherit loadJSON loadYAML toYAML toBase64 octalToDecimal mkSecretOption secretToEnv; }; }; }; diff --git a/lib.nix b/lib.nix index 2fb4588..7e662fc 100644 --- a/lib.nix +++ b/lib.nix @@ -62,11 +62,11 @@ rec { }; }; }); - - apply = value: if value == null then null else { - valueFrom.secretKeyRef = { - inherit (value) name key; - }; - }; }); + + secretToEnv = value: { + valueFrom.secretKeyRef = { + inherit (value) name key; + }; + }; } diff --git a/test/modules.nix b/test/modules.nix index 282f0c3..2b2cc4f 100644 --- a/test/modules.nix +++ b/test/modules.nix @@ -15,10 +15,7 @@ with lib; password = mkSecretOption { description = "Nginx simple auth credentials"; - default = { - key = "test"; - name = "test"; - }; + default = null; }; }; @@ -32,7 +29,8 @@ with lib; containerPort = config.port; }; - spec.template.spec.containers.nginx.env.name = mkIf (config.password != null) config.password; + spec.template.spec.containers.nginx.env.name = + mkIf (config.password != null) (secretToEnv config.password); } ];