summary refs log tree commit diff stats
path: root/package.nix
blob: 0bb826ea3cb20e908a3ab1a9bc23253c7dabf2d2 (plain) (blame)
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
{
  stdenv,
  system,
  # Deps
  zola,
  fd,
  # Data
  facharbeit,
  essay,
}:
stdenv.mkDerivation {
  pname = "b-peetz.de";
  version = "v1.0";
  src = ./src;

  # Run local
  preferLocalBuild = true;
  allowSubstitutes = false;

  nativeBuildInputs = [
    zola
    fd
  ];

  buildPhase = let
    installWriting = name: source:
    # bash
    ''
      pdf_path="writings/${name}"
      rm --recursive "$pdf_path/"

      install -D "${source}" "$pdf_path"
      fd . --type file --exec sed --in-place "s|$pdf_path/|$pdf_path|g"

      export base="$pdf_path"
    '';
  in
    # bash
    ''
      zola build

      cd ./public || exit 1

      # Remove some useless stuff
      rm --recursive ./categories

      mkdir --parents ./dead-trees{,/chemistry,/philosophy}

      {
          ${installWriting "kant-and-free-software.pdf" "${essay.outputs.packages."${system}".default}/philosophy/kant_and_free_software.pdf"}

          # NOTE: This link is for backward compatibility, as I have given out links with that url <2024-07-13>
          ln --symbolic --relative "$base" ./dead-trees/kant_and_free_software.pdf
          ln --symbolic --relative "$base" ./dead-trees/philosophy/kant_and_free_software.pdf
      }

      {
          ${installWriting "raman-spectroscopy.pdf" "${facharbeit.outputs.packages."${system}".default}/chemistry/facharbeit.pdf"}

          # NOTE: This link is for backward compatibility, as I have given out links with that url <2024-07-13>
          ln --symbolic --relative "$base" ./dead-trees/raman_spectrometer.pdf
          ln --symbolic --relative "$base" ./dead-trees/chemistry/facharbeit.pdf
      }
    '';

  installPhase = ''
    install -d $out/
    cp --recursive . $out/

    # # Make the website relative (this allows serving it from the ./result via python for
    # # debugging.)
    # fd . $out --type file --exec sed --in-place 's|https://b-peetz.de/|/|g'
    # fd . $out --type file --exec sed --in-place 's|https:&#x2F;&#x2F;b-peetz.de&#x2F;|/|g'
    #
    # fd . $out --type file --exec sed --in-place 's|https://b-peetz.de|/|g'
    # fd . $out --type file --exec sed --in-place 's|https:&#x2F;&#x2F;b-peetz.de|/|g'
  '';
}