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

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

  gems = bundlerEnv {
    name = "${name}-gems";
    inherit ruby;
    gemfile = ./Gemfile;
    lockfile = ./Gemfile.lock;
    gemset = ./gemset.nix;
  };
in stdenvNoCC.mkDerivation {
  pname = name;
  inherit version;
  src = ./.;
  buildInputs = [ gems ruby ];
  nativeBuildInputs = [ (writeShellScriptBin "git" "true") ];

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

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

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