summaryrefslogtreecommitdiff
path: root/hostnix
diff options
context:
space:
mode:
Diffstat (limited to 'hostnix')
-rw-r--r--hostnix/elmo/Makefile2
-rw-r--r--hostnix/elmo/cgithub.nix27
-rw-r--r--hostnix/elmo/packages/cgithub/default.nix46
3 files changed, 73 insertions, 2 deletions
diff --git a/hostnix/elmo/Makefile b/hostnix/elmo/Makefile
index 825a23e..dfe8025 100644
--- a/hostnix/elmo/Makefile
+++ b/hostnix/elmo/Makefile
@@ -1,5 +1,7 @@
push:
rsync -r --rsync-path='sudo rsync' --exclude Makefile . elmo:/etc/nixos/
+ rsync -r --delete --chown=joe:users --rsync-path='sudo rsync' \
+ --exclude node_modules --exclude .wrangler ../../cgithub/ elmo:/etc/nixos/cgithub/
switch: push
ssh elmo sudo nixos-rebuild switch
diff --git a/hostnix/elmo/cgithub.nix b/hostnix/elmo/cgithub.nix
index ec7c162..45ca323 100644
--- a/hostnix/elmo/cgithub.nix
+++ b/hostnix/elmo/cgithub.nix
@@ -1,11 +1,34 @@
-{ ... }:
+{ pkgs, ... }:
+let
+ # The Makefile copies cgithub/ next to this flake before rebuilding.
+ cgithub = pkgs.callPackage ./packages/cgithub { src = ./cgithub; };
+in
{
+ systemd.sockets.cgithub = {
+ wantedBy = [ "sockets.target" ];
+ socketConfig = {
+ ListenStream = "/run/cgithub/socket";
+ SocketGroup = "nginx";
+ SocketMode = "0660";
+ };
+ };
+
+ systemd.services.cgithub = {
+ requires = [ "cgithub.socket" ];
+ after = [ "cgithub.socket" ];
+ serviceConfig = {
+ Type = "exec";
+ DynamicUser = true;
+ ExecStart = "${cgithub}/bin/cgithub-server";
+ };
+ };
+
services.nginx.virtualHosts."fluffy-kitten.elmo.mou.fo" = {
useACMEHost = "elmo.mou.fo";
forceSSL = true;
locations."/" = {
- return = "301 https://cgithub.jmou.workers.dev$request_uri";
+ proxyPass = "http://unix:/run/cgithub/socket";
};
};
}
diff --git a/hostnix/elmo/packages/cgithub/default.nix b/hostnix/elmo/packages/cgithub/default.nix
new file mode 100644
index 0000000..12e6086
--- /dev/null
+++ b/hostnix/elmo/packages/cgithub/default.nix
@@ -0,0 +1,46 @@
+{
+ bash,
+ fetchPnpmDeps,
+ nodejs_22,
+ pnpm_11,
+ pnpmConfigHook,
+ stdenv,
+ src,
+}:
+
+let
+ pnpm = pnpm_11;
+in
+stdenv.mkDerivation (finalAttrs: {
+ pname = "cgithub";
+ version = "1.0.0";
+ inherit src;
+
+ nativeBuildInputs = [
+ nodejs_22
+ pnpmConfigHook
+ pnpm
+ ];
+
+ pnpmDeps = fetchPnpmDeps {
+ inherit (finalAttrs) pname version src;
+ inherit pnpm;
+ fetcherVersion = 4;
+ hash = "sha256-XxkTo+JeFyPEVgIJYm4/VaIAijaj4Sc0EzCCjZsu62Q=";
+ };
+
+ buildPhase = ''
+ node scripts/build.ts
+ '';
+
+ installPhase = ''
+ mkdir -p "$out/bin"
+ cp -a . "$out/"
+
+ cat > "$out/bin/cgithub-server" <<EOF
+ #!${bash}/bin/bash
+ exec ${nodejs_22}/bin/node "$out/src/index.ts" "\$@"
+ EOF
+ chmod +x "$out/bin/cgithub-server"
+ '';
+})