about summary refs log tree commit diff
path: root/web
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-02-11T19·31+0000
committerVincent Ambo <tazjin@google.com>2020-02-11T19·31+0000
commitb5c50f4699ad5dd18b247b77719aa188b0003430 (patch)
tree99c61b3c4b1876d8f3fde79f3e7e1b042fa92e2a /web
parent2e958227122717ae5a013fd4656664d28d20f00d (diff)
refactor(web): Let //web/ derivations build static pages only r/539
Removes nginx configuration built by the web targets (with the
exception of the includable block used to set up redirects for old
blog URLs).
Diffstat (limited to 'web')
-rw-r--r--web/blog/default.nix10
-rw-r--r--web/homepage/default.nix14
-rw-r--r--web/homepage/nginx.nix83
3 files changed, 14 insertions, 93 deletions
diff --git a/web/blog/default.nix b/web/blog/default.nix
index 5f97c00bc9..a8e48a9d68 100644
--- a/web/blog/default.nix
+++ b/web/blog/default.nix
@@ -7,7 +7,7 @@
 with pkgs.nix.yants;
 
 let
-  inherit (builtins) filter;
+  inherit (builtins) filter hasAttr map;
 
   # Type definition for a single blog post.
   post = struct "blog-post" {
@@ -48,4 +48,12 @@ in {
 
   # Only include listed posts
   posts = filter includePost posts;
+
+  # Generate embeddable nginx configuration for redirects from old post URLs
+  oldRedirects = lib.concatStringsSep "\n" (map (post: ''
+    location ~* ^(/en)?/${post.oldKey} {
+      # TODO(tazjin): 301 once this works
+      return 302 https://tazj.in/blog/${post.key};
+    }
+  '') (filter (hasAttr "oldKey") posts));
 }
diff --git a/web/homepage/default.nix b/web/homepage/default.nix
index d2905a7eb6..3c1e75f8f3 100644
--- a/web/homepage/default.nix
+++ b/web/homepage/default.nix
@@ -65,12 +65,8 @@ let
   ));
 
   homepage = index ((map postToEntry web.blog.posts) ++ (import ./entries.nix));
-  website = runCommandNoCC "website" {} ''
-    mkdir $out
-    cp ${homepage} $out/index.html
-    cp -r ${./static} $out/static
-  '';
-in third_party.callPackage ./nginx.nix {
-  inherit website;
-  blog = web.blog;
-}
+in runCommandNoCC "website" {} ''
+  mkdir $out
+  cp ${homepage} $out/index.html
+  cp -r ${./static} $out/static
+''
diff --git a/web/homepage/nginx.nix b/web/homepage/nginx.nix
deleted file mode 100644
index 8980457447..0000000000
--- a/web/homepage/nginx.nix
+++ /dev/null
@@ -1,83 +0,0 @@
-# This file creates an nginx server that serves the blog on port 8080.
-#
-# It's not intended to be the user-facing nginx.
-{
-  # third_party attributes supplied by callPackage
-  writeText, writeShellScriptBin, nginx, lib,
-
-  # website content
-  blog, website
-}:
-
-let
-  inherit (builtins) hasAttr filter map;
-  inherit (pkgs.third_party) ;
-
-  oldRedirects = lib.concatStringsSep "\n" (map (post: ''
-    location ~* ^(/en)?/${post.oldKey} {
-      # TODO(tazjin): 301 once this works
-      return 302 https://tazj.in/blog/${post.key};
-    }
-  '') (filter (hasAttr "oldKey") blog.posts));
-
-  config = writeText "homepage-nginx.conf" ''
-    daemon off;
-    worker_processes 1;
-    error_log stderr;
-    pid /tmp/nginx-homepage.pid;
-
-    events {
-      worker_connections  1024;
-    }
-
-    http {
-      include ${nginx}/conf/mime.types;
-      fastcgi_temp_path /tmp/nginx-homepage;
-      uwsgi_temp_path /tmp/nginx-homepage;
-      scgi_temp_path /tmp/nginx-homepage;
-      client_body_temp_path /tmp/nginx-homepage;
-      proxy_temp_path /tmp/nginx-homepage;
-      sendfile on;
-
-      # Logging is handled by the primary nginx server
-      access_log off;
-
-      server {
-        listen 8080 default_server;
-        server_name tazj.in;
-        root ${website};
-
-        ${oldRedirects}
-
-        location ~* \.(webp|woff2)$ {
-          add_header Cache-Control "public, max-age=31536000";
-        }
-
-        location /blog {
-          alias ${blog.rendered};
-
-          if ($request_uri ~ ^/(.*)\.html$) {
-            return 302 /$1;
-          }
-
-          try_files $uri $uri.html $uri/ =404;
-        }
-      }
-
-      server {
-        listen 8080;
-        server_name www.tazj.in;
-        return 301 https://tazj.in$request_uri;
-      }
-    }
-  '';
-in writeShellScriptBin "homepage" ''
-  if [[ -v CONTAINER_SETUP ]]; then
-    cd /run
-    echo 'nogroup:x:30000:nobody' >> /etc/group
-    echo 'nobody:x:30000:30000:nobody:/tmp:/bin/bash' >> /etc/passwd
-  fi
-
-  mkdir -p /tmp/nginx-homepage
-  exec ${nginx}/bin/nginx -c ${config}
-''