{pkgs, ...}: { services.secrets = { enable = true; vaultLogin = { enable = true; loginUsername = "hetzner-arm-container-storage"; }; autoSecrets = { enable = true; }; requiredVaultPaths = [ "api-keys/data/hetzner/storagebox" "api-keys/data/putio" "api-keys/data/backblaze/Chaos-Backups" "api-keys/data/backblaze/Chaos-Photos" "api-keys/data/backblaze/Chaos-Music" "api-keys/data/backblaze/Chaos-Personal" "api-keys/data/backblaze/Chaos-Public" "api-keys/data/backblaze/Chaos-Media" "api-keys/data/backblaze/Phoenix-Cryptidz-Storage" "api-keys/data/storage/restic/Music" "api-keys/data/storage/restic/Vault" "api-keys/data/storage/restic/Social" "api-keys/data/storage/restic/Quassel" "api-keys/data/storage/restic/Piped" "api-keys/data/storage/restic/Mail" "api-keys/data/storage/webdav/main" "api-keys/data/storage/webdav/media" "private-public-keys/data/rclone/Chaos-Media-Crypt" ]; packages = with pkgs; [ # for music & mail passwd files apacheHttpd # for rclone obscure config file rclone ]; extraFunctions = '' replace_slash_for_sed() { sed "s#/#\\\/#" } simple_get_obscure() { rclone obscure "$(simple_get "$@")" } simple_get_replace_b2() { api_account=$(simple_get "$1" .keyID | replace_slash_for_sed) api_key=$(simple_get "$1" .applicationKey | replace_slash_for_sed) replace_account=''${2}_ACCOUNT replace_key=''${2}_KEY sed -i "s/$replace_account/$api_account/" "$3" sed -i "s/$replace_key/$api_key/" "$3" } simple_get_replace_crypt() { password=$(simple_get_obscure "$1" .password) salt=$(simple_get_obscure "$1" .salt) replace_password=''${2}_PASSWORD replace_salt=''${2}_SALT sed -i "s/$replace_password/$password/" "$3" sed -i "s/$replace_salt/$salt/" "$3" } ''; secrets = { vault_password = {manual = true;}; restic_music_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/restic/Music" .username) password=$(simple_get "/api-keys/storage/restic/Music" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; restic_vault_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/restic/Vault" .username) password=$(simple_get "/api-keys/storage/restic/Vault" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; restic_social_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/restic/Social" .username) password=$(simple_get "/api-keys/storage/restic/Social" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; restic_quassel_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/restic/Quassel" .username) password=$(simple_get "/api-keys/storage/restic/Quassel" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; restic_piped_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/restic/Piped" .username) password=$(simple_get "/api-keys/storage/restic/Piped" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; restic_mail_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/restic/Mail" .username) password=$(simple_get "/api-keys/storage/restic/Mail" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; webdav_main_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/webdav/main" .username) password=$(simple_get "/api-keys/storage/webdav/main" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; webdav_media_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/webdav/media" .username) password=$(simple_get "/api-keys/storage/webdav/media" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; rclone_config = { user = "storage"; group = "storage"; fetchScript = '' TMP_DIR="$(mktemp -d)" cp ${./rclone_config.template} "$TMP_DIR/template" pushd "$TMP_DIR" >/dev/null STORAGEBOX_PASSWORD=$(simple_get_obscure /api-keys/hetzner/storagebox .password) sed -i "s/STORAGEBOX_PASSWORD/$STORAGEBOX_PASSWORD/" ./template simple_get_replace_b2 "/api-keys/backblaze/Chaos-Backups" "B2_CHAOS_BACKUPS" ./template simple_get_replace_b2 "/api-keys/backblaze/Chaos-Photos" "B2_CHAOS_PHOTOS" ./template simple_get_replace_b2 "/api-keys/backblaze/Chaos-Music" "B2_CHAOS_MUSIC" ./template simple_get_replace_b2 "/api-keys/backblaze/Chaos-Personal" "B2_CHAOS_PERSONAL" ./template simple_get_replace_b2 "/api-keys/backblaze/Chaos-Public" "B2_CHAOS_PUBLIC" ./template simple_get_replace_b2 "/api-keys/backblaze/Chaos-Media" "B2_CHAOS_MEDIA" ./template simple_get_replace_b2 "/api-keys/backblaze/Phoenix-Cryptidz-Storage" "B2_PHOENIX_CRYPTIDZ_STORAGE" ./template PUTIO_PASSWORD="token/$(simple_get /api-keys/putio .oauth_token)" PUTIO_PASSWORD="$(rclone obscure "$PUTIO_PASSWORD")" sed -i "s/PUTIO_PASSWORD/$PUTIO_PASSWORD/" ./template simple_get_replace_crypt "/private-public-keys/rclone/Chaos-Media-Crypt" "STORAGE_MEDIA_CRYPT" ./template cp ./template "$secretFile" popd >/dev/null rm -rf "$TMP_DIR" ''; }; }; }; }