{ buildToolbox
, checkedShellScript
}:
# Utility script for pinning the latest stable version of Nixpkgs.

# Instead of running `nix flake update` manually, we run this script
# to also pin readthedocs dependencies at the same time.
let
  upgrade =
    checkedShellScript
      {
        name = "postgrest-nixpkgs-upgrade";
        docs = "Pin the newest version of Nixpkgs.";
        workingDir = "/";
      }
      ''
        nix flake update

        echo "# This file is auto-generated by postgrest-nixpkgs-upgrade" > docs/requirements.txt
        cat "$(nix-build -A docs.requirements)" >> docs/requirements.txt
      '';

in
buildToolbox
{
  name = "postgrest-nixpkgs";
  tools = { inherit upgrade; };
}
