summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-11-22 18:06:26 +0100
committerRory& <root@rory.gay>2025-11-22 18:06:26 +0100
commit9c9f8daa9a5b09b6742fdf90d79aad054ae68e97 (patch)
tree4ed4f8395fc13f301f0b3b8b5bbe6dd0f9c2225b
parentAdd well-known routes (diff)
downloadserver-ts-emma/webrtc-fuckery.tar.xz
Attempt at sing older nodejs/py github/emma/webrtc-fuckery emma/webrtc-fuckery
-rw-r--r--.idea/data_source_mapping.xml6
-rw-r--r--.idea/workspace.xml15
-rw-r--r--nix/flake-webrtc/flake.lock61
-rw-r--r--nix/flake-webrtc/flake.nix155
4 files changed, 229 insertions, 8 deletions
diff --git a/.idea/data_source_mapping.xml b/.idea/data_source_mapping.xml
deleted file mode 100644

index c2a7ad0f..00000000 --- a/.idea/data_source_mapping.xml +++ /dev/null
@@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="DataSourcePerFileMappings"> - <file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/61e66448-285a-4205-a1d7-c2704d5afb2c/console.sql" value="61e66448-285a-4205-a1d7-c2704d5afb2c" /> - </component> -</project> \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 11e173ef..93c1954a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml
@@ -111,18 +111,28 @@ <value> <map> <entry key="Start API" value="STOPPED" /> + <entry key="Start CDN" value="STOPPED" /> <entry key="Start Gateway" value="STOPPED" /> - <entry key="build" value="STOPPED" /> + <entry key="Start bundle" value="STOPPED" /> </map> </value> </entry> </map> </option> </component> + <component name="RunManager" selected="Compound.Start separated"> + <list> + <item itemvalue="Compound.Start separated" /> + <item itemvalue="npm.Start API" /> + <item itemvalue="npm.Start CDN" /> + <item itemvalue="npm.Start Gateway" /> + <item itemvalue="npm.Start bundle" /> + </list> + </component> <component name="SharedIndexes"> <attachedChunks> <set> - <option value="bundled-js-predefined-d6986cc7102b-9c94529fcfe0-JavaScript-WS-252.26199.162" /> + <option value="bundled-js-predefined-d6986cc7102b-3aa1da707db6-JavaScript-WS-252.27397.92" /> </set> </attachedChunks> </component> @@ -149,6 +159,7 @@ <workItem from="1760044946282" duration="43683000" /> <workItem from="1760402350251" duration="49898000" /> <workItem from="1760538864442" duration="1330000" /> + <workItem from="1763745191714" duration="16112000" /> </task> <servers /> </component> diff --git a/nix/flake-webrtc/flake.lock b/nix/flake-webrtc/flake.lock new file mode 100644
index 00000000..20b915f5 --- /dev/null +++ b/nix/flake-webrtc/flake.lock
@@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1704290814, + "narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/flake-webrtc/flake.nix b/nix/flake-webrtc/flake.nix new file mode 100644
index 00000000..d40ca725 --- /dev/null +++ b/nix/flake-webrtc/flake.nix
@@ -0,0 +1,155 @@ +{ + description = "Spacebar server, written in Typescript."; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + }: + let + hashesFile = builtins.fromJSON (builtins.readFile ./hashes.json); + rVersion = + let + rev = self.sourceInfo.shortRev or self.sourceInfo.dirtyShortRev; + date = builtins.substring 0 8 self.sourceInfo.lastModifiedDate; + time = builtins.substring 8 6 self.sourceInfo.lastModifiedDate; + in + "preview.${date}-${time}+${rev}"; + in + flake-utils.lib.eachSystem flake-utils.lib.allSystems ( + system: + let + pkgs = import nixpkgs { + inherit system; + }; + lib = pkgs.lib; + in + { + packages = { + default = pkgs.buildNpmPackage { + pname = "spacebar-server-ts"; + nodejs = pkgs.nodejs_20; + version = "1.0.0-" + rVersion; + + meta = with lib; { + description = "Spacebar server, a FOSS reimplementation of the Discord backend."; + homepage = "https://github.com/spacebarchat/server"; + license = licenses.agpl3Plus; + platforms = platforms.all; + mainProgram = "start-bundle"; + maintainers = with maintainers; [ RorySys ]; # lol. + }; + + src = ../../.; + npmDepsHash = hashesFile.npmDepsHash; + npmBuildScript = "build:src"; + makeCacheWritable = true; + nativeBuildInputs = with pkgs; [ + python310 + ]; + installPhase = + let + revsFile = pkgs.writeText "spacebar-server-rev.json" (builtins.toJSON { + rev = self.sourceInfo.rev or self.sourceInfo.dirtyRev; + shortRev = self.sourceInfo.shortRev or self.sourceInfo.dirtyShortRev; + lastModified = self.sourceInfo.lastModified; + }); + in '' + 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[@]}" + ${./nix/trimNodeModules.sh} + + # Copy outputs + echo "Installing package into $out" + mkdir -p $out + cp -r assets dist node_modules package.json $out/ + cp ${revsFile} $out/.rev + + # Create wrappers for start scripts + echo "Creating wrappers for start scripts" + for i in dist/**/start.js + do + makeWrapper ${pkgs.nodejs_24}/bin/node $out/bin/start-`dirname ''${i/dist\//}` --prefix NODE_PATH : $out/node_modules --add-flags --enable-source-maps --add-flags $out/$i + done + + # set +x + runHook postInstall + ''; + + passthru.tests = pkgs.testers.runNixOSTest (import ./nix/tests/test-bundle-starts.nix self); + }; + + update-nix-hashes = pkgs.writeShellApplication { + name = "update-nix"; + runtimeInputs = with pkgs; [ + prefetch-npm-deps + nix + jq + ]; + text = '' + rm -rf node_modules + ${pkgs.nodejs}/bin/npm install --save --no-audit --no-fund --prefer-offline + DEPS_HASH=$(prefetch-npm-deps package-lock.json) + TMPFILE=$(mktemp) + jq '.npmDepsHash = "'"$DEPS_HASH"'"' hashes.json > "$TMPFILE" + mv -- "$TMPFILE" hashes.json + ''; + }; + + update-nix-flake = pkgs.writeShellApplication { + name = "update-nix"; + runtimeInputs = with pkgs; [ + prefetch-npm-deps + nix + jq + ]; + text = '' + nix flake update --extra-experimental-features 'nix-command flakes' + ''; + }; + }; + + containers.docker = pkgs.dockerTools.buildLayeredImage { + name = "spacebar-server-ts"; + tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.default.version; + contents = [ self.packages.${system}.default ]; + config = { + Cmd = [ "${self.outputs.packages.${system}.default}/bin/start-bundle" ]; + Expose = [ "3001" ]; + }; + }; + + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + nodejs_20 + python310 + nodePackages.typescript + nodePackages.patch-package + nodePackages.prettier + ]; + }; + } + ) + // { + nixosModules.default = import ./nix/modules/default self; + checks = + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + in + pkgs.lib.recursiveUpdate (pkgs.lib.attrsets.unionOfDisjoint { } self.packages) { + x86_64-linux = { + spacebar-server-tests = self.packages.x86_64-linux.default.passthru.tests; + docker-image = self.containers.x86_64-linux.docker; + }; + }; + }; +}