summary refs log tree commit diff
diff options
context:
space:
mode:
authorAshelyn Rose <rose@tempest.dev>2023-05-28 18:15:56 -0600
committerAshelyn Rose <rose@tempest.dev>2023-05-28 18:15:56 -0600
commit6697a293ae5d678cceaec2e3f4488196af936634 (patch)
tree48e95a9c03694f75018539e4a5275273dbec0d6e
parentab3c61f5cc765dab6b8d51cd0e0e34c51544c355 (diff)
Nix flake config
-rw-r--r--.dockerignore2
-rw-r--r--.gitignore1
-rw-r--r--.woodpecker.yml8
-rw-r--r--Dockerfile12
-rw-r--r--flake.lock77
-rw-r--r--flake.nix154
-rw-r--r--next.config.js3
-rw-r--r--package.json3
-rw-r--r--public/resources/signature.svg1
9 files changed, 237 insertions, 24 deletions
diff --git a/.dockerignore b/.dockerignore
deleted file mode 100644
index 57ff971..0000000
--- a/.dockerignore
+++ /dev/null
@@ -1,2 +0,0 @@
-node_modules/
-.next/
diff --git a/.gitignore b/.gitignore
index 1477cfb..31f60bd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ node_modules/
 .vscode/
 out/
 .DS_Store
