aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: d6cc962b5534e87c9d5d214cc9f7d8acecc96261 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
  description = "Aria Shrimpton dissertation";
  inputs = {
    crane.url = "github:ipetkov/crane";
    crane.inputs.nixpkgs.follows = "nixpkgs";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs = {
        nixpkgs.follows = "nixpkgs";
      };
    };
  };

  outputs = {
    self,
    nixpkgs,
    crane,
    rust-overlay,
  }: let
    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;
      overlays = [(import rust-overlay)];
    };
    toolchain = pkgs.rust-bin.fromRustupToolchain (builtins.fromTOML (builtins.readFile ./src/rust-toolchain.toml)).toolchain // {profile = "minimal";};
    craneLib = crane.lib.${system}.overrideToolchain toolchain;
    tex = pkgs.texlive.combine {
      inherit
        (pkgs.texlive)
        scheme-small
        microtype
        sectsty
        printlen
        psnfss
        helvetic
        courier
        biblatex
        latex-bin
        latexmk
        ;
    };
  in rec {
    devShells.${system}.default = pkgs.mkShell {
      buildInputs = [
        pkgs.just # command runner
        tex # latex environment
        pkgs.biber # bibliography backend

        (pkgs.callPackage ./racket-env.nix {})
        pkgs.z3
      ];
    };
    packages.${system} = {
      thesis = pkgs.stdenvNoCC.mkDerivation rec {
        name = "thesis";
        src = ./thesis;
        buildInputs = [pkgs.coreutils tex pkgs.biber];
        phases = ["unpackPhase" "buildPhase" "installPhase"];
        buildPhase = ''
          export PATH="${pkgs.lib.makeBinPath buildInputs}";
          mkdir -p .cache/texmf-var
          env TEXMFHOME=.cache TEXMFVAR=.cache/texmf-var \
            latexmk -interaction=nonstopmode -bibtex -pdf \
            main.tex
        '';
        installPhase = ''
          mkdir -p $out
          cp main.pdf $out/
        '';
      };

      default = let
        rustCrate = craneLib.buildPackage {
          pname = "candelabra-unwrapped";
          version = "1.0.0";

          src = craneLib.cleanCargoSource (craneLib.path ./src);
          doCheck = false;

          cargoExtraArgs = "-p candelabra-cli";
        };
      in
        pkgs.runCommand "candelabra" {} ''
          . ${pkgs.makeWrapper}/nix-support/setup-hook
          mkdir -p $out/bin
          makeWrapper ${rustCrate}/bin/candelabra $out/bin/candelabra \
            --set CANDELABRA_SRC_DIR ${pkgs.lib.sourceByRegex ./src [
            ".*crates"
            ".*racket_specs.*"
            ".*crates/library.*"
            ".*crates/benchmarker.*"
          ]}
        '';
    };

    dockerImages.${system}.default = pkgs.dockerTools.streamLayeredImage {
      name = "candelabra";
      maxLayers = 128;
      contents = [
        toolchain
        (pkgs.callPackage ./racket-env.nix {})
        pkgs.z3

        packages.${system}.default

        pkgs.just
        (craneLib.cleanCargoSource (craneLib.path ./src))
      ];
    };
  };
}