diff --git a/.gitignore b/.gitignore index 85ecc7c..0cca3b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,6 @@ # Nix. /.direnv/ - -# rst2df. -/**/*.pdf -/**/*.rst.build_temp -/dist/* -!/dist/.keep +/result # pdfpc. /**/*.pdfpc diff --git a/dist/.keep b/dist/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/flake.lock b/flake.lock index 37be8ba..c621a52 100644 --- a/flake.lock +++ b/flake.lock @@ -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" } diff --git a/flake.nix b/flake.nix index 695a484..230a14c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,25 +1,98 @@ { - 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 ( + { name, src }: + mkDerivation { + inherit name shared src; + + 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 { + name = "build-configs"; + src = ./src/building-build-configs; + }; + + sculpin = mkTalk { + name = "building-static-websites-sculpin"; + src = ./src/building-static-websites-sculpin; + }; + + tailwind-css = mkTalk { + name = "taking-flight-with-tailwind-css"; + src = ./src/taking-flight-with-tailwind-css; + }; + + test-driven-drupal = mkTalk { + name = "test-driven-drupal"; + 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; }; } diff --git a/justfile b/justfile new file mode 100644 index 0000000..428df9b --- /dev/null +++ b/justfile @@ -0,0 +1,19 @@ +alias b := build + +_default: + just --list + +build: + #!/usr/bin/env bash + selected=$(nix flake show --json | jq --raw-output '.packages["x86_64-linux"] | keys[]' | grep -v shared | fzf) + + nix build \ + --json \ + --print-build-logs \ + .#"$selected" + +check: + nix flake check + +clean: + rm -frv result diff --git a/run b/run deleted file mode 100755 index 442a666..0000000 --- a/run +++ /dev/null @@ -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]} " - 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]} " - 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 [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]} " - 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}"