mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-22 01:31:33 +01:00
Configure tailscale docker sidecars for all containers at once
This commit is contained in:
parent
4db060800b
commit
490056a0d7
3 changed files with 52 additions and 71 deletions
|
|
@ -2,45 +2,23 @@
|
||||||
let
|
let
|
||||||
serviceName = "actualbudget";
|
serviceName = "actualbudget";
|
||||||
subdomain = "budget";
|
subdomain = "budget";
|
||||||
|
|
||||||
|
serveConfig = builtins.toJSON {
|
||||||
|
TCP."443".HTTPS = true;
|
||||||
|
Web."${subdomain}.${config.networking.domain}:443".Handlers."/".Proxy = "http://127.0.0.1:5006";
|
||||||
|
};
|
||||||
|
configPath = pkgs.writeTextDir "tailscale-serve.json" serveConfig;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
sops.secrets."container/${serviceName}/tailscale-auth-key" = { };
|
|
||||||
|
|
||||||
virtualisation.oci-containers.containers = {
|
virtualisation.oci-containers.containers = {
|
||||||
${serviceName} = {
|
${serviceName} = {
|
||||||
image = "ghcr.io/actualbudget/actual-server:latest";
|
image = "ghcr.io/actualbudget/actual-server:latest";
|
||||||
volumes = [ "/data/${serviceName}:/data" ];
|
volumes = [ "/data/${serviceName}:/data" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
"tailscale-${serviceName}" =
|
"tailscale-${serviceName}" = {
|
||||||
let
|
environment.TS_HOSTNAME = subdomain;
|
||||||
configPath = pkgs.writeTextFile {
|
volumes = [ "${configPath}:/config" ];
|
||||||
name = "config";
|
};
|
||||||
destination = "/tailscale-serve.json";
|
|
||||||
text = builtins.toJSON {
|
|
||||||
TCP."443".HTTPS = true;
|
|
||||||
Web."${subdomain}.${config.networking.domain}:443".Handlers."/".Proxy = "http://127.0.0.1:5006";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
image = "ghcr.io/tailscale/tailscale:latest";
|
|
||||||
environment = {
|
|
||||||
TS_HOSTNAME = subdomain;
|
|
||||||
TS_STATE_DIR = "/var/lib/tailscale";
|
|
||||||
TS_SERVE_CONFIG = "/config/tailscale-serve.json";
|
|
||||||
TS_USERSPACE = "true"; # https://github.com/tailscale/tailscale/issues/11372
|
|
||||||
};
|
|
||||||
environmentFiles = [
|
|
||||||
# Contains "TS_AUTHKEY=<token>"
|
|
||||||
config.sops.secrets."container/${serviceName}/tailscale-auth-key".path
|
|
||||||
];
|
|
||||||
volumes = [
|
|
||||||
"/var/lib/tailscale-${serviceName}:/var/lib/tailscale"
|
|
||||||
"${configPath}:/config"
|
|
||||||
];
|
|
||||||
extraOptions = [ "--network=container:${serviceName}" ];
|
|
||||||
dependsOn = [ serviceName ];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,34 @@
|
||||||
{ lib, ... }:
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
containers = lib.filterAttrs (_: v: v == "directory") (builtins.readDir ./.);
|
||||||
|
in
|
||||||
{
|
{
|
||||||
imports = lib.mapAttrsToList (name: _: ./${name}) (
|
imports = lib.mapAttrsToList (name: _: ./${name}) containers;
|
||||||
lib.filterAttrs (_: value: value == "directory") (builtins.readDir ./.)
|
|
||||||
);
|
|
||||||
|
|
||||||
virtualisation.oci-containers.backend = "docker";
|
sops.secrets = lib.mapAttrs' (
|
||||||
|
name: _: lib.nameValuePair "container/${name}/tailscale-auth-key" { }
|
||||||
|
) containers;
|
||||||
|
|
||||||
|
virtualisation.oci-containers = {
|
||||||
|
backend = "docker";
|
||||||
|
|
||||||
|
containers = lib.mapAttrs' (
|
||||||
|
name: _:
|
||||||
|
lib.nameValuePair "tailscale-${name}" {
|
||||||
|
image = "ghcr.io/tailscale/tailscale:latest";
|
||||||
|
environment = {
|
||||||
|
TS_STATE_DIR = "/var/lib/tailscale";
|
||||||
|
TS_SERVE_CONFIG = "/config/tailscale-serve.json";
|
||||||
|
TS_USERSPACE = "true"; # https://github.com/tailscale/tailscale/issues/11372
|
||||||
|
};
|
||||||
|
environmentFiles = [
|
||||||
|
# Contains "TS_AUTHKEY=<token>"
|
||||||
|
config.sops.secrets."container/${name}/tailscale-auth-key".path
|
||||||
|
];
|
||||||
|
volumes = [ "/var/lib/tailscale-${name}:/var/lib/tailscale" ];
|
||||||
|
extraOptions = [ "--network=container:${name}" ];
|
||||||
|
dependsOn = [ name ];
|
||||||
|
}
|
||||||
|
) containers;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,15 @@
|
||||||
let
|
let
|
||||||
serviceName = "onlyoffice";
|
serviceName = "onlyoffice";
|
||||||
subdomain = "office";
|
subdomain = "office";
|
||||||
|
|
||||||
|
serveConfig = builtins.toJSON {
|
||||||
|
TCP."443".HTTPS = true;
|
||||||
|
Web."${subdomain}.${config.networking.domain}:443".Handlers."/".Proxy = "http://127.0.0.1:80";
|
||||||
|
};
|
||||||
|
configPath = pkgs.writeTextDir "tailscale-serve.json" serveConfig;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
sops.secrets = {
|
sops.secrets."container/${serviceName}/jwt-secret" = { };
|
||||||
"container/${serviceName}/tailscale-auth-key" = { };
|
|
||||||
"container/${serviceName}/jwt-secret" = { };
|
|
||||||
};
|
|
||||||
|
|
||||||
virtualisation.oci-containers.containers = {
|
virtualisation.oci-containers.containers = {
|
||||||
${serviceName} = {
|
${serviceName} = {
|
||||||
|
|
@ -18,35 +21,9 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
"tailscale-${serviceName}" =
|
"tailscale-${serviceName}" = {
|
||||||
let
|
environment.TS_HOSTNAME = subdomain;
|
||||||
configPath = pkgs.writeTextFile {
|
volumes = [ "${configPath}:/config" ];
|
||||||
name = "config";
|
};
|
||||||
destination = "/tailscale-serve.json";
|
|
||||||
text = builtins.toJSON {
|
|
||||||
TCP."443".HTTPS = true;
|
|
||||||
Web."${subdomain}.${config.networking.domain}:443".Handlers."/".Proxy = "http://127.0.0.1:80";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
image = "ghcr.io/tailscale/tailscale:latest";
|
|
||||||
environment = {
|
|
||||||
TS_HOSTNAME = subdomain;
|
|
||||||
TS_STATE_DIR = "/var/lib/tailscale";
|
|
||||||
TS_SERVE_CONFIG = "/config/tailscale-serve.json";
|
|
||||||
TS_USERSPACE = "true"; # https://github.com/tailscale/tailscale/issues/11372
|
|
||||||
};
|
|
||||||
environmentFiles = [
|
|
||||||
# Contains "TS_AUTHKEY=<token>"
|
|
||||||
config.sops.secrets."container/${serviceName}/tailscale-auth-key".path
|
|
||||||
];
|
|
||||||
volumes = [
|
|
||||||
"/var/lib/tailscale-${serviceName}:/var/lib/tailscale"
|
|
||||||
"${configPath}:/config"
|
|
||||||
];
|
|
||||||
extraOptions = [ "--network=container:${serviceName}" ];
|
|
||||||
dependsOn = [ serviceName ];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue