blog-static-flake/lib.nix

81 lines
2.4 KiB
Nix
Raw Normal View History

{ pkgs, blog-source, web-files, resume }:
2021-10-21 23:00:13 -07:00
with pkgs;
with lib;
2020-04-06 16:51:17 -07:00
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}
";
};
2020-09-02 17:25:52 -07:00
website = settings: stdenv.mkDerivation {
2021-10-23 00:51:13 -07:00
inherit (settings) src ssl host;
inherit resume ruby;
2020-09-02 17:25:52 -07:00
name = "blog-static";
version = settings.src.rev or "dirty";
2020-09-02 17:25:52 -07:00
publicPath = settings.path;
hugoFlags = concatStringsSep " " (
2023-04-10 19:54:30 -07:00
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
];
2020-09-02 17:25:52 -07:00
};
2020-09-02 17:03:02 -07:00
in
2021-10-23 00:33:22 -07:00
{
english = settings: website {
2021-10-23 00:51:13 -07:00
inherit (settings) host;
ssl = settings.ssl or false;
2021-10-23 00:33:22 -07:00
drafts = settings.drafts or false;
2021-10-23 00:51:13 -07:00
src = blog-source;
2020-09-02 17:25:52 -07:00
path = ".";
};
virtualHostFor = package:
{
"${package.host}" = mkMerge [
{
root = package;
}
(mkIf (package.ssl) {
forceSSL = true;
enableACME = true;
})
];
};
2021-10-23 00:33:22 -07:00
}