build(frontend): use pnpm

deno is evil
This commit is contained in:
isabel
2026-04-12 16:01:21 +00:00
committed by Tangled
parent 1c87ef5536
commit bc5e0e0446
12 changed files with 2616 additions and 2109 deletions
+5 -2
View File
@@ -1,7 +1,10 @@
FROM denoland/deno:alpine AS frontend
FROM node:24-alpine AS builder
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
COPY frontend/package.json frontend/pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY frontend/ ./
RUN deno task build
RUN pnpm build
FROM rust:1.92-alpine AS builder
RUN apk add --no-cache ca-certificates musl-dev pkgconfig openssl-dev openssl-libs-static mold clang protoc
+7 -6
View File
@@ -49,12 +49,12 @@ mkdir -p /var/lib/tranquil/blobs
We'll set ownership after creating the service user.
## Install deno (for frontend build)
## Install Node.js and pnpm (for frontend build)
```bash
curl -fsSL https://deno.land/install.sh | sh
export PATH="$HOME/.deno/bin:$PATH"
echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc
curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
apt install -y nodejs
npm install -g pnpm
```
## Clone and build Tranquil PDS
@@ -64,7 +64,8 @@ cd /opt
git clone https://tangled.org/tranquil.farm/tranquil-pds tranquil-pds
cd tranquil-pds
cd frontend
deno task build
pnpm install --frozen-lockfile
pnpm build
cd ..
cargo build --release
```
@@ -330,7 +331,7 @@ Update Tranquil PDS:
```bash
cd /opt/tranquil-pds
git pull
cd frontend && deno task build && cd ..
cd frontend && pnpm install --frozen-lockfile && pnpm build && cd ..
cargo build --release
systemctl stop tranquil-pds
cp target/release/tranquil-pds /usr/local/bin/
Generated
+4 -21
View File
@@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1766314097,
"narHash": "sha256-laJftWbghBehazn/zxVJ8NdENVgjccsWAdAqKXhErrM=",
"lastModified": 1775888245,
"narHash": "sha256-nwASzrRDD1JBEu/o8ekKYEXm/oJW6EMCzCRdrwcLe90=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "306ea70f9eb0fb4e040f8540e2deab32ed7e2055",
"rev": "13043924aaa7375ce482ebe2494338e058282925",
"type": "github"
},
"original": {
@@ -16,26 +16,9 @@
"type": "github"
}
},
"nixpkgs-fetch-deno": {
"locked": {
"lastModified": 1766410835,
"narHash": "sha256-dRhVt0aFDyTqppyzRLxiO1JZEAoIA2fUnaeyJTe+UwU=",
"owner": "aMOPel",
"repo": "nixpkgs",
"rev": "c9801acc8c4fac6377d076bc1c102b15bd9cfa6f",
"type": "github"
},
"original": {
"owner": "aMOPel",
"ref": "feat/fetchDenoDeps",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"nixpkgs-fetch-deno": "nixpkgs-fetch-deno"
"nixpkgs": "nixpkgs"
}
}
},
+42 -40
View File
@@ -1,51 +1,53 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
# tranquil frontend uses deno as its package manager and build time runtime.
# nixpkgs does not have deno support yet but its being worked on in https://github.com/NixOS/nixpkgs/pull/419255
# for now we important that PR as well purely for its fetchDenoDeps
nixpkgs-fetch-deno.url = "github:aMOPel/nixpkgs/feat/fetchDenoDeps";
};
outputs = {
self,
nixpkgs,
...
} @ inputs: let
forAllSystems = function:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
system: (function system nixpkgs.legacyPackages.${system})
);
in {
packages = forAllSystems (system: pkgs: {
tranquil-pds = pkgs.callPackage ./default.nix {};
tranquil-frontend = pkgs.callPackage ./frontend.nix {
inherit (inputs.nixpkgs-fetch-deno.legacyPackages.${system}) fetchDenoDeps;
outputs =
{
self,
nixpkgs,
}:
let
forAllSystems =
function:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
system: function nixpkgs.legacyPackages.${system}
);
in
{
packages = forAllSystems (pkgs: {
tranquil-pds = pkgs.callPackage ./default.nix { };
tranquil-frontend = pkgs.callPackage ./frontend.nix { };
default = self.packages.${pkgs.stdenv.hostPlatform.system}.tranquil-pds;
});
devShells = forAllSystems (pkgs: {
default = pkgs.callPackage ./shell.nix { };
});
nixosModules = {
default = self.nixosModules.tranquil-pds;
tranquil-pds =
{ lib, pkgs, ... }:
{
_file = "${self.outPath}/flake.nix#nixosModules.tranquil-pds";
imports = [ (import ./module.nix self) ];
config.services.tranquil-pds = {
package = self.packages.${pkgs.stdenv.hostPlatform.system}.tranquil-pds;
settings.frontend.package = self.packages.${pkgs.stdenv.hostPlatform.system}.tranquil-frontend;
};
};
};
default = self.packages.${pkgs.stdenv.hostPlatform.system}.tranquil-pds;
});
devShells = forAllSystems (system: pkgs: {
default = pkgs.callPackage ./shell.nix {};
});
checks.x86_64-linux.integration = import ./test.nix {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
inherit self;
};
nixosModules = {
default = self.nixosModules.tranquil-pds;
tranquil-pds = {
_file = "${self.outPath}/flake.nix#nixosModules.tranquil-pds";
imports = [(import ./module.nix self)];
checks.aarch64-linux.integration = import ./test.nix {
pkgs = nixpkgs.legacyPackages.aarch64-linux;
inherit self;
};
};
checks.x86_64-linux.integration = import ./test.nix {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
inherit self;
};
checks.aarch64-linux.integration = import ./test.nix {
pkgs = nixpkgs.legacyPackages.aarch64-linux;
inherit self;
};
};
}
+41 -60
View File
@@ -1,66 +1,47 @@
{
lib,
stdenvNoCC,
fetchDenoDeps,
fetchFromGitHub,
buildGoModule,
deno,
esbuild,
}: let
pnpm,
pnpmConfigHook,
fetchPnpmDeps,
nix-update-script,
}:
let
toml = (lib.importTOML ./Cargo.toml).workspace.package;
deno-deps = fetchDenoDeps {
pname = "tranquil-frontend-deno-deps";
denoLock = ./frontend/deno.lock;
hash = "sha256-UB+E00TjWX0fTUZ7XwcwRJ/OUOSSJpz6Ss04U5i8dGI=";
};
# the esbuild in upstream nixpkgs is too old.
esbuild' = esbuild.override {
buildGoModule = args: buildGoModule (
args // (
let
version = "0.27.2";
in {
inherit version;
src = fetchFromGitHub {
owner = "evanw";
repo = "esbuild";
tag = "v${version}";
hash = "sha256-JbJB3F1NQlmA5d0rdsLm4RVD24OPdV4QXpxW8VWbESA";
};
vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ";
}
)
);
};
in stdenvNoCC.mkDerivation {
pname = "tranquil-frontend";
inherit (toml) version;
src = ./frontend;
in
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "tranquil-frontend";
inherit (toml) version;
nativeBuildInputs = [
deno
src = ./frontend;
pnpmDeps = fetchPnpmDeps {
inherit (finalAttrs) pname version src;
fetcherVersion = 3;
hash = "sha256-E0S8dOaTOpY9m7Ft59tUQ6CLlLriWPE4WE1+S45vomY=";
};
nativeBuildInputs = [
pnpm
pnpmConfigHook
];
buildPhase = ''
runHook preBuild
pnpm build
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -r ./dist $out
runHook postInstall
'';
passthru.updateScript = nix-update-script {
extraArgs = [
"--version"
"SKIP"
];
# tell vite (through the esbuild api) where the nix provided esbuild binary is
env.ESBUILD_BINARY_PATH = lib.getExe esbuild';
buildPhase = ''
# copy the deps to the required location
cp -r --no-preserve=mode ${deno-deps.denoDeps}/.deno ./
cp -r --no-preserve=mode ${deno-deps.denoDeps}/vendor ./
pwd
ls /build/frontend/vendor
# Now you can run the project using deps
# you need to activate [deno's vendor feature](https://docs.deno.com/runtime/fundamentals/modules/#vendoring-remote-modules)
# you need to use the `$DENO_DIR` env var, to point deno to the correct local cache
DENO_DIR=./.deno deno run --frozen --cached-only build
'';
installPhase = ''
cp -r ./dist $out
'';
}
};
})
+5 -2
View File
@@ -1,7 +1,10 @@
FROM denoland/deno:alpine AS builder
FROM node:24-alpine AS builder
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . ./
RUN deno task build
RUN pnpm build
FROM nginx:1.29-alpine
COPY --from=builder /app/dist /usr/share/nginx/html
-22
View File
@@ -1,22 +0,0 @@
{
"tasks": {
"dev": "deno run -A npm:vite",
"build": "deno run -A npm:vite build",
"preview": "deno run -A npm:vite preview",
"check": "deno run -A npm:svelte-check --tsconfig ./tsconfig.json",
"test": "deno run -A npm:vitest",
"test:run": "deno run -A npm:vitest run",
"test:watch": "deno run -A npm:vitest watch",
"test:ui": "deno run -A npm:vitest --ui",
"test:coverage": "deno run -A npm:vitest run --coverage"
},
"nodeModulesDir": "auto",
"lint": {
"rules": {
"exclude": [
"require-await",
"prefer-const"
]
}
}
}
-1930
View File
File diff suppressed because it is too large Load Diff
+2475
View File
File diff suppressed because it is too large Load Diff
+16 -11
View File
@@ -1,15 +1,17 @@
self: {
{
lib,
pkgs,
config,
...
}: let
}:
let
cfg = config.services.tranquil-pds;
inherit (lib) types mkOption;
settingsFormat = pkgs.formats.toml { };
in {
in
{
_class = "nixos";
options.services.tranquil-pds = {
@@ -17,8 +19,8 @@ in {
package = mkOption {
type = types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.tranquil-pds;
defaultText = lib.literalExpression "self.packages.\${pkgs.stdenv.hostPlatform.system}.tranquil-pds";
default = pkgs.callPackage ./default.nix { };
defaultText = lib.literalExpression "pkgs.tranquil-pds";
description = "The tranquil-pds package to use";
};
@@ -97,13 +99,16 @@ in {
};
frontend = {
enabled = lib.mkEnableOption "serving the frontend from the backend. Disable to serve the frontend manually"
// { default = true; };
enabled =
lib.mkEnableOption "serving the frontend from the backend. Disable to serve the frontend manually"
// {
default = true;
};
dir = mkOption {
type = types.nullOr types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.tranquil-frontend;
defaultText = lib.literalExpression "self.packages.\${pkgs.stdenv.hostPlatform.system}.tranquil-frontend";
default = pkgs.callPackage ./frontend.nix { };
defaultText = lib.literalExpression "pkgs.tranquil-frontend";
description = "Frontend package to be served by the backend";
};
};
@@ -137,7 +142,7 @@ in {
};
config = lib.mkIf cfg.enable (
lib.mkMerge [
lib.mkMerge [
(lib.mkIf cfg.database.createLocally {
services.postgresql = {
enable = true;
@@ -159,7 +164,7 @@ in {
};
})
{
{
users.users.${cfg.user} = {
isSystemUser = true;
inherit (cfg) group;
+10 -6
View File
@@ -207,11 +207,15 @@ if ! command -v rustc &>/dev/null; then
source "$HOME/.cargo/env"
fi
log_info "Installing deno..."
export PATH="$HOME/.deno/bin:$PATH"
if ! command -v deno &>/dev/null && [[ ! -f "$HOME/.deno/bin/deno" ]]; then
curl -fsSL https://deno.land/install.sh | sh
grep -q 'deno/bin' ~/.bashrc 2>/dev/null || echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc
log_info "Installing Node.js..."
if ! command -v node &>/dev/null; then
curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
apt install -y nodejs
fi
log_info "Installing pnpm..."
if ! command -v pnpm &>/dev/null; then
npm install -g pnpm
fi
log_info "Cloning Tranquil PDS..."
@@ -223,7 +227,7 @@ fi
cd /opt/tranquil-pds
log_info "Building frontend..."
"$HOME/.deno/bin/deno" task build --filter=frontend
cd frontend && pnpm install --frozen-lockfile && pnpm build && cd ..
log_success "Frontend built"
log_info "Building Tranquil PDS (this takes a while)..."
+11 -9
View File
@@ -1,5 +1,4 @@
{
lib,
mkShell,
callPackage,
rustPlatform,
@@ -17,13 +16,18 @@
cargo-nextest,
# frontend tooling
deno,
svelte-language-server,
typescript-language-server,
}: let
defaultPackage = callPackage ./default.nix { };
in mkShell {
inputsFrom = [ defaultPackage ];
}:
let
pds = callPackage ./default.nix { };
frontend = callPackage ./frontend.nix { };
in
mkShell {
inputsFrom = [
pds
frontend
];
env = {
RUST_SRC_PATH = rustPlatform.rustLibSrc;
@@ -39,10 +43,8 @@ in mkShell {
rust-analyzer
sqlx-cli
cargo-nextest
deno
svelte-language-server
typescript-language-server
];
}