Build slides with Nix

This commit is contained in:
Oliver Davies 2025-04-11 18:13:44 +01:00
parent e80aee1deb
commit 50662bffcc
10 changed files with 175 additions and 153 deletions

7
.gitignore vendored
View file

@ -1,11 +1,6 @@
# Nix.
/.direnv/
# rst2df.
/**/*.pdf
/**/*.rst.build_temp
/dist/*
!/dist/.keep
/result
# pdfpc.
/**/*.pdfpc

0
dist/.keep vendored
View file

8
flake.lock generated
View file

@ -2,16 +2,16 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1725001927,
"narHash": "sha256-eV+63gK0Mp7ygCR0Oy4yIYSNcum2VQwnZamHxYTNi+M=",
"lastModified": 1741010256,
"narHash": "sha256-WZNlK/KX7Sni0RyqLSqLPbK8k08Kq7H7RijPJbq9KHM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6e99f2a27d600612004fbd2c3282d614bfee6421",
"rev": "ba487dbc9d04e0634c64e3b1f0d25839a0a68246",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}

View file

@ -1,25 +1,96 @@
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs =
{ nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) mkShell nixfmt-classic;
in
{
devShells.${system}.default = mkShell {
packages = with pkgs; [
ghostscript
pdfpc
python310Packages.rst2pdf
texliveMedium # includes pdfjam
tree
];
inherit (nixpkgs.lib) makeOverridable;
inherit (pkgs.stdenvNoCC) mkDerivation;
shared = mkDerivation {
name = "talks-shared";
src = ./src;
installPhase = ''
runHook preInstall
mkdir $out
cp -r fonts styles $out
runHook postInstall
'';
};
formatter.${system} = nixfmt-classic;
commonBuildInputs = with pkgs; [
(python310.withPackages (p: with p; [ rst2pdf ]))
];
mkTalk = makeOverridable (
{ src }:
mkDerivation {
inherit shared src;
name = builtins.head (builtins.attrNames talks);
buildInputs = commonBuildInputs;
buildPhase = ''
runHook preBuild
mkdir $out
rst2pdf slides.rst \
--break-level 1 \
--fit-background-mode scale \
--font-path "${toString shared}/fonts" \
--output "$out/slides.pdf" \
--stylesheets bw,"${toString shared}/styles/opdavies-light"
runHook postBuild
'';
}
);
talks = {
build-configs = mkTalk {
src = ./src/building-build-configs;
};
sculpin = mkTalk {
src = ./src/building-static-websites-sculpin;
};
tailwind-css = mkTalk {
src = ./src/taking-flight-with-tailwind-css;
};
test-driven-drupal = mkTalk {
src = ./src/test-driven-drupal;
};
};
in
{
devShells.${system}.default =
with pkgs;
mkShell {
packages =
with pkgs;
commonBuildInputs
++ [
ghostscript
just
pdfpc
texliveMedium # includes pdfjam
];
};
packages.${system} = {
inherit shared;
} // talks;
formatter.${system} = pkgs.nixfmt-rfc-style;
};
}

19
justfile Normal file
View file

@ -0,0 +1,19 @@
alias b := build
_default:
just --list
check:
nix flake check
clean:
rm -frv result
build:
#!/usr/bin/env bash
talk=$(nix flake show --json | jq --raw-output '.packages["x86_64-linux"] | keys[]' | grep -v shared | fzf)
nix build \
--json \
--print-build-logs \
.#"$talk"

107
run
View file

@ -1,107 +0,0 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
PDF_FILENAME=slides.pdf
RST_FILENAME="${RST_FILENAME:-slides.rst}"
THUMBNAIL_FILENAME=thumbnail.jpg
function clean {
rm -fr dist/*
touch dist/.keep
find . \
-type f \( -name "${PDF_FILENAME}*" -o -name *.build_temp -o -name ${THUMBNAIL_FILENAME} \) \
-delete
}
function generate {
generate:pdf "${@}"
}
function generate:pdf {
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
DIRECTORY_NAME=$1
shift 1
pushd "src/${DIRECTORY_NAME}"
rst2pdf "${RST_FILENAME}" \
--break-level 1 \
-e preprocess \
--fit-background-mode scale \
--font-path ../fonts \
--output "../../dist/${DIRECTORY_NAME}.pdf" \
--stylesheets ../styles/opdavies-light,tango \
"${@}"
popd
tree dist
}
# Generate JPG thumbnails of each slide in a presentation.
function generate:thumbnail {
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
if [ ! -d "src/${1}" ]; then
echo "${1} not found"
exit 2
fi
generate:pdf "${1}"
mkdir -p "dist/${1}"
gs \
-dBATCH \
-dDownScaleFactor=3 \
-dNOPAUSE \
-r600 \
-sDEVICE=jpeg \
-sOutputFile="dist/${1}/%d.jpg" \
"dist/${1}.pdf"
}
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# Create a new talk.
function new {
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
if [[ -e "src/${1}" ]]; then
echo "Error: ${1} already exists."
exit 1
fi
mkdir -vp "src/${1}"
touch "src/${1}/slides.rst"
}
function present {
TALK_PATH=$1
shift 1
pdfpc "${@}" "dist/${TALK_PATH}.pdf"
}
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"

View file

@ -1,7 +1,9 @@
..
This file used a mixture of `plain` and `php` languages for code blocks so that `hl_lines` display correctly.
.. page:: titlePage
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
@ -12,7 +14,9 @@ Building a blog module
TextAnnotation "Shortened and simplified example."
TextAnnotation "I'd use Views for this in a real situation."
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
Acceptance criteria
===================

View file

@ -1,4 +1,6 @@
.. page:: titlePage
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle

View file

@ -1,15 +1,21 @@
.. page:: titlePage
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
Example
.. page:: imagePage
.. raw:: pdf
PageBreak imagePage
.. image:: images/broadbean-website.png
:width: 20cm
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
Specification
=============
@ -27,7 +33,9 @@ Specification
TextAnnotation "Job applicants would visit the job on the Drupal site, click the application URL and go to another (CRM) system to apply."
TextAnnotation "Client wanted to be able to specify the Drupal path in advance."
.. page:: imagePage
.. raw:: pdf
PageBreak imagePage
|
|
@ -35,7 +43,9 @@ Specification
.. image:: images/broadbean-drupal-flow-2.png
:width: 20cm
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
Implementation
==============

View file

@ -15,7 +15,9 @@ Oliver Davies (@opdavies)
https://opdavi.es/drupal-london
.. page:: titlePage
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
@ -27,7 +29,9 @@ Software Developer, Consultant, open-source maintainer
TextAnnotation "I contribute to and maintain open-source projects including Drupal core."
TextAnnotation "Different perspectives."
.. page:: imagePage
.. raw:: pdf
PageBreak imagePage
.. image:: images/timmillwood-ono.png
:width: 22cm
@ -36,7 +40,9 @@ Software Developer, Consultant, open-source maintainer
TextAnnotation "I saw this tweet by Tim Millwood and become the maintainer in 2012."
.. page:: imagePage
.. raw:: pdf
PageBreak imagePage
.. image:: images/override-node-options-1.png
:width: 18cm
@ -70,7 +76,9 @@ Software Developer, Consultant, open-source maintainer
PageBreak
TextAnnotation "Had some existing tests, crucial to preventing regressions"
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
Why write tests?
================
@ -117,7 +125,9 @@ Writing PHPUnit Tests for Drupal
TextAnnotation "PSR-4 autoloading."
TextAnnotation "Different to D7."
.. page:: titlePage
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
@ -143,7 +153,9 @@ Given, When, Then
TextAnnotation "When I go to that page..."
TextAnnotation "I should see 'About me' on the page."
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
What to test?
=============
@ -160,14 +172,18 @@ What to test?
TextAnnotation "Examples of some things that I tested on previous projects."
.. page:: imagePage
.. raw:: pdf
PageBreak imagePage
|
.. image:: images/matt-stauffer-tweet.png
:width: 20cm
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
What does a test look like?
===========================
@ -296,13 +312,17 @@ Unit Tests
* Can become tightly coupled
* Can be hard to refactor
.. page:: titlePage
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
Running Tests
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
Core script
===========
@ -416,13 +436,17 @@ Test Driven Development
TextAnnotation "Refactor if needed."
TextAnnotation "Repeat."
.. page:: titlePage
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
Red, Green, Refactor
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
Porting Modules From Drupal 7
=============================
@ -465,12 +489,16 @@ Run in 2-3 minutes in a CI pipeline with GitHub Actions.
.. .. include:: demo.rst
.. include:: demo2.rst
.. page:: imagePage
.. raw:: pdf
PageBreak imagePage
.. image:: images/tawny-tweet-2.png
:width: 18cm
.. page:: standardPage
.. raw:: pdf
PageBreak standardPage
Thanks!
=======