{ lib
, stdenvNoCC
, ruby
, bundler
, libffi
, gcc
, writeShellScriptBin
, fetchFromGitHub }: let
  name = "website";
  version = "20240114";

  assets = fetchFromGitHub {
    name = "${name}-assets";
    owner = "cotes2020";
    repo = "chirpy-static-assets";
    rev = "c577249";
    hash = "sha256-Uxe7PMNwzKUN2b77QbjWLxEtOOLodPOyeMuUM1eKdlc=";
  };

  vendor = stdenvNoCC.mkDerivation {
    pname = "${name}-vendor";
    inherit version;
    src = ./.;

    nativeBuildInputs = [ bundler ];

    buildPhase = ''
      export HOME="$(mktemp -d)"
      bundle config set --local path "$out"
      bundler package --no-install
    '';

    installPhase = ''
      cp Gemfile* $out
    '';

    outputHashAlgo = "sha256";
    outputHashMode = "recursive";
    outputHash = "sha256-ql0Rf1annFrlhaPF/s96xPTNsSjQbM44SCBmE53DaEY=";
  };

  deps = stdenvNoCC.mkDerivation {
    pname = "${name}-deps";
    inherit version;
    src = vendor;

    buildInputs = [ ruby libffi gcc ];

    nativeBuildInputs = [ bundler ];

    buildPhase = ''
      export HOME="$(mktemp -d)"
      bundle config set --local path "$out"
      mkdir -p "vendor"
      mv ruby/*/cache "vendor/"
      bundle install --local
    '';
  };
in stdenvNoCC.mkDerivation {
  pname = name;
  inherit version;
  src = ./.;

  buildInputs = [ ruby libffi gcc ];

  nativeBuildInputs = [ (writeShellScriptBin "git" "true") bundler ];

  configurePhase = ''
    export HOME="$(mktemp -d)"
    bundle config set --local path "${deps}"

    cp -r ${assets}/. assets/lib/
  '';

  buildPhase = "JEKYLL_ENV=production bundle exec jekyll build";

  installPhase = ''
    cp -r _site "$out"
  '';
}
