From 92db74acf3aa3b0e59d70c15763ab83379c6269a Mon Sep 17 00:00:00 2001 From: April John Date: Tue, 13 Aug 2024 12:04:46 +0200 Subject: [PATCH 1/9] rm: nix build --- flake.lock | 6 +++--- flake.nix | 60 ------------------------------------------------------ 2 files changed, 3 insertions(+), 63 deletions(-) diff --git a/flake.lock b/flake.lock index fb00c420..484fc45c 100644 --- a/flake.lock +++ b/flake.lock @@ -16,11 +16,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1722957468, - "narHash": "sha256-SQ0TCC4aklOhN/OzcztrKqDLY8SjpIZcyvTulzhDXs0=", + "lastModified": 1723320709, + "narHash": "sha256-DeKCsLQsS58D8TB/cTjXs2x8XMvsyv2JVxcF0Hu6pu8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2a13929e1f191b3690dd2f2db13098b04adb9043", + "rev": "e1d92cda6fd1bcec60e4938ce92fcee619eea793", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index fd5ebd8d..6a40abcb 100644 --- a/flake.nix +++ b/flake.nix @@ -22,66 +22,6 @@ }); 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; - }; - 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; - }; - }); devShells = forAllSystems ({ pkgs }: { default = pkgs.mkShell { buildInputs = with pkgs; [ From 5b6a7557bb9d64584ad057a917204ba00e469f07 Mon Sep 17 00:00:00 2001 From: April John Date: Tue, 13 Aug 2024 13:19:13 +0200 Subject: [PATCH 2/9] feat: staging builds --- .github/workflows/check.yml | 50 +++++++++++++++++------------------ .github/workflows/staging.yml | 34 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/staging.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 2b4422e7..4322d55a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,31 +1,31 @@ -name: Check Types + name: Check Types -on: - push: - branches: ["*"] - pull_request: - # The branches below must be a subset of the branches above - branches: ["main"] + on: + push: + branches: ["*"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] -jobs: - tests: - runs-on: ubuntu-latest - permissions: - contents: read + jobs: + tests: + runs-on: ubuntu-latest + permissions: + contents: read - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - submodules: recursive + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: recursive - - name: Setup Bun - uses: oven-sh/setup-bun@v2 + - name: Setup Bun + uses: oven-sh/setup-bun@v2 - - name: Install NPM packages - run: | - bun install + - name: Install NPM packages + run: | + bun install - - name: Run typechecks - run: | - bun run check + - name: Run typechecks + run: | + bun run check diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml new file mode 100644 index 00000000..c9955fbd --- /dev/null +++ b/.github/workflows/staging.yml @@ -0,0 +1,34 @@ +name: Check Types + +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: Bundle + run: | + tar -xJf archive.tar.xz dist/ config/ CODE_OF_CONDUCT.md CONTRIBUTING.md README.md flake.nix shell.nix flake.lock docs/ LICENSE SECURITY.md + + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: staging-dist + path: archive.tar.xz From 9c1ca570b6d4315f30019d4adb9c6489e2de9a5c Mon Sep 17 00:00:00 2001 From: April John Date: Tue, 13 Aug 2024 13:24:48 +0200 Subject: [PATCH 3/9] fix: staging bundle --- .github/workflows/staging.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index c9955fbd..8702069a 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -1,4 +1,4 @@ -name: Check Types +name: Staging build bundle on: push: @@ -25,7 +25,7 @@ jobs: - name: Bundle run: | - tar -xJf archive.tar.xz dist/ config/ CODE_OF_CONDUCT.md CONTRIBUTING.md README.md flake.nix shell.nix flake.lock docs/ LICENSE SECURITY.md + tar cf dist/ config/ CODE_OF_CONDUCT.md CONTRIBUTING.md README.md flake.nix shell.nix flake.lock docs/ LICENSE SECURITY.md | xz -z - > archive.tar.xz - name: Upload uses: actions/upload-artifact@v4 From a17c634c162caa20a02c903a367d3816bd1c626c Mon Sep 17 00:00:00 2001 From: April John Date: Tue, 13 Aug 2024 13:27:10 +0200 Subject: [PATCH 4/9] fix: staging bundle --- .github/workflows/staging.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 8702069a..f115e875 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -25,10 +25,11 @@ jobs: - name: Bundle run: | - tar cf dist/ config/ CODE_OF_CONDUCT.md CONTRIBUTING.md README.md flake.nix shell.nix flake.lock docs/ LICENSE SECURITY.md | xz -z - > archive.tar.xz + mkdir bundle + cp dist/ config/ CODE_OF_CONDUCT.md CONTRIBUTING.md README.md flake.nix shell.nix flake.lock docs/ LICENSE SECURITY.md bundle/ - name: Upload uses: actions/upload-artifact@v4 with: name: staging-dist - path: archive.tar.xz + path: bundle/ From 78eaa5478c94bb75b07a3335d98b0c5b695f6e6a Mon Sep 17 00:00:00 2001 From: April John Date: Tue, 13 Aug 2024 13:49:17 +0200 Subject: [PATCH 5/9] fix: staging bundle --- .github/workflows/staging.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index f115e875..bc766a4a 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -26,7 +26,17 @@ jobs: - name: Bundle run: | mkdir bundle - cp dist/ config/ CODE_OF_CONDUCT.md CONTRIBUTING.md README.md flake.nix shell.nix flake.lock docs/ LICENSE SECURITY.md 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/ - name: Upload uses: actions/upload-artifact@v4 From 2f46e756595558fc1771d5a2c62e5413ccf2916d Mon Sep 17 00:00:00 2001 From: April John Date: Tue, 13 Aug 2024 14:03:58 +0200 Subject: [PATCH 6/9] fix: staging bundle --- .github/workflows/staging.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index bc766a4a..a82cc1d4 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -23,6 +23,10 @@ jobs: run: | bun install + - name: Build dist + run: | + bun run build + - name: Bundle run: | mkdir bundle From 4e6e3425ceeefe5d8ae68c392edfdcb001ec12af Mon Sep 17 00:00:00 2001 From: April John Date: Tue, 13 Aug 2024 14:59:03 +0200 Subject: [PATCH 7/9] fix: staging bundle --- .github/workflows/staging.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index a82cc1d4..22a9c928 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -41,9 +41,10 @@ jobs: 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: bundle/ + path: archive.tar.xz From f678d51542f4b34561010cad44c3def7d23b920b Mon Sep 17 00:00:00 2001 From: emily Date: Thu, 15 Aug 2024 23:57:31 +0200 Subject: [PATCH 8/9] refactor: flake --- flake.lock | 45 +++++++++++++++++++++++++++++------------- flake.nix | 57 +++++++++++++++++++++++++++--------------------------- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/flake.lock b/flake.lock index 484fc45c..655e86c9 100644 --- a/flake.lock +++ b/flake.lock @@ -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": 1723320709, - "narHash": "sha256-DeKCsLQsS58D8TB/cTjXs2x8XMvsyv2JVxcF0Hu6pu8=", + "lastModified": 1723703277, + "narHash": "sha256-nk0RaUB5f68BwtXAYy3WAjqFhVKqIl9Z89RGycTa2vk=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e1d92cda6fd1bcec60e4938ce92fcee619eea793", + "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", diff --git a/flake.nix b/flake.nix index 6a40abcb..fadc8cba 100644 --- a/flake.nix +++ b/flake.nix @@ -1,37 +1,36 @@ { - 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 }: - 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 - { - devShells = forAllSystems ({ pkgs }: { - default = pkgs.mkShell { - buildInputs = with pkgs; [ - bun - nodejs - nodePackages.typescript - nodePackages.typescript-language-server - nix-ld - ]; - }; - }); + outputs = { self, nixpkgs, flake-utils }: { + hydraJobs = { + inherit (self) packages; }; + } // flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in { + packages = { + versiajs = pkgs.callPackage ./nix/package.nix {}; + default = self.packages.${system}.versiajs; + }; + + devShells = { + default = pkgs.mkShell { + buildInputs = with pkgs; [ + bun + nodejs + nodePackages.typescript + nodePackages.typescript-language-server + nix-ld + ]; + }; + }; + }); } From f480036454db17815d0c9aea9fd0f469950d2351 Mon Sep 17 00:00:00 2001 From: emily Date: Thu, 15 Aug 2024 23:58:07 +0200 Subject: [PATCH 9/9] feat: Add nix package --- .gitignore | 6 ++- nix/fix-build-spinner.patch | 33 ++++++++++++++ nix/nodeHashes.nix | 6 +++ nix/package.nix | 90 +++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 nix/fix-build-spinner.patch create mode 100644 nix/nodeHashes.nix create mode 100644 nix/package.nix diff --git a/.gitignore b/.gitignore index b378a2e4..79f66ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -117,6 +117,10 @@ out .nuxt dist +# Nix build output + +result + # Gatsby files .cache/ @@ -182,4 +186,4 @@ glitch-dev *.pem oclif.manifest.json .direnv/ -tsconfig.tsbuildinfo \ No newline at end of file +tsconfig.tsbuildinfo diff --git a/nix/fix-build-spinner.patch b/nix/fix-build-spinner.patch new file mode 100644 index 00000000..7445c3d1 --- /dev/null +++ b/nix/fix-build-spinner.patch @@ -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(); diff --git a/nix/nodeHashes.nix b/nix/nodeHashes.nix new file mode 100644 index 00000000..df2b68d4 --- /dev/null +++ b/nix/nodeHashes.nix @@ -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; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 00000000..947f9732 --- /dev/null +++ b/nix/package.nix @@ -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" ]; + }; +})