+result
diff --git a/.woodpecker.yml b/.woodpecker.yml
deleted file mode 100644
index d25834f..0000000
--- a/.woodpecker.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-pipeline:
-  neocities:
-    image: ruby:latest
-    when:
-      branch: main
-    commands:
-      - gem install neocities
-      - neocities push .
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 26a3c4f..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,12 +0,0 @@
-from node:18
-
-workdir /app
-copy package.json .
-copy package-lock.json .
-run npm ci
-copy . .
-
-run npx next build
-
-expose 3000
-entrypoint npx next start
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..74b7e69
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,77 @@
+{
+  "nodes": {
+    "nix-filter": {
+      "locked": {
+        "lastModified": 1681154353,
+        "narHash": "sha256-MCJ5FHOlbfQRFwN0brqPbCunLEVw05D/3sRVoNVt2tI=",
+        "owner": "numtide",
+        "repo": "nix-filter",
+        "rev": "f529f42792ade8e32c4be274af6b6d60857fbee7",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "nix-filter",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1685005470,
+        "narHash": "sha256-Nw+4uivzCwyZcEB71YH58zYk4N5UgcNeqb+D52bjlhI=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "60a2bc32e7369caf2f009f701ca98a8622abfdb3",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "master",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "root": {
+      "inputs": {
+        "nix-filter": "nix-filter",
+        "nixpkgs": "nixpkgs",
+        "utils": "utils"
+      }
+    },
+    "systems": {
+      "locked": {
+        "lastModified": 1681028828,
+        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+        "owner": "nix-systems",
+        "repo": "default",
+        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-systems",
+        "repo": "default",
+        "type": "github"
+      }
+    },
+    "utils": {
+      "inputs": {
+        "systems": "systems"
+      },
+      "locked": {
+        "lastModified": 1681202837,
+        "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "cfacdce06f30d2b68473a46042957675eebb3401",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..a5d6c53
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,154 @@
+{
+  inputs = {
+    utils.url = "github:numtide/flake-utils";
+    nixpkgs.url = "github:NixOS/nixpkgs/master";
+    nix-filter.url = "github:numtide/nix-filter";
+  };
+
+  outputs = {
+    self,
+    nixpkgs,
+    utils,
+    nix-filter,
+  }:
+    utils.lib.eachDefaultSystem
+    (system: let
+      pkgs = import nixpkgs {
+        inherit system;
+      };
+
+      filter = nix-filter.lib;
+
+      nodejs = pkgs.nodejs-18_x;
+
+      node_modules = pkgs.stdenv.mkDerivation {
+        name = "node_modules";
+
+        src = filter {
+          root = ./.;
+          include = [
+            ./package.json
+            ./package-lock.json
+          ];
+        };
+
+        __noChroot = true;
+
+        configurePhase = ''
+          export HOME=$TMP
+        '';
+
+        buildInputs = [ nodejs ];
+
+        buildPhase = ''
+          ${nodejs}/bin/npm ci
+        '';
+
+        installPhase = ''
+          mkdir $out
+          mv node_modules $out/node_modules
+        '';
+      };
+    in {
+      packages = {
+
+        default = pkgs.stdenv.mkDerivation {
+          name = "tempest.dev";
+
+          src = filter {
+            root = ./.;
+            exclude = [
+              ./.next
+              ./node_modules
+            ];
+          };
+
+          nativeBuildInputs = [ nodejs ];
+
+          buildPhase = ''npm run build'';
+
+          configurePhase = ''
+            ln -sf ${node_modules}/node_modules node_modules
+            export HOME=$TMP
+          '';
+
+          installPhase = ''
+            # Use the standalone nextjs version
+            mv .next/standalone $out
+
+            # Copy non-generated static files
+            if [ -d "public" ]; then
+              cp -R public $out/public
+            fi
+
+            # Also copy generated static files
+            mv .next/static $out/.next/static
+
+            # Re-link the node_modules
+            rm $out/node_modules
+            mv node_modules $out/node_modules
+
+            # Link cache directory
+            ln -s /tmp $out/.next/cache
+
+            # Wrap the script
+            cat <<ENTRYPOINT > $out/entrypoint
+            #!${pkgs.stdenv.shell}
+            exec "$(type -p node)" "$out/server.js" "$$@"
+            ENTRYPOINT
+            chmod +x $out/entrypoint
+          '';
+        };
+      };
+    }) // {
+      nixosModule = {config, lib, pkgs, ...}:
+        with lib;
+        let cfg = config.ashe.services."tempest.dev";
+
+        in {
+          options.ashe.services."tempest.dev" = {
+            enable = mkEnableOption "Enables the tempest.dev HTTP service";
+
+            port = mkOption rec {
+              type = types.int;
+              default = 8000;
+              example = default;
+              description = "The port for this service to listen on";
+
+            };
+
+            domain = mkOption rec {
+              type = types.str;
+              default = "tempest.dev";
+              example = default;
+              description = "The domain name for tempest.dev";
+            };
+          };
+
+          config = mkIf cfg.enable {
+            systemd.services."ashe.tempest.dev" = {
+              wantedBy = [ "multi-user.target" ];
+
+              serviceConfig = let pkg = self.packages.${pkgs.system}.default;
+              in {
+                Restart = "on-failure";
+                ExecStart = "${pkg}/entrypoint";
+                DynamicUser = "yes";
+                PrivateTmp = "yes";
+                Environment = [
+                  "PORT=${toString cfg.port}"
+                ];
+              };
+            };
+
+            services.nginx.virtualHosts.${cfg.domain} = {
+              locations."/" = { proxyPass = "http://127.0.0.1:${toString cfg.port}"; };
+              forceSSL = true;
+              enableACME = true;
+            };
+          };
+        };
+
+
+    };
+}
diff --git a/next.config.js b/next.config.js
new file mode 100644
index 0000000..e97173b
--- /dev/null
+++ b/next.config.js
@@ -0,0 +1,3 @@
+module.exports = {
+  output: 'standalone',
+}
diff --git a/package.json b/package.json
index 4a8d60e..9089ced 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,8 @@
   "description": "",
   "main": "index.js",
   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "build": "next build"
   },
   "author": "",
   "license": "ISC",
diff --git a/public/resources/signature.svg b/public/resources/signature.svg
deleted file mode 100644
index 4d69a57..0000000
--- a/public/resources/signature.svg
+++ /dev/null
@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" width="538.976" height="auto" viewBox="0 0 142.604 83.456" fill="white"><path d="M54.604 1.176C43.158 20.393 24.232 53.76 12.243 69.112 5.036 78.339 5.123 77.945.6 80.81c-.752 1.16-1.058 2.192.661 2.646 16.11-11.59 36.723-19.474 53.9-30.104.12 6.764-.812 11.014-4.33 14.45.168.096 16.612-.37 20.272-3.929 10.575-10.284 18.11-28.074 20.414-33.529 3.998-9.462 5.664-14.712 6.106-16.833.422-2.021-.732-2.253-1.758-.155-2.96 6.05-5.538 12.318-8.063 18.616-4.019 10.258-8.67 19.065-11.657 29.15-.485 1.638 2.703 1.205 3.298.45 2.311-2.935 4.725-5.795 6.782-8.925 1.266-1.926 2.997-3.652 4.71-5.477 1.4-1.488 1.777-.189 1.607.756-.715 3.973-2.666 8.173-1.378 11.753.521 1.447 4.838 3.496 8.465.437.444-.374.915-.72 1.323-1.134 3.15-3.917 10.236-9.918 10.255-14.78-1.449-3.749-6.414.183-8.27 1.646-2.209 2.276-4.762 6.066-2.93 8.449 1.353 1.842 4.704 2.623 6.989 2.666 5.104.097 9.185-1.396 13.639-3.84 6.248-3.43 18.962-7.81 19.912-7.952 3.514-1.311 1.984-1.887-.569-1.497-4.72.883-9.098 3.074-13.607 4.725-4.691 1.717-8.827 4.17-13.618 5.587-1.759.52-3.93 1.146-5.753.933-1.764-.206-3.64-.872-4.953-2.067-1.687-1.536.467-4.005 1.834-5.398 2.07-2.108 7.14-4.306 5.387-.756-2.255 4.089-6.4 7.694-9.434 10.489-1.853 1.321-5.206 3.732-6.747.79-1.77-3.378 1.834-10.093 1.367-11.94-.667-2.64-1.857-2.678-3.613-1.04-1.05.98-3.56 3.43-5.593 6.461-1.43 2.133-3.326 4.374-4.708 6.02-1.878 2.515-2.848 2.988-1.91.713 3.266-7.926 7.452-18.333 7.492-18.366 0 0-3.006 3.502-6.12 8.802-2.705 4.836-5.216 9.996-9.377 13.014-5.03 3.648-8.907 3.07-15.124 3.672-3.476-.025-6.79.438-10.12-.45-1.285-.038-2.457.797.292 3.19 8.026 6.99 10.964-4.858 11.34-12.945l.283-3.402c-.03-1.44-.798-2.558-1.89-1.795-12.598 8.8-24.516 14.212-37.892 21.261l-6.993 3.685-1.04.473C28.293 49.87 37.65 30.92 50.494 9.845c.731-1.024.999-.837.945.19-7.554 20.092-14.22 40.717-22.962 60.098-.558 1.618.178 3.866 1.796 1.228 8.504-22.364 15.682-45.203 25.253-67.185 1.492-3.427.666-5.665-.921-3z"></path></svg>