blog-static-flake/lib.nix
Danila Fedorin 0962df69ad Factor out building Agda HTML from building the blog
This saves a lot of time since typechecking Agda is slow.

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-24 20:33:34 +00:00

81 lines
2.4 KiB
Nix

{ pkgs, blog-source, web-files, resume }:
with pkgs;
with lib;
let
protocol = ssl: if ssl then "https://" else "http://";
gems = settings: bundlerEnv {
inherit ruby;
name = "blog-static-flake";
gemfile = "${settings.src}/Gemfile";
lockfile = "${settings.src}/Gemfile.lock";
gemset = ./gemset.nix;
};
# --- Building Agda HTML ---
agdaEnv = agda.withPackages [ agdaPackages.standard-library ];
agdaHtml = settings:
let
# Create content-addresed versions of the scripts in the Nix store to
# avoid throwing off memoization for unrelated changes.
agdaBuildScript = builtins.toFile "build-agda-html.rb" (builtins.readFile "${settings.src}/build-agda-html.rb");
submoduleDataFile = builtins.toFile "submodules.json" (builtins.readFile "${settings.src}/data/submodules.json");
codeRoot = pkgs.lib.cleanSource "${settings.src}/code";
agdaCommand = pkgs.lib.escapeShellArg "agda -l standard-library -i . ";
in
stdenv.mkDerivation {
name = "blog-static-agda-html";
version = settings.src.rev or "dirty";
buildInputs = [ ruby agdaEnv ];
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
mkdir -p code $out
cp -r ${codeRoot}/* code/
chmod -R u+w code
ruby ${agdaBuildScript} --data-file=${submoduleDataFile} --target-dir=$out ${agdaCommand}
";
};
website = settings: stdenv.mkDerivation {
inherit (settings) src ssl host;
inherit resume ruby;
name = "blog-static";
version = settings.src.rev or "dirty";
publicPath = settings.path;
hugoFlags = concatStringsSep " " (
optionals settings.drafts (singleton "-D") ++
[ "--baseURL=${protocol settings.ssl + settings.host}" ]
);
builder = ./build/builder.sh;
webFiles = web-files;
gems = gems settings;
agdaHtml = agdaHtml settings;
buildInputs = [
hugo ruby stork agdaEnv
];
};
in
{
english = settings: website {
inherit (settings) host;
ssl = settings.ssl or false;
drafts = settings.drafts or false;
src = blog-source;
path = ".";
};
virtualHostFor = package:
{
"${package.host}" = mkMerge [
{
root = package;
}
(mkIf (package.ssl) {
forceSSL = true;
enableACME = true;
})
];
};
}