48 lines
1.3 KiB
Nix
48 lines
1.3 KiB
Nix
{ pkgs, ... }:
|
|
|
|
let
|
|
bibleApiPackage = pkgs.stdenv.mkDerivation {
|
|
pname = "bible-api";
|
|
version = "2025-07-18";
|
|
|
|
src = pkgs.fetchzip {
|
|
url = "https://bible.helloao.org/api.zip";
|
|
hash = "sha256-bYl8svY++D0+YHXZ8/3h+yn0xiqIDCXcN+Hh9FjP98k=";
|
|
stripRoot = false;
|
|
};
|
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/api
|
|
mv * $out/api/
|
|
'';
|
|
};
|
|
in {
|
|
services.caddy.enable = true;
|
|
|
|
services.caddy.virtualHosts."bible.chandlerswift.com" = {
|
|
extraConfig = ''
|
|
encode zstd gzip
|
|
file_server
|
|
root * ${bibleApiPackage}
|
|
|
|
handle / {
|
|
header Content-Type text/html
|
|
# This is a bit of a hack, but I was unable to find a better way to just
|
|
# serve the contents of the file. If I knew the directory of the file
|
|
# and its filename, I think I could use file_server with try_files, but
|
|
# if I do a `file_server` with `.\${./bible.chandlerswift.com.html}`, then
|
|
# bible.chandlerswift.com.html just gets copied as a file into nix-store
|
|
# and I don't know its name. ...or something? Anyway this seems to work!
|
|
respond <<EOF
|
|
${builtins.readFile ./bible.chandlerswift.com.html}
|
|
EOF
|
|
}
|
|
|
|
handle_errors {
|
|
respond "{err.status_code} {err.status_text}"
|
|
}
|
|
'';
|
|
};
|
|
}
|