From 6697a293ae5d678cceaec2e3f4488196af936634 Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Sun, 28 May 2023 18:15:56 -0600 Subject: [PATCH] Nix flake config --- .dockerignore | 2 - .gitignore | 1 + .woodpecker.yml | 8 -- Dockerfile | 12 --- flake.lock | 77 +++++++++++++++++ flake.nix | 154 +++++++++++++++++++++++++++++++++ next.config.js | 3 + package.json | 3 +- public/resources/signature.svg | 1 - 9 files changed, 237 insertions(+), 24 deletions(-) delete mode 100644 .dockerignore delete mode 100644 .woodpecker.yml delete mode 100644 Dockerfile create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 next.config.js delete mode 100644 public/resources/signature.svg 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 < $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 @@ -