Add build script

This commit is contained in:
Smaug123
2023-09-29 23:23:01 +01:00
parent d8cf76c2f1
commit f2cb47916b
4 changed files with 163 additions and 0 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@
*.pdf
.DS_Store
/result

24
build.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
USER_DIR=$(readlink -f "$1")
WORKDIR=$(mktemp -d -p "$USER_DIR")
cd "$WORKDIR" || exit 1
# Build PDFs from LaTeX. Do the build twice to sort out any bookmarks.
find "$USER_DIR" -type f -name '*.tex' -print0 | while IFS= read -r -d '' file; do
echo ">>> $file"
ls -la "$file"
output=$(dirname "$file")/$(basename "$file" .tex).pdf
if [ -f "$output" ]; then
echo "Skipping $file as already built"
exit 0
fi
echo "$file - $output"
HOME=$(pwd) SOURCE_DATE_EPOCH=1622905527 pdflatex "$file" || exit 1
HOME=$(pwd) SOURCE_DATE_EPOCH=1622905527 pdflatex "$file" || exit 1
mv "$(basename "$output")" "$output" || exit 1
done
cd "$USER_DIR" || exit 1
rm -r "$WORKDIR"

61
flake.lock generated Normal file
View File

@@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1688392541,
"narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

77
flake.nix Normal file
View File

@@ -0,0 +1,77 @@
{
description = "PDFs hosted on patrickstevens.co.uk";
inputs = {
flake-utils.url = github:numtide/flake-utils;
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
};
outputs = {
self,
nixpkgs,
flake-utils,
}: let
commit = self.shortRev or "dirty";
date = self.lastModifiedDate or self.lastModified or "19700101";
version = "1.0.0+${builtins.substring 0 8 date}.${commit}";
in
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in let
texlive = pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-medium mdframed etoolbox zref needspace tikz-cd;
};
in let
createShellScript = name: contents:
pkgs.stdenv.mkDerivation {
__contentAddressed = true;
pname = name;
version = "0.1.0";
src = contents;
buildInputs = [
pkgs.shellcheck
];
phases = ["configurePhase" "buildPhase" "installPhase"];
configurePhase = ''
${pkgs.shellcheck}/bin/shellcheck "${contents}"
'';
buildPhase = ''
cp "${contents}" run.sh
patchShebangs run.sh
sed -i 's_"/bin/bash"_"${pkgs.bash}/bin/bash"_' run.sh
'';
installPhase = ''
mkdir -p $out
mv run.sh $out/run.sh
'';
};
in let
buildLatex = createShellScript "latex" ./build.sh;
in {
packages.default = pkgs.stdenv.mkDerivation {
__contentAddressed = true;
inherit version;
pname = "patrickstevens.co.uk-pdfs";
src = ./.;
buildInputs = [texlive buildLatex];
buildPhase = ''
${pkgs.bash}/bin/sh ${buildLatex}/run.sh .
'';
installPhase = ''
mkdir -p $out
cp ./*.pdf $out
cp ./*.tex $out
cp ./pdf-targets.txt $out
'';
};
devShells.default = pkgs.mkShell {
buildInputs = [pkgs.alejandra pkgs.shellcheck];
};
});
}