Skip to content

Commit

Permalink
hoarder: init at 0.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
three committed Jan 18, 2025
1 parent 2e6a5e6 commit 34b6474
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkgs/by-name/ho/hoarder/helpers/hoarder-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eu -o pipefail
HOARDER_LIB_PATH=
NODEJS=
exec "$NODEJS/bin/node" "$HOARDER_LIB_PATH/apps/cli/dist/index.mjs" "$@"
10 changes: 10 additions & 0 deletions pkgs/by-name/ho/hoarder/helpers/migrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -eu -o pipefail
HOARDER_LIB_PATH=
RELEASE=
NODE_ENV=production

[[ -d "$DATA_DIR" ]] # Ensure DATA_DIR is defined and exists

export RELEASE NODE_ENV
exec "$HOARDER_LIB_PATH/node_modules/.bin/tsx" "$HOARDER_LIB_PATH/packages/db/migrate.ts" "$@"
11 changes: 11 additions & 0 deletions pkgs/by-name/ho/hoarder/helpers/start-web
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -eu -o pipefail
HOARDER_LIB_PATH=
RELEASE=
NODEJS=
NODE_ENV=production

[[ -d "$DATA_DIR" ]] # Ensure DATA_DIR is defined and exists

export RELEASE NODE_ENV
exec "$NODEJS/bin/node" "$HOARDER_LIB_PATH/apps/web/.next/standalone/apps/web/server.js"
11 changes: 11 additions & 0 deletions pkgs/by-name/ho/hoarder/helpers/start-workers
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -eu -o pipefail
HOARDER_LIB_PATH=
RELEASE=
NODE_ENV=production
NODE_PATH="$HOARDER_LIB_PATH/apps/workers"

[[ -d "$DATA_DIR" ]] # Ensure DATA_DIR is defined and exists

