feat(lib): add mkValueOrSecretOption

This commit is contained in:
Jaka Hudoklin 2017-11-11 13:42:15 +01:00
parent cbf84e25a5
commit 30c9de967f
3 changed files with 36 additions and 8 deletions

25
lib.nix
View file

@ -29,4 +29,29 @@ rec {
toBase64 = value:
builtins.readFile
(pkgs.runCommand "value-to-b64" {} "echo '${value}' | ${pkgs.coreutils}/bin/base64 -w0 > $out");
mkValueOrSecretOption = {...}@options: mkOption ({
type = types.either types.str (types.submodule {
options.secret = mkOption {
description = "Name of the secret where password is stored";
type = types.str;
};
options.key = mkOption {
description = "Name of the key where password is stored";
type = types.str;
default = "password";
};
});
apply = value:
if isAttrs value
then {
valueFrom.secretKeyRef = {
name = value.secret;
key = value.key;
};
}
else {inherit value;};
} // options);
}