Merge branch 'main' of github.com:lysand-org/lysand

This commit is contained in:
Jesse Wierzbinski 2024-08-19 14:43:57 +02:00
commit 526ae6cfdd
No known key found for this signature in database
8 changed files with 269 additions and 128 deletions

View file

@ -1,13 +1,13 @@
name: Check Types
name: Check Types
on:
on:
push:
branches: ["*"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
jobs:
jobs:
tests:
runs-on: ubuntu-latest
permissions:

50
.github/workflows/staging.yml vendored Normal file
View file

@ -0,0 +1,50 @@
name: Staging build bundle
on:
push:
branches: ["staging"]
jobs:
tests:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install NPM packages
run: |
bun install
- name: Build dist
run: |
bun run build
- name: Bundle
run: |
mkdir bundle
cp -r dist bundle/
cp -r config bundle/
cp -r docs bundle/
cp -r CODE_OF_CONDUCT.md bundle/
cp -r CONTRIBUTING.md bundle/
cp -r README.md bundle/
cp -r flake.nix bundle/
cp -r shell.nix bundle/
cp -r flake.lock bundle/
cp -r LICENSE bundle/
cp -r SECURITY.md bundle/
tar cfJ archive.tar.xz bundle/
- name: Upload
uses: actions/upload-artifact@v4
with:
name: staging-dist
path: archive.tar.xz

4
.gitignore vendored
View file

@ -117,6 +117,10 @@ out
.nuxt
dist
# Nix build output
result
# Gatsby files
.cache/

View file

@ -1,26 +1,30 @@
{
"nodes": {
"flake-compat": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"revCount": 57,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz"
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1722957468,
"narHash": "sha256-SQ0TCC4aklOhN/OzcztrKqDLY8SjpIZcyvTulzhDXs0=",
"lastModified": 1723703277,
"narHash": "sha256-nk0RaUB5f68BwtXAYy3WAjqFhVKqIl9Z89RGycTa2vk=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "2a13929e1f191b3690dd2f2db13098b04adb9043",
"rev": "8b908192e64224420e2d59dfd9b2e4309e154c5d",
"type": "github"
},
"original": {
@ -32,9 +36,24 @@
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"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",

View file

@ -1,88 +1,27 @@
{
description = "JavaScript example flake for Zero to Nix";
description = "Lysand Server";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-compat }:
outputs = { self, nixpkgs, flake-utils }: {
hydraJobs = {
inherit (self) packages;
};
} // flake-utils.lib.eachDefaultSystem (system:
let
# Systems supported
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
# Helper to provide system-specific attributes
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
in
{
packages = forAllSystems ({ pkgs }: {
default = let
pin = pkgs.lib.importJSON ./pin.json;
src = self;
node_modules = pkgs.stdenv.mkDerivation {
pname = "versiajs-node_modules";
inherit src;
version = pin.version;
impureEnvVars = pkgs.lib.fetchers.proxyImpureEnvVars
++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ];
nativeBuildInputs = with pkgs; [ bun nodejs nodePackages.typescript nodePackages.typescript-language-server ];
buildInputs = with pkgs; [ libstdcxx5 ];
dontConfigure = true;
buildPhase = ''
bun install --production --frozen-lockfile --ignore-scripts
'';
installPhase = ''
mkdir -p $out/node_modules
cp -R ./node_modules $out
'';
outputHash = pin."${pkgs.stdenv.system}";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
dontFixup = true;
pkgs = import nixpkgs {
inherit system;
};
in pkgs.stdenv.mkDerivation {
name = "versiajs";
version = pin.version;
buildPhase = ''
runHook preBuild
ln -s ${node_modules}/node_modules .
bun run build
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp -R ./* $out
makeBinaryWrapper ${pkgs.bun}/bin/bun $out/bin/versiajs \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.bun ]} \
--add-flags "run --prefer-offline --no-install --cwd $out ./cli/index.ts start"
runHook postInstall
'';
buildInputs = with pkgs; [
nodejs
];
nativeBuildInputs = with pkgs; [ makeBinaryWrapper bun ];
inherit src;
dontConfigure = true;
in {
packages = {
versiajs = pkgs.callPackage ./nix/package.nix {};
default = self.packages.${system}.versiajs;
};
});
devShells = forAllSystems ({ pkgs }: {
devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs; [
bun
@ -92,6 +31,6 @@
nix-ld
];
};
});
};
});
}

View file

@ -0,0 +1,33 @@
diff --git a/build.ts b/build.ts
index 3b3ebe9..9531121 100644
--- a/build.ts
+++ b/build.ts
@@ -1,10 +1,10 @@
import { $ } from "bun";
-import ora from "ora";
+// import ora from "ora";
import { routes } from "~/routes";
-const buildSpinner = ora("Building").start();
+// const buildSpinner = ora("Building").start();
-await $`rm -rf dist && mkdir dist`;
+// await $`rm -rf dist && mkdir dist`;
await Bun.build({
entrypoints: [
@@ -25,7 +25,7 @@ await Bun.build({
}
});
-buildSpinner.text = "Transforming";
+// buildSpinner.text = "Transforming";
// Copy Drizzle migrations to dist
await $`cp -r drizzle dist/drizzle`;
@@ -49,4 +49,4 @@ await $`cp package.json dist/package.json`;
// Copy cli/theme.json
await $`cp cli/theme.json dist/cli/theme.json`;
-buildSpinner.stop();
+// buildSpinner.stop();

6
nix/nodeHashes.nix Normal file
View file

@ -0,0 +1,6 @@
{ lib }: {
x86_64-linux = "sha256-T/U9altP5HFzmULtsuvHQIXQXDCmQEAau8KFN8J5i/8=";
x86_64-darwin = lib.fakeHash;
aarch64-linux = "sha256-6ZzrYI2G+7q9Efgu5iKhZB3bT2C7T5fk4I/t5glpQYA=";
aarch64-darwin = lib.fakeHash;
}

90
nix/package.nix Normal file
View file

@ -0,0 +1,90 @@
{
lib,
stdenv,
fetchFromGitHub,
bun,
callPackage,
nodeHashes ? callPackage ./nodeHashes.nix { inherit lib; },
nodePackages_latest,
makeBinaryWrapper,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "versiajs";
version = "0.7.0";
src = ../.;
node_modules = stdenv.mkDerivation {
pname = "${finalAttrs.pname}-node_modules";
inherit (finalAttrs) version src;
nativeBuildInputs = with nodePackages_latest; [ bun nodejs typescript ];
dontConfigure = true;
buildPhase = ''
bun install --production --no-progress --ignore-scripts --frozen-lockfile
'';
installPhase = ''
mkdir -p $out/node_modules
cp -r node_modules $out
'';
dontFixup = true;
outputHash = nodeHashes.${stdenv.system};
outputHashMode = "recursive";
};
nativeBuildInputs = [ bun ];
buildInputs = [ bun nodePackages_latest.nodejs makeBinaryWrapper ];
patches = [ ./fix-build-spinner.patch ];
configurePhase = ''
runHook preConfigure
cp -r ${finalAttrs.node_modules}/node_modules .
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
bun run build
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -r dist/ $out
mkdir -p $out/bin
makeBinaryWrapper ${bun}/bin/bun $out/bin/versiajs \
--prefix PATH : ${lib.makeBinPath [ bun ]} \
--set NODE_ENV "production" \
--add-flags "run --prefer-offline --no-install --cwd $out $out/index.js"
makeBinaryWrapper ${bun}/bin/bun $out/bin/versiajs-cli \
--prefix PATH : ${lib.makeBinPath [ bun ]} \
--add-flags "run --prefer-offline --no-install --cwd $out $out/cli/index.js"
runHook postInstall
'';
meta = {
description = "A new federated server written with TypeScript and Bun ";
homepage = "https://lysand.org";
license = with lib.licenses; [ agpl3Plus ];
maintainers = with lib.maintainers; [ snaki ];
platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
};
})