about summary refs log tree commit diff stats
path: root/nix
diff options
context:
space:
mode:
Diffstat (limited to '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);
+  };
 }