aboutsummaryrefslogtreecommitdiff
path: root/src/fcuny.net/default.nix
blob: b34bfe04d0f03c72f305145f818965f4fbf3d442 (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
{
  pkgs ? import <nixpkgs> { },
}:

let
  pname = "fcuny-net";
  version = "0.1.0";

  site = pkgs.stdenv.mkDerivation {
    inherit pname version;
    src = ./.;

    nativeBuildInputs = with pkgs; [
      lychee
      zola
    ];

    buildPhase = ''
      zola build
      lychee docs/*.html
    '';

    installPhase = ''
      mkdir -p $out
      cp -r docs/* $out/
    '';
  };

  # Development server
  serve = pkgs.writeShellScriptBin "serve-fcuny-net" ''
    cd src/fcuny.net
    ${pkgs.zola}/bin/zola serve --interface 0.0.0.0 --port 1111
  '';

  # Nginx configuration
  nginxConfig = pkgs.writeText "fcuny-net.conf" ''
    server {
        listen 80;
        server_name fcuny.net;

        root ${site};
        index index.html;

        location / {
            try_files $uri $uri/ =404;
        }

        # Optional: Add some basic security headers
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header X-XSS-Protection "1; mode=block" always;

        # Cache static assets
        location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg)$ {
            expires 1y;
            add_header Cache-Control "public, immutable";
        }
    }
  '';

in
{
  inherit site serve nginxConfig;

  # Make site the default output
  default = site;
}