{pkgs, ...}: { services.secrets = { enable = true; extraPackages = 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 "$1" .password | replace_slash_for_sed) salt=$(simple_get "$1" .salt | replace_slash_for_sed) replace_password=''${2}_ACCOUNT replace_salt=''${2}_KEY sed -i "s/$replace_password/$password/" "$3" sed -i "s/$replace_salt/$salt/" "$3" } ''; secrets = { vault_password = {manual = true;}; restic_hetznervm_htpasswd = { user = "storage"; group = "storage"; fetchScript = '' username=$(simple_get "/api-keys/storage/restic/HetznerVM" .username) password=$(simple_get "/api-keys/storage/restic/HetznerVM" .password) htpasswd -bc "$secretFile" "$username" "$password" 2>/dev/null ''; }; 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 ''; }; 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>&1 ''; }; 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>&1 ''; }; rclone_config = { user = "storage"; group = "storage"; fetchScript = '' TMP_DIR="$(mktemp -d)" cp ${./rclone_config.template} "$TMP_DIR/template" pushd "$TMP_DIR" 2>/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/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 2>/dev/null rm -rf "$TMP_DIR" ''; }; wg_privkey = { fetchScript = '' simple_get "/private-public-keys/wireguard/chaos-internal/storage" .private > $secretFile ''; }; wg_preshared_hetzner-vm = { path = "/secrets/wg_preshared_hetzner-vm"; fetchScript = '' simple_get "/private-public-keys/wireguard/chaos-internal/storage" .preshared_keys.hetzner_vm > $secretFile ''; }; wg_preshared_tablet = { path = "/secrets/wg_preshared_tablet"; fetchScript = '' simple_get "/private-public-keys/wireguard/chaos-internal/storage" .preshared_keys.tablet > $secretFile ''; }; wg_preshared_vault = { path = "/secrets/wg_preshared_vault"; fetchScript = '' simple_get "/private-public-keys/wireguard/chaos-internal/storage" .preshared_keys.vault > $secretFile ''; }; wg_preshared_iphone8 = { path = "/secrets/wg_preshared_iphone8"; fetchScript = '' simple_get "/private-public-keys/wireguard/chaos-internal/storage" .preshared_keys.iphone8 > $secretFile ''; }; }; }; }