about summary refs log tree commit diff stats
path: root/nix/default.nix
diff options
context:
space:
mode:
authorAlan Pearce2024-04-21 13:49:30 +0200
committerAlan Pearce2024-04-21 13:49:30 +0200
commitc258ad4dfcd394c212073d6bd809de9754c30955 (patch)
tree6b9750c76aa5c0edf164b8fdec0a8838de15af67 /nix/default.nix
parent9ece57315f2cfee0b2fb64d1fd9fb05fb7fb6301 (diff)
downloadwebsite-c258ad4dfcd394c212073d6bd809de9754c30955.tar.lz
website-c258ad4dfcd394c212073d6bd809de9754c30955.tar.zst
website-c258ad4dfcd394c212073d6bd809de9754c30955.zip
serve site from filesystem rather than embedding
It's cool to embed, but it requires server.go to be at the root. Also,
I'd like to be able to update the built site separately in the future.
Diffstat (limited to 'nix/default.nix')
-rw-r--r--nix/default.nix48
1 files changed, 31 insertions, 17 deletions
diff --git a/nix/default.nix b/nix/default.nix
index 612e3e0..4299676 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -2,7 +2,7 @@
 let
   version = self.shortRev or self.dirtyShortRev or "unstable-${self.lastModified}";
   dockerTag = self.rev or self.dirtyRev or "unstable-${self.lastModified}";
-  mkDocker = type: server:
+  mkDocker = type: { server, public }:
     let
       PORT = 3000;
     in
@@ -11,6 +11,7 @@ let
       tag = dockerTag;
       contents = [
         (pkgs.writeTextDir "config.toml" (builtins.readFile ./../config.toml))
+        public
       ];
       config = {
         Cmd = [ "${server}/bin/website" ];
@@ -18,7 +19,6 @@ let
           "PRODUCTION=true"
           "LISTEN_ADDRESS=::"
           "PORT=${builtins.toString PORT}"
-          "ROOT=public"
         ];
         ExposedPorts = {
           "${builtins.toString PORT}/tcp" = { };
@@ -28,7 +28,7 @@ let
   mkDockerStream = mkDocker "streamLayeredImage";
   mkDockerImage = mkDocker "buildLayeredImage";
 in
-with pkgs; rec{
+with pkgs; rec {
   default = server;
   builder = buildGoApplication {
     pname = "website-builder";
@@ -46,6 +46,20 @@ with pkgs; rec{
     modules = ./gomod2nix.toml;
     subPackages = [ "cmd/build" ];
   };
+  public = runCommandLocal "build"
+    {
+      src = with lib.fileset; toSource {
+        root = ./..;
+        fileset = unions [
+          ./../config.toml
+          ./../content
+          ./../static
+          ./../templates
+        ];
+      };
+    } ''
+    ${builder}/bin/build -s $src -d $out/public
+  '';
   server = buildGoApplication {
     pname = "website";
     inherit version;
@@ -57,23 +71,23 @@ with pkgs; rec{
         ./../go.sum
         ./../server.go
         ./../internal
-        ./../config.toml
-        ./../content
-        ./../static
-        ./../templates
       ];
     };
-    nativeBuildInputs = [ builder ];
-    prePatch = ''
-      ${builder}/bin/build
-    '';
     modules = ./gomod2nix.toml;
     ldflags = [ "-s" "-w" "-X" "main.Commit=${version}" ];
   };
-  docker-stream = mkDockerStream server;
-  docker-stream-aarch64-linux = mkDockerStream (self.packages.aarch64-linux.server);
-  docker-stream-x86_64-linux = mkDockerStream (self.packages.x86_64-linux.server);
-  docker-image = mkDockerImage server;
-  docker-image-aarch64-linux = mkDockerImage (self.packages.aarch64-linux.server);
-  docker-image-x86_64-linux = mkDockerImage (self.packages.x86_64-linux.server);
+  docker-stream = mkDockerStream { inherit server public; };
+  docker-stream-aarch64-linux = mkDockerStream {
+    inherit public; server = (self.packages.aarch64-linux.server);
+  };
+  docker-stream-x86_64-linux = mkDockerStream {
+    inherit public; server = (self.packages.x86_64-linux.server);
+  };
+  docker-image = mkDockerImage { inherit server public; };
+  docker-image-aarch64-linux = mkDockerImage {
+    inherit public; server = (self.packages.aarch64-linux.server);
+  };
+  docker-image-x86_64-linux = mkDockerImage {
+    inherit public; server = (self.packages.x86_64-linux.server);
+  };
 }