Converting .aax files to .flac with Nix

Here is a script from my nix-config repository that allows me to download .aax files from my Audible library and convert them to .flac files:

(pkgs.writeShellApplication {
name = "convert-audiobook";

runtimeInputs = with pkgs; [
aaxtomp3
audible-cli
];

text = ''
if [[ $# -eq 0 ]]; then
echo "Usage: $(basename "$0") <file>"

exit 1
fi

file="''$1"

aaxtomp3 \
--authcode "$(audible activation-bytes)" \
--flac \
--single \
"$file"
'';
})

Once converted, I can upload and listen to the .flac file within my installation of Audiobookshelf.