Need to request password from the user during system boot for encryption

Hello everyone,

I am trying to enable LUKS encryption for my disk partition where I need to ask password from user then proceed with formatting partition with LUKS using cryptsetup

I have tried with following configuration.

let
  postBootCmds = ''
    set -x
    echo "Hello"
    USER_PSWD=$(${pkgs.systemd}/bin/systemd-ask-password --timeout=30 -n "Please enter encryption password:")
    echo "$USER_PSWD"
    echo -n "$USER_PSWD" ${pkgs.cryptsetup}/bin/cryptsetup luksFormat --type luks2 /dev/sda5
    .........
   '';
in
{
  boot.postBootCommands = postBootCmds;
}

Expectation:
During boot system prompt/stop and ask for the password from user.

Actual:
There will be no prompt for password, activation script will timeout and proceed with boot.

Logs:

nixos systemd[1]: Starting NixOS Activation...
nixos initrd-nixos-activation-start[295]: booting system configuration /nix/store/msi8qdv9b6v82k2ahirqss8fib6wmywp-nixos-system-nixos-25.05.20250201.3a22805
nixos initrd-nixos-activation-start[351]: ++ systemd-ask-password  --timeout=30  -n 'Please enter disk encryption password:'
nixos systemd-ask-password[351]: Failed to query password: Timer expired
nixos systemd[1]: initrd-nixos-activation.service: Deactivated successfully.
nixos systemd[1]: Finished NixOS Activation.

Any help is appericated.