aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: b221973b3323fee1cc989244b2996b01e66246e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Taken from https://flyx.org/nix-flakes-latex/
{
  description = "LaTeX Document Demo";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    nixvim.url = "github:nix-community/nixvim";
  };
  outputs = {
    self,
    nixpkgs,
    nixvim,
    flake-utils,
  }:
    with flake-utils.lib;
      eachSystem allSystems (system: let
        pkgs = nixpkgs.legacyPackages.${system};
        tex = pkgs.texlive.combine {
          inherit (pkgs.texlive) scheme-basic cite pgf nicematrix latex-bin latexmk titlesec listings ieeetran;
        };
        nvim = nixvim.legacyPackages.x86_64-linux.makeNixvim {
          plugins.lsp.enable = true;
          colorschemes.gruvbox.enable = true;
        };
      in rec {
        packages = {
          document = pkgs.stdenvNoCC.mkDerivation rec {
            name = "latex-demo-document";
            src = self;
            buildInputs = [ pkgs.coreutils pkgs.texliveFull pkgs.pandoc pkgs.texliveFull pkgs.tetex pkgs.zathura pkgs.kile];
            phases = ["unpackPhase" "buildPhase" "installPhase"];
            buildPhase = ''
              runHook preBuild

              export PATH="${pkgs.lib.makeBinPath buildInputs}";
                pandoc sources.md -s -o sources.tex --pdf-engine=pdflatex
                mkdir -p .cache/texmf-var
                env TEXMFHOME=.cache TEXMFVAR=.cache/texmf-var \
                  latexmk -f -interaction=nonstopmode -pdf -pdflatex \
                  sources.tex
              runHook postBuild
            '';
            installPhase = ''
              runHook preInstall

              install -m644 -D *.pdf $out/sources.pdf

              runHook postInstall
            '';
          };
        };
        defaultPackage = packages.document;
      });
}