{ pkgs, ... }:
let
  getLatestN = pkgs.writeShellApplication {
    name = "misskey-getLatestN";
    runtimeInputs = with pkgs; [
      curl
      jq
    ];
    text = ''
      if [ ! -e /tmp//misskey-scripts/getLatestN1.fifo ]; then
          mkdir -p /tmp/misskey-scripts
          mkfifo /tmp/misskey-scripts/getLatestN1.fifo
      fi
      if [ ! -e /tmp//misskey-scripts/getLatestN2.fifo ]; then
          mkdir -p /tmp/misskey-scripts
          mkfifo /tmp/misskey-scripts/getLatestN2.fifo
      fi

      pipeLocation1=/tmp/misskey-scripts/getLatestN1.fifo
      pipeLocation2=/tmp/misskey-scripts/getLatestN2.fifo

      curl https://misskey.io/api/notes -s --request POST --header 'Content-Type: application/json' --data "{\"local\": true, \"reply\": false, \"renote\": false, \"withFiles\": false, \"poll\": false, \"limit\": $1}" > "$pipeLocation1" &

      jq -M -r '.[].text' < $pipeLocation1 > $pipeLocation2 &

      while read -r line; do
          echo "$line"
      done < $pipeLocation2
      wait
    '';
  };
  
in
pkgs.symlinkJoin {
  name = "misskey-scripts";
  paths = [ getLatestN ];
}
