blog-static-flake/lib.nix
Danila Fedorin 7d6f362936 Avoid using rev in Agda derivation
This might make the derivation more cacheable

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-25 06:06:10 +00:00

80 lines
2.3 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";
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;
})
];
};
}