From 363e8db444d9aade0fcca2bd3171653b7dab01d8 Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Fri, 18 Sep 2026 07:42:53 +0100 Subject: Run cgithub locally on elmo --- hostnix/elmo/Makefile | 2 ++ hostnix/elmo/cgithub.nix | 27 ++++++++++++++++-- hostnix/elmo/packages/cgithub/default.nix | 46 +++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 hostnix/elmo/packages/cgithub/default.nix (limited to 'hostnix/elmo') 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" <