From b24eed9a86d20f745f71e5996f308d8ef54ddfd7 Mon Sep 17 00:00:00 2001 From: ibizaman Date: Tue, 16 Sep 2025 21:09:38 +0200 Subject: [PATCH] lib: add toEnvVar function --- lib/default.nix | 3 ++- modules/blocks/restic.nix | 4 ++-- modules/services/vaultwarden.nix | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 51fa00d..5590883 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,7 +1,7 @@ { pkgs, lib }: let inherit (builtins) isAttrs hasAttr; - inherit (lib) any concatMapStringsSep concatStringsSep mapAttrsToList; + inherit (lib) any concatMapStringsSep concatStringsSep; in rec { # Replace secrets in a file. @@ -25,6 +25,7 @@ rec { replaceSecretsFormatAdapter = format: format.generate; replaceSecretsGeneratorAdapter = generator: name: value: pkgs.writeText "generator " (generator value); + toEnvVar = replaceSecretsGeneratorAdapter (v: (lib.generators.toINIWithGlobalSection {} { globalSection = v; })); template = file: newPath: replacements: replaceSecretsScript { inherit file replacements; diff --git a/modules/blocks/restic.nix b/modules/blocks/restic.nix index 783ef38..3654ae1 100644 --- a/modules/blocks/restic.nix +++ b/modules/blocks/restic.nix @@ -314,7 +314,7 @@ in script = shblib.genConfigOutOfBandSystemd { config = instance.settings.repository.secrets; configLocation = "/run/secrets_restic/${serviceName}"; - generator = name: v: pkgs.writeText "template" (generators.toINIWithGlobalSection {} { globalSection = v; }); + generator = shblib.toEnvVar; user = instance.request.user; }; in @@ -340,7 +340,7 @@ in RESTIC_REPOSITORY = instance.settings.repository.path; }; resultPath = "/run/secrets_restic_env/${fullName name instance.settings.repository}"; - generator = name: v: pkgs.writeText (fullName name instance.settings.repository) (generators.toINIWithGlobalSection {} { globalSection = v; }); + generator = shblib.toEnvVar; user = instance.request.user; }); }; diff --git a/modules/services/vaultwarden.nix b/modules/services/vaultwarden.nix index 83cf52a..aae1ee7 100644 --- a/modules/services/vaultwarden.nix +++ b/modules/services/vaultwarden.nix @@ -195,7 +195,7 @@ in SMTP_PASSWORD.source = cfg.smtp.password.result.path; }; resultPath = "${dataFolder}/vaultwarden.env"; - generator = name: v: pkgs.writeText "template" (lib.generators.toINIWithGlobalSection {} { globalSection = v; }); + generator = shblib.toEnvVar; }; shb.nginx.vhosts = [