From 45934f0c923d00863a6ec28ee20ee9b93b11ffc1 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 7 Nov 2024 03:01:45 +0100 Subject: [PATCH] Fetch FQDN from configuration --- lib/modules/valhalla.nix | 8 +++++++- scripts/Common/Software/docker/services/service.fish | 7 ++++++- .../docker/services/vaultwarden/docker-compose.yml | 4 ++-- .../Software/docker/services/vaultwarden/main.fish | 9 +++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/modules/valhalla.nix b/lib/modules/valhalla.nix index 8d0b6113..9007c820 100644 --- a/lib/modules/valhalla.nix +++ b/lib/modules/valhalla.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ config, lib, ... }: let inherit (lib) mkOption types; in { imports = [ @@ -28,6 +28,12 @@ in { }; }; + fqdn = mkOption { + type = types.str; + description = "The FQDN of the system."; + default = config.valhalla.hostname; + }; + hostname = mkOption { type = types.str; description = "The hostname of the system."; diff --git a/scripts/Common/Software/docker/services/service.fish b/scripts/Common/Software/docker/services/service.fish index 39200084..f24d9c01 100644 --- a/scripts/Common/Software/docker/services/service.fish +++ b/scripts/Common/Software/docker/services/service.fish @@ -12,8 +12,13 @@ begin echo "$_flag_name" end + function getMachineFQDN -V dir + source "$dir/../../../../lib/settings.fish" + getOSConfig fqdn + end + function getServiceDomain - echo "$(getServiceSubdomain $argv).nuth.ch" + echo "$(getServiceSubdomain $argv).$(getMachineFQDN)" end function getServiceSubdomain diff --git a/scripts/Common/Software/docker/services/vaultwarden/docker-compose.yml b/scripts/Common/Software/docker/services/vaultwarden/docker-compose.yml index a7b43080..10a3aa05 100644 --- a/scripts/Common/Software/docker/services/vaultwarden/docker-compose.yml +++ b/scripts/Common/Software/docker/services/vaultwarden/docker-compose.yml @@ -9,9 +9,9 @@ services: - ./data:/data - /etc/localtime:/etc/localtime:ro environment: - DOMAIN: https://passwords.nuth.ch + DOMAIN: null SMTP_HOST: bridge - SMTP_FROM: no-reply@nuth.ch + SMTP_FROM: null SMTP_FROM_VALUE: vaultwarden SMTP_PORT: 25 SMTP_ACCEPT_INVALID_CERTS: "true" diff --git a/scripts/Common/Software/docker/services/vaultwarden/main.fish b/scripts/Common/Software/docker/services/vaultwarden/main.fish index d61c931e..b7349ae8 100644 --- a/scripts/Common/Software/docker/services/vaultwarden/main.fish +++ b/scripts/Common/Software/docker/services/vaultwarden/main.fish @@ -9,11 +9,16 @@ begin end function installSW -V dir -V source + set -l file "$dir/docker-compose.yml" set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") - set -l dbKey ".services.vaultwarden.environment.DATABASE_URL" + set -l envKey ".services.vaultwarden.environment" + set -l dbKey "$envKey.DATABASE_URL" set -l dbUrl (yq --raw-output "$dbKey" "$source" | sed "s/^\(.*:\/\/.*:\).*\(@.*\/.*\)\$/\1$pw\2/") initializeServiceInstallation $argv - sudo cp "$dir/docker-compose.yml" (getServiceRoot $argv) + + URL="https://$(getServiceDomain $argv)" yq "$envKey.DOMAIN = env.URL" "$file" | \ + ADDRESS="noreply@$(getMachineFQDN)" yq -y "$envKey.SMTP_FROM = env.ADDRESS" | \ + sudo tee "$(getServiceRoot $argv)/$(basename "$file")" >/dev/null URL=$dbUrl yq "$dbKey = env.URL" "$source" | \ PW=$pw yq ".services.db.environment.MARIADB_PASSWORD = env.PW" | \