treewide: use optionalAttrs instead of 'else {}'

This commit is contained in:
Felix Buehler 2023-06-25 12:25:42 +02:00 committed by Anderson Torres
parent fa6b5a3cb3
commit 6672dde558
31 changed files with 51 additions and 66 deletions

View file

@ -800,14 +800,14 @@ in
# declarative containers
++ (mapAttrsToList (name: cfg: nameValuePair "container@${name}" (let
containerConfig = cfg // (
if cfg.enableTun then
optionalAttrs cfg.enableTun
{
allowedDevices = cfg.allowedDevices
++ [ { node = "/dev/net/tun"; modifier = "rw"; } ];
additionalCapabilities = cfg.additionalCapabilities
++ [ "CAP_NET_ADMIN" ];
}
else {});
);
in
recursiveUpdate unit {
preStart = preStartScript containerConfig;
@ -817,7 +817,7 @@ in
unitConfig.RequiresMountsFor = lib.optional (!containerConfig.ephemeral) "${stateDirectory}/%i";
environment.root = if containerConfig.ephemeral then "/run/nixos-containers/%i" else "${stateDirectory}/%i";
} // (
if containerConfig.autoStart then
optionalAttrs containerConfig.autoStart
{
wantedBy = [ "machines.target" ];
wants = [ "network.target" ];
@ -828,7 +828,7 @@ in
];
restartIfChanged = true;
}
else {})
)
)) config.containers)
));