/ flake.nix
flake.nix
  1  {
  2    description = "";
  3  
  4    inputs = {
  5      nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  6      systems.url = "github:nix-systems/default";
  7      pre-commit-hooks.url = "github:cachix/git-hooks.nix";
  8    };
  9  
 10    outputs =
 11      {
 12        self,
 13        nixpkgs,
 14        systems,
 15        ...
 16      }@inputs:
 17      let
 18        forAllSystems =
 19          function: nixpkgs.lib.genAttrs (import systems) (system: function nixpkgs.legacyPackages.${system});
 20      in
 21      {
 22        packages = forAllSystems (
 23          pkgs:
 24          let
 25            name = "bornhack_2025_mailservers";
 26            typst-packages = pkgs.typst.withPackages (
 27              p: with p; [
 28                polylux_0_4_0
 29              ]
 30            );
 31            fontsConf = pkgs.symlinkJoin {
 32              name = "typst-fonts";
 33              paths = [
 34                pkgs.iosevka
 35                pkgs.lexend
 36              ];
 37            };
 38          in
 39          {
 40            default = self.packages.${pkgs.system}.presentation;
 41            presentation = pkgs.stdenvNoCC.mkDerivation rec {
 42              inherit name;
 43              src = ./src;
 44              XDG_CACHE_HOME = "${typst-packages}/lib";
 45              buildInputs = with pkgs; [
 46                typst
 47              ];
 48              buildPhase = ''
 49                runHook preBuild
 50  
 51                # compile main.typ
 52                ${pkgs.lib.getExe pkgs.typst} compile --root ./. --font-path ${fontsConf} ./main.typ ${name}.pdf
 53  
 54                # generate pdfpc file from main.typ
 55                ${pkgs.lib.getExe pkgs.polylux2pdfpc} --root ./. ./main.typ && mv ./main.pdfpc ${name}.pdfpc
 56  
 57                runHook postBuild
 58              '';
 59              installPhase = ''
 60                runHook preInstall
 61                install -m640 -D ${name}.pdf -t $out
 62                install -m640 -D ${name}.pdfpc -t $out
 63                runHook postInstall
 64              '';
 65            };
 66            watch-presentation = pkgs.writeShellApplication rec {
 67              inherit name;
 68              runtimeInputs = with pkgs; [
 69                typst
 70                polylux2pdfpc
 71              ];
 72              text = ''
 73                export XDG_CACHE_HOME="${typst-packages}/lib"
 74                ${pkgs.lib.getExe pkgs.typst} watch --root ./. --font-path ${fontsConf} ./src/main.typ ${name}.pdf
 75                ${pkgs.lib.getExe pkgs.polylux2pdfpc} --root ./. ./src/main.typ && mv ./src/main.pdfpc ${name}.pdfpc
 76                ${pkgs.inotify-tools}/bin/inotifywait --exclude '\.pdf|\.git' -qre close_write .; \
 77              '';
 78            };
 79          }
 80        );
 81        devShells = forAllSystems (pkgs: {
 82          default = pkgs.mkShell {
 83            inherit (self.checks.${pkgs.system}.pre-commit-check) shellHook;
 84            buildInputs = self.checks.${pkgs.system}.pre-commit-check.enabledPackages;
 85            packages = with pkgs; [
 86              typst
 87              typstyle
 88              pdfpc
 89              zathura
 90            ];
 91          };
 92        });
 93        checks = forAllSystems (pkgs: {
 94          pre-commit-check = inputs.pre-commit-hooks.lib.${pkgs.system}.run {
 95            src = ./.;
 96            hooks = {
 97              nixfmt-rfc-style.enable = true;
 98            };
 99          };
100        });
101      };
102  }