{ "uuid": [ { "value": "f3e69f27-6b57-434e-a50a-308e99838872" } ], "langcode": [ { "value": "en" } ], "type": [ { "target_id": "daily_email", "target_type": "node_type", "target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7" } ], "revision_timestamp": [ { "value": "2025-05-11T08:59:58+00:00" } ], "revision_uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "revision_log": [], "status": [ { "value": true } ], "uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "title": [ { "value": "Generating presentation slides with Nix and rst2pdf" } ], "created": [ { "value": "2025-04-07T00:00:00+00:00" } ], "changed": [ { "value": "2025-05-11T08:59:58+00:00" } ], "promote": [ { "value": false } ], "sticky": [ { "value": false } ], "default_langcode": [ { "value": true } ], "revision_translation_affected": [ { "value": true } ], "path": [ { "alias": "\/daily\/2025\/04\/07\/nix-rst2pdf", "langcode": "en" } ], "body": [ { "value": "\n

Since switching to Nix and NixOS, I've been looking for opportunities to use Nix more in addition to managing my laptop and server configurations and creating development shells for projects.<\/p>\n\n

Nix is a build tool, so I've started to use it to build my slide decks which I create using rst2pdf.<\/p>\n\n

I write the rst (reStructuredText) file and compile it to a PDF file.<\/p>\n\n

I had a flake.nix file to add rst2pdf, pdfpc and other tools to my shell, but the compilation to a PDF file was done in a bash script which I've since removed.<\/p>\n\n

Here's how my flake.nix file looks now:<\/p>\n\n

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

Each talk is its own derivation, so I can run nix run .#test-driven-drupal<\/code> and it will generate the appropriate PDF file for me to present or share.<\/p>\n\n

The source code is available at https:\/\/code.oliverdavies.uk\/opdavies\/talks<\/a> if you want to see how I use rst2pdf to create my presentations and I've even given a presentation about how I create presentations<\/a>.<\/p>\n\n ", "format": "full_html", "processed": "\n

Since switching to Nix and NixOS, I've been looking for opportunities to use Nix more in addition to managing my laptop and server configurations and creating development shells for projects.<\/p>\n\n

Nix is a build tool, so I've started to use it to build my slide decks which I create using rst2pdf.<\/p>\n\n

I write the rst (reStructuredText) file and compile it to a PDF file.<\/p>\n\n

I had a flake.nix file to add rst2pdf, pdfpc and other tools to my shell, but the compilation to a PDF file was done in a bash script which I've since removed.<\/p>\n\n

Here's how my flake.nix file looks now:<\/p>\n\n

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

Each talk is its own derivation, so I can run nix run .#test-driven-drupal<\/code> and it will generate the appropriate PDF file for me to present or share.<\/p>\n\n

The source code is available at https:\/\/code.oliverdavies.uk\/opdavies\/talks<\/a> if you want to see how I use rst2pdf to create my presentations and I've even given a presentation about how I create presentations<\/a>.<\/p>\n\n ", "summary": null } ] }