summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 09f76101f6af1e98ccb7b713dbadbfc21f964ea8 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
  description = "Latex Project Report Template";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
  };

  outputs = { self, nixpkgs, ... }:
    let
      supportedSystems = [ "x86_64-linux" "x86_64-darwin" ];
      forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
      pname = "report";
      version = "0.1.0";

      nixpkgsFor = forAllSystems (system:
        import nixpkgs {
          inherit system;
          overlays = [ self.overlay ];
        }
      );

    in
    rec {

      overlay = final: prev: {

        watcher = with final; pkgs.writeScriptBin "watch" ''
          out=".latexmkout"
          mkdir "$out"
          latexmk \
            -pvc \
            -outdir="$out" \
            -pdf \
            -pdflatex="pdflatex -interaction=nonstopmode" \
            -use-make ${pname}.tex
          rm -r "$out"
        '';

        buildLatex = with final; pkgs.stdenv.mkDerivation {
          inherit pname version;

          src = ./.;

          nativeBuildInputs = with pkgs; [
            (texlive.combine {
              inherit (texlive)
                scheme-medium
                multirow
                hyperref
                blindtext
                fancyhdr
                etoolbox
                topiclongtable;
            })
            gnumake
          ];

          buildPhase = ''
            latexmk \
            -pdf \
            -pdflatex="pdflatex -interaction=nonstopmode" \
            -use-make ${pname}.tex
          '';
          installPhase = ''
            install -Dm444 -t $out ${pname}.pdf 
          '';
        };

      };

      packages = forAllSystems (system: {
        inherit (nixpkgsFor.${system}) watcher buildLatex;
      });

      defaultPackage =
        forAllSystems (system: self.packages."${system}".buildLatex);


      apps = forAllSystems (system: {
        watch = {
          type = "app";
          program = "${self.packages."${system}".watcher}/bin/watch";
        };
      });

    };
}