export RELEASE NODE_ENV NODE_PATH
exec "$HOARDER_LIB_PATH/node_modules/.bin/tsx" "$HOARDER_LIB_PATH/apps/workers/index.ts"
133 changes: 133 additions & 0 deletions pkgs/by-name/ho/hoarder/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
lib,
callPackage,
stdenv,
fetchFromGitHub,
nodejs,
node-gyp,
inter,
python3,
bash,
coreutils,
writeShellScript,
srcOnly,
removeReferencesTo,
pnpm_9_0_0_alpha_8,
}:
let
version = "0.21.0";
pnpm = pnpm_9_0_0_alpha_8;
in
stdenv.mkDerivation (finalAttrs: {
pname = "hoarder";
inherit version;

src = fetchFromGitHub {
owner = "hoarder-app";
repo = "hoarder";
tag = "v${finalAttrs.version}";
hash = "sha256-3xgpiqq+BV0a/OlcQiGDt59fYNF+zP0+HPeBCRiZj48=";
};

patches = [
./patches/use-local-font.patch
./patches/fix-migrations-path.patch
];
postPatch = ''
ln -s ${inter}/share/fonts/truetype ./apps/landing/app/fonts
ln -s ${inter}/share/fonts/truetype ./apps/web/app/fonts
'';

nativeBuildInputs = [
python3
nodejs
node-gyp
pnpm.configHook
];
pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pname version src;
hash = "sha256-F6iW0rjcD2RUfWptMLpDw1Gfa2mbbzxqY2Ey1lYZTU4=";
};
buildPhase = ''
runHook preBuild
# Based on matrix-appservice-discord
pushd node_modules/better-sqlite3
npm run build-release --offline "--nodedir=${srcOnly nodejs}"
find build -type f -exec ${removeReferencesTo}/bin/remove-references-to -t "${srcOnly nodejs}" {} \;
popd
export CI=true
echo "Compiling apps/web..."
pushd apps/web
pnpm run build
popd
echo "Building apps/cli"
pushd apps/cli
pnpm run build
popd
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/share/doc/hoarder
cp README.md LICENSE $out/share/doc/hoarder
# Copy necessary files into lib/hoarder while keeping the directory structure
LIB_TO_COPY="node_modules apps/web/.next/standalone apps/cli/dist apps/workers packages/db packages/shared packages/trpc"
HOARDER_LIB_PATH="$out/lib/hoarder"
for DIR in $LIB_TO_COPY; do
mkdir -p "$HOARDER_LIB_PATH/$DIR"
cp -a $DIR/{.,}* "$HOARDER_LIB_PATH/$DIR"
chmod -R u+w "$HOARDER_LIB_PATH/$DIR"
done
# NextJS requires static files are copied in a specific way
# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#automatically-copying-traced-files
cp -r ./apps/web/public "$HOARDER_LIB_PATH/apps/web/.next/standalone/apps/web/"
cp -r ./apps/web/.next/static "$HOARDER_LIB_PATH/apps/web/.next/standalone/apps/web/.next/"
# Copy and patch helper scripts
for HELPER_SCRIPT in ${./helpers}/*; do
HELPER_SCRIPT_NAME="$(basename "$HELPER_SCRIPT")"
cp "$HELPER_SCRIPT" "$HOARDER_LIB_PATH/"
substituteInPlace "$HOARDER_LIB_PATH/$HELPER_SCRIPT_NAME" \
--replace-warn "HOARDER_LIB_PATH=" "HOARDER_LIB_PATH=$HOARDER_LIB_PATH" \
--replace-warn "RELEASE=" "RELEASE=${version}" \
--replace-warn "NODEJS=" "NODEJS=${nodejs}"
chmod +x "$HOARDER_LIB_PATH/$HELPER_SCRIPT_NAME"
patchShebangs "$HOARDER_LIB_PATH/$HELPER_SCRIPT_NAME"
done
# The cli should be in bin/
mkdir -p $out/bin
mv "$HOARDER_LIB_PATH/hoarder-cli" $out/bin/
runHook postInstall
'';

fixupPhase = ''
runHook preFixup
# Remove large dependencies that are not necessary during runtime
rm -rf $out/lib/hoarder/node_modules/{@next,next,@swc,react-native,monaco-editor,faker,@typescript-eslint,@microsoft,@typescript-eslint,pdfjs-dist}
# Remove broken symlinks
find $out -type l ! -exec test -e {} \; -delete
runHook postFixup
'';

meta = {
homepage = "https://github.com/hoarder-app/hoarder";
description = "A self-hostable bookmark-everything app with a touch of AI for the data hoarders out there";
license = lib.licenses.agpl3Only;
maintainers = [ lib.maintainers.three ];
platforms = lib.platforms.linux;
};
})
10 changes: 10 additions & 0 deletions pkgs/by-name/ho/hoarder/patches/fix-migrations-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
--- a/packages/db/migrate.ts 2025-01-05 14:34:28.535360000 +0000
+++ b/packages/db/migrate.ts 2025-01-05 16:01:08.950580861 +0000
@@ -1,4 +1,5 @@
import { db } from "./drizzle";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
+import path from "path";

-migrate(db, { migrationsFolder: "./drizzle" });
+migrate(db, { migrationsFolder: path.join(__dirname, "./drizzle") });
39 changes: 39 additions & 0 deletions pkgs/by-name/ho/hoarder/patches/use-local-font.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
--- a/apps/landing/app/layout.tsx 2025-01-05 14:34:28.404363512 +0000
+++ b/apps/landing/app/layout.tsx 2025-01-03 19:48:04.929242480 +0000
@@ -1,11 +1,14 @@
import type { Metadata } from "next";
-import { Inter } from "next/font/google";
+import localFont from 'next/font/local';

import "@hoarder/tailwind-config/globals.css";

import React from "react";

-const inter = Inter({ subsets: ["latin"] });
+const inter = localFont({
+ subsets: ["latin"],
+ src: "./fonts/InterVariable.ttf",
+});

export const metadata: Metadata = {
title: "Hoarder",
--- a/apps/web/app/layout.tsx 2025-01-05 14:34:28.461361984 +0000
+++ b/apps/web/app/layout.tsx 2025-01-03 19:48:27.408659348 +0000
@@ -1,5 +1,5 @@
import type { Metadata } from "next";
-import { Inter } from "next/font/google";
+import localFont from 'next/font/local';

import "@hoarder/tailwind-config/globals.css";

@@ -13,7 +13,8 @@

import { clientConfig } from "@hoarder/shared/config";

-const inter = Inter({
+const inter = localFont({
+ src: "./fonts/InterVariable.ttf",
subsets: ["latin"],
fallback: ["sans-serif"],
});
4 changes: 4 additions & 0 deletions pkgs/development/tools/pnpm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ let
version = "8.15.9";
hash = "sha256-2qJ6C1QbxjUyP/lsLe2ZVGf/n+bWn/ZwIVWKqa2dzDY=";
};
"9_0_0_alpha_8" = {
version = "9.0.0-alpha.8";
hash = "sha256-pDOllWmwA4mpUTUpVvryXR/fQ7VoIT+95ZHDYnTUvDA";
};
"9" = {
version = "9.15.3";
hash = "sha256-wdpDcnzLwe1Cr/T9a9tLHpHmWoGObv/1skD78HC6Tq8=";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4759,7 +4759,7 @@ with pkgs;
};

inherit (callPackage ../development/tools/pnpm { })
pnpm_8 pnpm_9 pnpm_10;
pnpm_8 pnpm_9 pnpm_9_0_0_alpha_8 pnpm_10;
pnpm = pnpm_10;

po4a = perlPackages.Po4a;
Expand Down

0 comments on commit 34b6474

Please sign in to comment.