syntactic sugar for long-syntax secrets

This commit is contained in:
Kiara Grouwstra 2024-08-04 15:28:22 +00:00
parent 5a5ed5202f
commit f216ec0277
2 changed files with 9 additions and 8 deletions

View file

@ -6,15 +6,14 @@
ports = [ ports = [
"8080:80" "8080:80"
]; ];
secrets = [ secrets = {
{ "foo" = {
source = "foo";
target = "/run/secrets/foo"; target = "/run/secrets/foo";
uid = "123"; uid = "123";
gid = "123"; gid = "123";
mode = "0440"; mode = "0440";
} };
]; };
}; };
secrets.foo.environment = "FOO"; secrets.foo.environment = "FOO";
} }

View file

@ -128,7 +128,7 @@ in
''; '';
}; };
secrets = mkOption { secrets = mkOption {
type = nullOr (listOf (either str serviceSecretType)); type = nullOr (either (listOf str) (attrsOf serviceSecretType));
default = null; default = null;
description = '' description = ''
Build-time secrets exposed to the service. Build-time secrets exposed to the service.
@ -138,7 +138,7 @@ in
}); });
}; };
service.secrets = mkOption { service.secrets = mkOption {
type = nullOr (listOf (either str serviceSecretType)); type = nullOr (either (listOf str) (attrsOf serviceSecretType));
default = []; default = [];
description = '' description = ''
Run-time secrets exposed to the service. Run-time secrets exposed to the service.
@ -451,7 +451,9 @@ in
} // lib.optionalAttrs (config.service.extra_hosts != []) { } // lib.optionalAttrs (config.service.extra_hosts != []) {
inherit (config.service) extra_hosts; inherit (config.service) extra_hosts;
} // lib.optionalAttrs (config.service.secrets != []) { } // lib.optionalAttrs (config.service.secrets != []) {
secrets = lib.lists.map (s: { secrets = lib.mapAttrsToList (k: s: {
source = k;
target = k;
} // lib.optionalAttrs (s.source != null) { } // lib.optionalAttrs (s.source != null) {
inherit (s) source; inherit (s) source;
} // lib.optionalAttrs (s.target != null) { } // lib.optionalAttrs (s.target != null) {