From 29df169c81d963742cc973a8835a7c1a126d7220 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 19 Feb 2024 10:09:50 +0000 Subject: [PATCH] Add nix flake to repo (#1111) --- .github/CODEOWNERS | 3 + .github/workflows/nix-build.yml | 18 +++++ .gitignore | 3 +- .husky/pre-commit | 26 ++++++- assets/inline-plugins/.gitkeep | 0 assets/plugins/.gitkeep | 0 assets/preload-plugins/.gitkeep | 0 assets/preload-plugins/checkLocale.js | 38 ---------- assets/preload-plugins/oauth2.js | 9 --- assets/public/fosscord-login.css | 68 ----------------- assets/public/fosscord.css | 92 ----------------------- assets/public/user.css | 1 - assets/webrtc.js | 82 -------------------- flake.lock | Bin 0 -> 1497 bytes flake.nix | 70 +++++++++++++++++ hashes.json | 3 + nix-update.sh | 10 +++ package-lock.json | Bin 293070 -> 300713 bytes package.json | 2 + src/cdn/routes/embed.ts | 20 ++++- src/util/connections/ConnectionLoader.ts | 2 +- 21 files changed, 152 insertions(+), 295 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/nix-build.yml delete mode 100644 assets/inline-plugins/.gitkeep delete mode 100644 assets/plugins/.gitkeep delete mode 100644 assets/preload-plugins/.gitkeep delete mode 100644 assets/preload-plugins/checkLocale.js delete mode 100644 assets/preload-plugins/oauth2.js delete mode 100644 assets/public/fosscord-login.css delete mode 100644 assets/public/fosscord.css delete mode 100644 assets/public/user.css delete mode 100644 assets/webrtc.js create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 hashes.json create mode 100755 nix-update.sh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..b55d76cd --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# Nix stuff is owned by Rory& - we& want to be notified if these are changed. +/flake.nix root@rory.gay +/nix-update.sh root@rory.gay \ No newline at end of file diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml new file mode 100644 index 00000000..ae9afa2e --- /dev/null +++ b/.github/workflows/nix-build.yml @@ -0,0 +1,18 @@ +name: Nix build + +on: + push: + pull_request: + +jobs: + build-nix: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v25 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: DeterminateSystems/magic-nix-cache-action@v2 + - run: nix build -L + - run: nix develop --command echo OK diff --git a/.gitignore b/.gitignore index bc780d64..e62c03d6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ build *.log.ansi *.tmp tmp/ -dump/ \ No newline at end of file +dump/ +result diff --git a/.husky/pre-commit b/.husky/pre-commit index 1bc5a8c6..702231b5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,28 @@ #!/usr/bin/env sh +#!nix-shell -i "bash" -p bash prefetch-npm-deps jq nodejs nix-output-monitor . "$(dirname -- "$0")/_/husky.sh" -npx -y lint-staged \ No newline at end of file +# Check if nix is available +if [ -x "$(/usr/bin/env which nix-shell 2>/dev/null)" ]; then + # Check if we haven't re-executed ourselves yet + if [ ! "$HOOK_NIX_SHELL" ]; then + echo "Nix is available, updating nix flake..." + export HOOK_NIX_SHELL=1 + nix-shell $0 + exit $? + else + nix flake update + # run ./nix-update.sh if package lock has changed and has no unstaged changes + if [ -n "$(git status --porcelain=v1 2>/dev/null | grep -E '^(MM| M) package-lock.json')" ]; then + echo "package-lock.json has unstaged changes. Skipping update of nix dependencies." + elif [ ! -n "$(git status --porcelain=v1 2>/dev/null | grep -E '^M package-lock.json')" ]; then + echo "package-lock.json has no changes. Skipping update of nix dependencies." + else + ./nix-update.sh || exit $? + fi + fi +else + echo "You do not appear to have nix installed. Skipping update of nix dependencies." +fi + +npx -y lint-staged diff --git a/assets/inline-plugins/.gitkeep b/assets/inline-plugins/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/assets/plugins/.gitkeep b/assets/plugins/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/assets/preload-plugins/.gitkeep b/assets/preload-plugins/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/assets/preload-plugins/checkLocale.js b/assets/preload-plugins/checkLocale.js deleted file mode 100644 index 1b5e7b71..00000000 --- a/assets/preload-plugins/checkLocale.js +++ /dev/null @@ -1,38 +0,0 @@ -const supportedLocales = [ - "bg", - "cs", - "da", - "de", - "el", - "en-GB", - "es-ES", - "fi", - "fr", - "hi", - "hr", - "hu", - "it", - "ja", - "ko", - "lt", - "nl", - "no", - "pl", - "pt-BR", - "ro", - "ru", - "sv-SE", - "th", - "tr", - "uk", - "vi", - "zh-CN", - "zh-TW" -]; - -const settings = JSON.parse(window.localStorage.getItem("UserSettingsStore")); -if (settings && !supportedLocales.includes(settings.locale)) { - // fix client locale wrong and client not loading at all - settings.locale = "en-US"; - window.localStorage.setItem("UserSettingsStore", JSON.stringify(settings)); -} \ No newline at end of file diff --git a/assets/preload-plugins/oauth2.js b/assets/preload-plugins/oauth2.js deleted file mode 100644 index 5b78ec83..00000000 --- a/assets/preload-plugins/oauth2.js +++ /dev/null @@ -1,9 +0,0 @@ -// Fixes /oauth2 endpoints not requesting a CSS file - -if (location.pathname.startsWith("/oauth2/")) { - const link = document.createElement("link"); - link.rel = "stylesheet" - link.type = "text/css" - link.href = "/assets/40532.f7b1e10347ef10e790ac.css" - document.head.appendChild(link) -} \ No newline at end of file diff --git a/assets/public/fosscord-login.css b/assets/public/fosscord-login.css deleted file mode 100644 index e66e70a0..00000000 --- a/assets/public/fosscord-login.css +++ /dev/null @@ -1,68 +0,0 @@ -/* replace tos acceptance popup */ -#app-mount > div:nth-child(7) > div > div > div.tooltipContent-bqVLWK { - visibility: hidden; -} -#app-mount > div:nth-child(7) > div > div > div.tooltipContent-bqVLWK::after { - visibility: visible; - display: block; - content: "You need to agree to this instance's rules to continue"; - margin-top: -32px; -} -/* replace login header */ -#app-mount > div.app-1q1i1E > div > div > div > div > form > div > div > div.mainLoginContainer-1ddwnR > h3 { - visibility: hidden; -} -h3.title-jXR8lp.marginBottom8-AtZOdT.base-1x0h_U.size24-RIRrxO::after { - margin-top: -32px; - content: "Welcome to Spacebar!"; - visibility: visible; - display: block; -} - -/* Logo in top left when bg removed */ -#app-mount > div.app-1q1i1E > div > a { - /* replace me: original dimensions: 130x36 */ - background: url(https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/branding/svg/Spacebar__Logo-Blue.svg); - width: 130px; - height: 23px; - background-size: contain; -} - -/* replace TOS text */ - -#app-mount - > div.app-1q1i1E - > div - > div - > div - > form - > div - > div - > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignCenter-1dQNNs.noWrap-3jynv6.marginTop20-3TxNs6 - > label - > div.label-cywgfr.labelClickable-11AuB8.labelForward-1wfipV - > * { - visibility: hidden; -} - -#app-mount - > div.app-1q1i1E - > div - > div - > div - > form - > div - > div - > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignCenter-1dQNNs.noWrap-3jynv6.marginTop20-3TxNs6 - > label - > div.label-cywgfr.labelClickable-11AuB8.labelForward-1wfipV::after { - visibility: visible; - content: "I have read and agree with the rules set by this instance."; - display: block; - margin-top: -16px; -} - -/* shrink login box to same size as register */ -.authBoxExpanded-2jqaBe { - width: 480px !important; -} \ No newline at end of file diff --git a/assets/public/fosscord.css b/assets/public/fosscord.css deleted file mode 100644 index 53ffd41b..00000000 --- a/assets/public/fosscord.css +++ /dev/null @@ -1,92 +0,0 @@ -/* loading spinner */ -#app-mount > div.app-1q1i1E > div.container-16j22k.fixClipping-3qAKRb > div.content-1-zrf2 > video { - filter: opacity(1); - background: url("http://www.clipartbest.com/cliparts/7ca/6Rr/7ca6RrLAi.gif"); - background-size: contain; - /* width: 64px; - height: 64px; */ - padding-bottom: 64px; - background-repeat: no-repeat; -} - -/* home button icon */ -#app-mount - > div.app-1q1i1E - > div - > div.layers-3iHuyZ.layers-3q14ss - > div - > div - > nav - > ul - > div.scroller-1Bvpku.none-2Eo-qx.scrollerBase-289Jih - > div.tutorialContainer-2sGCg9 - > div - > div.listItemWrapper-KhRmzM - > div - > svg - > foreignObject - > div - > div { - background-image: url(https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/branding/svg/Spacebar__Icon-Rounded-Subtract.svg); - background-size: contain; - border-radius: 50%; -} - -#app-mount - > div.app-1q1i1E - > div - > div.layers-3iHuyZ.layers-3q14ss - > div - > div - > nav - > ul - > div.scroller-1Bvpku.none-2Eo-qx.scrollerBase-289Jih - > div.tutorialContainer-2sGCg9 - > div - > div.listItemWrapper-KhRmzM - > div - > svg - > foreignObject - > div - > div, -#app-mount - > div.app-1q1i1E - > div - > div.layers-3iHuyZ.layers-3q14ss - > div - > div - > nav - > ul - > div.scroller-1Bvpku.none-2Eo-qx.scrollerBase-289Jih - > div.tutorialContainer-2sGCg9 - > div - > div.listItemWrapper-KhRmzM - > div - > svg - > foreignObject - > div - > div:hover { - background-color: white; -} -/* Login QR */ -#app-mount > div.app-1q1i1E > div > div > div > div > form > div > div > div.transitionGroup-aR7y1d.qrLogin-1AOZMt, -#app-mount > div.app-1q1i1E > div > div > div > div > form > div > div > div.verticalSeparator-3huAjp, -/* Remove login bg */ -#app-mount > div.app-1q1i1E > div > svg, -/* Download bar */ -#app-mount > div.app-1q1i1E > div > div.layers-3iHuyZ.layers-3q14ss > div > div > div > div.notice-3bPHh-.colorDefault-22HBa0, -/* Connection problem links */ -#app-mount > div.app-1q1i1E > div.container-16j22k.fixClipping-3qAKRb > div.problems-3mgf6w.slideIn-sCvzGz > div:nth-child(2), -/* Downloads button */ -#app-mount > div.app-1q1i1E > div > div.layers-3iHuyZ.layers-3q14ss > div > div > nav > ul > div.scroller-1Bvpku.none-2Eo-qx.scrollerBase-289Jih > div:nth-child(7) > div.listItemWrapper-KhRmzM > div > svg > foreignObject > div, -#app-mount > div.app-1q1i1E > div > div.layers-3iHuyZ.layers-3q14ss > div > div > nav > ul > div.scroller-1Bvpku.none-2Eo-qx.scrollerBase-289Jih > div:nth-child(6) > div, -/* help button */ -#app-mount > div.app-1q1i1E > div > div.layers-3iHuyZ.layers-3q14ss > div > div > div > div.content-98HsJk > div.chat-3bRxxu > section > div.toolbar-1t6TWx > a, -/* download button start of guild */ -#chat-messages-899316648933185083 > div > div > div:nth-child(5), -/* Thread permissions etc popups */ -#app-mount > div.app-1q1i1E > div > div.layers-3iHuyZ.layers-3q14ss > div > div > div > div.content-98HsJk > div.sidebar-2K8pFh.hasNotice-1XRy4h > nav > div.container-3O_wAf, -/* home button icon */ -#app-mount > div.app-1q1i1E > div > div.layers-3iHuyZ.layers-3q14ss > div > div > nav > ul > div.scroller-1Bvpku.none-2Eo-qx.scrollerBase-289Jih > div.tutorialContainer-2sGCg9 > div > div.listItemWrapper-KhRmzM > div > svg > foreignObject > div > div > svg { - display: none; -} \ No newline at end of file diff --git a/assets/public/user.css b/assets/public/user.css deleted file mode 100644 index a7e5c4f3..00000000 --- a/assets/public/user.css +++ /dev/null @@ -1 +0,0 @@ -/* Your custom CSS goes here, enjoy! */ \ No newline at end of file diff --git a/assets/webrtc.js b/assets/webrtc.js deleted file mode 100644 index b56e41c4..00000000 --- a/assets/webrtc.js +++ /dev/null @@ -1,82 +0,0 @@ -/* - This file is used to patch client version 134842 ( and probably a lot more ) to send additional info when using webrtc. - If you want to use it, throw it into the `preload-plugins` folder. - TODO: Make it so this file is not required for webrtc. - - Do note that webrtc, as of 17/12/2022, is not implemented yet in spacebarchat/server. -*/ - -(this.webpackChunkdiscord_app = this.webpackChunkdiscord_app || []).push([ - [[228974]], - { - 632540: (module, exports, req) => { - window.find = (filter, options = {}) => { - const { cacheOnly = false } = options; - for (let i in req.c) { - if (req.c.hasOwnProperty(i)) { - let m = req.c[i].exports; - if (m && m.__esModule && m.default && filter(m.default)) return m.default; - if (m && filter(m)) return m; - } - } - if (cacheOnly) { - console.warn("Cannot find loaded module in cache"); - return null; - } - console.warn("Cannot find loaded module in cache. Loading all modules may have unexpected side effects"); - for (let i = 0; i < req.m.length; ++i) { - let m = req(i); - if (m && m.__esModule && m.default && filter(m.default)) return m.default; - if (m && filter(m)) return m; - } - console.warn("Cannot find module"); - return null; - }; - window.findByUniqueProperties = (propNames, options) => - find((module) => propNames.every((prop) => module[prop] !== undefined), options); - window.findByDisplayName = (displayName, options) => find((module) => module.displayName === displayName, options); - window.req = req; - - init(); - } - }, - (t) => t(632540) -]); - -function retry(callback) { - return new Promise((resolve) => { - const interval = setInterval(() => { - const mod = callback(); - if (!mod) return; - - clearInterval(interval); - resolve(mod); - }, 50); - }); -} - -async function init() { - const SDP = await retry(() => findByUniqueProperties(["truncateSDP"])); - const StringManipulator = findByUniqueProperties(["uniq"]); - - const truncateSDP = SDP.truncateSDP; - SDP.truncateSDP = (e) => { - const result = truncateSDP(e); - const i = result.codecs.find((x) => x.name === "VP8"); - const a = new RegExp("^a=ice|a=extmap|opus|VP8|fingerprint|" + i?.rtxPayloadType + " rtx", "i"); - return { - sdp: StringManipulator(e) - .split(/\r\n/) - .filter(function (e) { - return a.test(e); - }) - .uniq() - .join("\n"), - codecs: result.codecs - }; - }; - // SDP.generateUnifiedSessionDescription = (e) => { - // console.log(e); - // return new RTCSessionDescription({ sdp: e.baseSDP.replace(/sendonly/g, "recvonly"), type: "answer" }); - // }; -} \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000000000000000000000000000000000..ae5e8b23070de1f0618864a223c9a3c17f752ca5 GIT binary patch literal 1497 zcmbu9U6YzH6o&8p6%N;R%m;*|Grdr2>$I-BL+kcBkbn$d%Ezv_v;VyTWjBt}+UX6D z6LQX*^FGPTU^q0=Ovu9cIDAn9HS}X1$x&5?@q18(!*pAfdPK#Fx+rDR1m8Z}9K+%3 zhtr1=5Tl%&{%!~3a6QLirGtdSW1`J`dTh*xI`GOalHur`ji;Sw30p=1rcoO3F}3eJ+>VteMg`tu4*v zQ!@*tk0i07hh5-7rqnWmJYWk~a7-~q!jrC#h@QEux3XCqgyp7kjf=iyc^HH#kJUfN z#-T)WlS4&80t4#Ks`49)k%&;ET6gj6b72Uy>(SQz~!cp)Tdb55_IE5Fkp?pD}r?VZO5_+^Lp_`@L7v^kDuZ&v8(%9s96ctD7KV z$#iBD+Kb7kQ`niNE{qNqA$?xOrSA9%7Qu-P7~u*H*S82~P(Z=}L<~y{y4-S2#*uyI pU5`Os-5X%}N3A^tkN&75oW0Z#U8v4egi7jeBA&5 literal 0 HcmV?d00001 diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..00a18f64 --- /dev/null +++ b/flake.nix @@ -0,0 +1,70 @@ +{ + description = "Spacebar server, written in Typescript."; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachSystem flake-utils.lib.allSystems (system: + let + pkgs = import nixpkgs { + inherit system; + }; + hashesFile = builtins.fromJSON (builtins.readFile ./hashes.json); + in rec { + packages.default = pkgs.buildNpmPackage { + pname = "spacebar-server-ts"; + src = ./.; + name = "spacebar-server-ts"; + nativeBuildInputs = with pkgs; [ python3 ]; + npmDepsHash = hashesFile.npmDepsHash; + makeCacheWritable = true; + postPatch = '' + substituteInPlace package.json --replace 'npx patch-package' '${pkgs.nodePackages.patch-package}/bin/patch-package' + ''; + installPhase = '' + runHook preInstall + set -x + #remove packages not needed for production, or at least try to... + npm prune --omit dev --no-save $npmInstallFlags "''${npmInstallFlagsArray[@]}" $npmFlags "''${npmFlagsArray[@]}" + find node_modules -maxdepth 1 -type d -empty -delete + + mkdir -p $out/node_modules/ + cp -r node_modules/* $out/node_modules/ + cp -r dist/ $out/node_modules/@spacebar + for i in dist/**/start.js + do + makeWrapper ${pkgs.nodejs-slim}/bin/node $out/bin/start-`dirname ''${i/dist\//}` --prefix NODE_PATH : $out/node_modules --add-flags $out/node_modules/@spacebar`dirname ''${i/dist/}`/start.js + done + set +x + substituteInPlace package.json --replace 'dist/' 'node_modules/@spacebar/' + find $out/node_modules/@spacebar/ -type f -name "*.js" | while read srcFile; do + echo Patching imports in ''${srcFile/$out\/node_modules\/@spacebar//}... + substituteInPlace $srcFile --replace 'require("./' 'require(__dirname + "/' + substituteInPlace $srcFile --replace 'require("../' 'require(__dirname + "/../' + substituteInPlace $srcFile --replace ', "assets"' ', "..", "assets"' + #substituteInPlace $srcFile --replace 'require("@spacebar/' 'require(" + done + set -x + cp -r assets/ $out/ + cp package.json $out/ + rm -v $out/assets/openapi.json + #rm -v $out/assets/schemas.json + + #debug utils: + #cp $out/node_modules/@spacebar/ $out/build_output -r + set +x + runHook postInstall + ''; + }; + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + nodejs + nodePackages.typescript + ]; + }; + } + ); +} diff --git a/hashes.json b/hashes.json new file mode 100644 index 00000000..dd55b81d --- /dev/null +++ b/hashes.json @@ -0,0 +1,3 @@ +{ + "npmDepsHash": "sha256-fZNDN2/fNy6Nu7tbr0RhQ8j4BP7X1Yhrh/fSTH7hbJc=" +} diff --git a/nix-update.sh b/nix-update.sh new file mode 100755 index 00000000..4413e6e0 --- /dev/null +++ b/nix-update.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i "bash -x" -p bash prefetch-npm-deps jq git nix-output-monitor +nix flake update +DEPS_HASH=`prefetch-npm-deps package-lock.json` +TMPFILE=$(mktemp) +jq '.npm_deps_hash = "'$DEPS_HASH'"' hashes.json > $TMPFILE +mv -- "$TMPFILE" hashes.json + +nom build .# || exit $? +git add hashes.json flake.lock flake.nix \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bc58336ff1ec639c987e2d2d724444acfabf5222..875aba1b5a898e35da28cc0a36d5a6278844ed5b 100644 GIT binary patch delta 3468 zcmZ8jYl!346-Jh4!%jQdN3uJ+o9^!HY?d}vJd&)3<VfNGVwYg|ckeO&>#lHGw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J;nbq~M;(FtH7Q@OVvhHfdsfCs!G1YXY zlUl1UED)36pXXp2ym1}g-2U4bo?Km7k{0X;zBAy}lYZ>va_zNzm(2lk7ZJ}(JtP<5mQ>#|Gn;A_P=*v{OtaG zy@0kiYkR{#vA73nhQZDhG}NA?lN2(FseOEgmfN_isTe{q>P%3Qvx-QNiE%lUZpm7y z9*t%zg|x=>v>ciU#mnxLiAI9Gf}F?WVKqEx?VeoFPNfYQHx=ePg)%cF { id = id.split(".")[0]; // remove .file extension const hash = defaultAvatarHashMap.get(id); if (!hash) throw new HTTPError("not found", 404); - const path = join(process.cwd(), "assets", "public", `${hash}.png`); + const path = join( + __dirname, + "..", + "..", + "..", + "assets", + "public", + `${hash}.png`, + ); const file = await getFile(path); if (!file) throw new HTTPError("not found", 404); @@ -80,7 +88,15 @@ router.get("/group-avatars/:id", async (req: Request, res: Response) => { id = id.split(".")[0]; // remove .file extension const hash = defaultGroupDMAvatarHashMap.get(id); if (!hash) throw new HTTPError("not found", 404); - const path = join(process.cwd(), "assets", "public", `${hash}.png`); + const path = join( + __dirname, + "..", + "..", + "..", + "assets", + "public", + `${hash}.png`, + ); const file = await getFile(path); if (!file) throw new HTTPError("not found", 404); diff --git a/src/util/connections/ConnectionLoader.ts b/src/util/connections/ConnectionLoader.ts index e9dc6973..31b8e04b 100644 --- a/src/util/connections/ConnectionLoader.ts +++ b/src/util/connections/ConnectionLoader.ts @@ -22,7 +22,7 @@ import path from "path"; import { ConnectionConfig } from "./ConnectionConfig"; import { ConnectionStore } from "./ConnectionStore"; -const root = "dist/connections"; +const root = path.join(__dirname, "..", "..", "connections"); const connectionsLoaded = false; export class ConnectionLoader {