docs/ci: use nix build --argstr to safely supply input

Rather than interpolating input (flakeref & baseHref) into the build
expression, take advantage of `--argstr`.

See "Common evaluation options" in `nix build --help` for more detail.
This commit is contained in:
Matt Sturgeon 2024-11-20 17:30:41 +00:00
parent ed30fd8588
commit 9416bc9018
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -53,15 +53,30 @@ jobs:
# 1: branch
# 2: install dir (relative to /nixvim/)
build() {
flake="github:${repo}${1:+/$1}"
branch="$1"
dir="${2:+/$2}"
flakeref="github:${repo}${branch:+/$branch}"
baseHref="/${repoName}${dir}/"
installDir="${out}${dir}"
# Build docs for the given flake ref, overriding baseHref in the derivation args
nix build --impure --expr '(builtins.getFlake "'"$flake"'").outputs.packages.${builtins.currentSystem}.docs.override {
baseHref = "'"$baseHref"'";
}'
nix build --impure \
--argstr flakeref "$flakeref" \
--argstr baseHref "$baseHref" \
--expr '
{
flakeref,
baseHref,
system ? builtins.currentSystem,
}:
let
flake = builtins.getFlake flakeref;
packages = flake.outputs.packages.${system};
in
packages.docs.override {
inherit baseHref;
}
'
# Copy the result to the install dir
mkdir -p "$installDir"