Update modules/server/containers/builder.nix
This commit is contained in:
@@ -1,34 +1,41 @@
|
|||||||
{ config, lib, pkgs, serverCfg }:
|
{ config, lib, pkgs, serverCfg }:
|
||||||
let
|
let
|
||||||
builder =
|
builder =
|
||||||
{ image ? null, imageStream ? null
|
{ image ? null, imageStream ? null, imageFile ? null
|
||||||
, secret ? null
|
, secret ? null
|
||||||
, subdomain ? null, ip ? null, port ? 0
|
, subdomain ? null, subpath?null, port ? 0
|
||||||
, extraEnv ? { }, extraLabels ? { }, extraOptions ? [ ]
|
, extraEnv ? { }, extraLabels ? { }, extraOptions ? [ ]
|
||||||
, overrides ? { }
|
, overrides ? { }
|
||||||
}:
|
}:
|
||||||
let base = {
|
let
|
||||||
|
routerName = if subpath != null
|
||||||
|
then "${subdomain}-${lib.strings.sanitizeDerivationName subpath}"
|
||||||
|
else subdomain;
|
||||||
|
base = {
|
||||||
image = if imageStream != null then "${imageStream.imageName}:${imageStream.imageTag}"
|
image = if imageStream != null then "${imageStream.imageName}:${imageStream.imageTag}"
|
||||||
else image;
|
else image;
|
||||||
imageStream = imageStream;
|
imageStream = imageStream;
|
||||||
|
imageFile = imageFile;
|
||||||
|
|
||||||
environmentFiles = if secret!=null then [ config.sops.secrets."${lib.toUpper secret}".path ] else [];
|
environmentFiles = if secret!=null then [ config.sops.secrets."${lib.toUpper secret}".path ] else [];
|
||||||
environment = {} // extraEnv;
|
environment = {} // extraEnv;
|
||||||
|
|
||||||
labels = (if subdomain!=null then ({
|
labels = (if subdomain!=null then ({
|
||||||
"traefik.enable" = "true";
|
"traefik.enable" = "true";
|
||||||
"traefik.http.routers.${subdomain}.entrypoints" = "web-secure";
|
"traefik.http.routers.${routerName}.entrypoints" = "web-secure";
|
||||||
"traefik.http.routers.${subdomain}.rule" = "Host(`${subdomain}.${serverCfg.hostDomain}`)";
|
"traefik.http.routers.${routerName}.rule" = if subpath != null
|
||||||
"traefik.http.routers.${subdomain}.tls" = "true";
|
then "Host(`${subdomain}.${serverCfg.hostDomain}`) && PathPrefix(`/${subpath}`)"
|
||||||
|
else "Host(`${subdomain}.${serverCfg.hostDomain}`)";
|
||||||
|
"traefik.http.routers.${routerName}.tls" = "true";
|
||||||
} // lib.optionalAttrs (port!=null) {
|
} // lib.optionalAttrs (port!=null) {
|
||||||
"traefik.http.services.${subdomain}.loadbalancer.server.port" = toString port;
|
"traefik.http.services.${routerName}.loadbalancer.server.port" = toString port;
|
||||||
}) else {
|
}) else {
|
||||||
"traefik.enable" = "false";
|
"traefik.enable" = "false";
|
||||||
}) // extraLabels;
|
}) // extraLabels;
|
||||||
|
|
||||||
extraOptions = extraOptions ++ [
|
extraOptions = extraOptions ++ [
|
||||||
"--add-host=host.containers.internal:host-gateway"
|
"--add-host=host.containers.internal:host-gateway"
|
||||||
] ++ lib.optional (ip!=null) "--ip=${ip}";
|
];
|
||||||
};
|
};
|
||||||
in lib.recursiveUpdate base overrides;
|
in lib.recursiveUpdate base overrides;
|
||||||
in {
|
in {
|
||||||
|
|||||||
Reference in New Issue
Block a user