Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trilium-next: init at 0.90.4 #348144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nixos/modules/services/web-apps/trilium.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ in
options.services.trilium-server = with lib; {
enable = mkEnableOption "trilium-server";

package = mkPackageOption pkgs "trilium-server" {};

dataDir = mkOption {
type = types.str;
default = "/var/lib/trilium";
Expand Down Expand Up @@ -117,7 +119,7 @@ in
wantedBy = [ "multi-user.target" ];
environment.TRILIUM_DATA_DIR = cfg.dataDir;
serviceConfig = {
ExecStart = "${pkgs.trilium-server}/bin/trilium-server";
ExecStart = "${cfg.package}/bin/trilium-server";
User = "trilium";
Group = "trilium";
PrivateTmp = "true";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
diff --git a/src/services/log.js b/src/services/log.js
index 2840c185a..7fb16dd08 100644
--- a/src/services/log.js
+++ b/src/services/log.js
@@ -1,45 +1,12 @@
"use strict";
-import fs from "fs";
-import dataDir from "./data_dir.js";
import cls from "./cls.js";
-if (!fs.existsSync(dataDir.LOG_DIR)) {
- fs.mkdirSync(dataDir.LOG_DIR, 0o700);
-}
-let logFile;
const SECOND = 1000;
const MINUTE = 60 * SECOND;
-const HOUR = 60 * MINUTE;
-const DAY = 24 * HOUR;
-const NEW_LINE = process.platform === "win32" ? '\r\n' : '\n';
-let todaysMidnight;
-initLogFile();
-function getTodaysMidnight() {
- const now = new Date();
- return new Date(now.getFullYear(), now.getMonth(), now.getDate());
-}
-function initLogFile() {
- todaysMidnight = getTodaysMidnight();
- const path = `${dataDir.LOG_DIR}/trilium-${formatDate()}.log`;
- if (logFile) {
- logFile.end();
- }
- logFile = fs.createWriteStream(path, { flags: 'a' });
-}
-function checkDate(millisSinceMidnight) {
- if (millisSinceMidnight >= DAY) {
- initLogFile();
- millisSinceMidnight -= DAY;
- }
- return millisSinceMidnight;
-}
function log(str) {
const bundleNoteId = cls.get("bundleNoteId");
if (bundleNoteId) {
str = `[Script ${bundleNoteId}] ${str}`;
- }
- let millisSinceMidnight = Date.now() - todaysMidnight.getTime();
- millisSinceMidnight = checkDate(millisSinceMidnight);
- logFile.write(`${formatTime(millisSinceMidnight)} ${str}${NEW_LINE}`);
+ }
console.log(str);
}
function info(message) {
@@ -61,27 +28,6 @@ function request(req, res, timeMs, responseLength = "?") {
info((timeMs >= 10 ? "Slow " : "") +
`${res.statusCode} ${req.method} ${req.url} with ${responseLength} bytes took ${timeMs}ms`);
}
-function pad(num) {
- num = Math.floor(num);
- return num < 10 ? (`0${num}`) : num.toString();
-}
-function padMilli(num) {
- if (num < 10) {
- return `00${num}`;
- }
- else if (num < 100) {
- return `0${num}`;
- }
- else {
- return num.toString();
- }
-}
-function formatTime(millisSinceMidnight) {
- return `${pad(millisSinceMidnight / HOUR)}:${pad((millisSinceMidnight % HOUR) / MINUTE)}:${pad((millisSinceMidnight % MINUTE) / SECOND)}.${padMilli(millisSinceMidnight % SECOND)}`;
-}
-function formatDate() {
- return `${pad(todaysMidnight.getFullYear())}-${pad(todaysMidnight.getMonth() + 1)}-${pad(todaysMidnight.getDate())}`;
-}
export default {
info,
error,
25 changes: 25 additions & 0 deletions pkgs/applications/office/trilium-next/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ lib, callPackage, ... }:

let
metaCommon = with lib; {
description = "Hierarchical note taking application with focus on building large personal knowledge bases";
homepage = "https://github.com/TriliumNext/Notes";
license = licenses.agpl3Plus;
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
platforms = [ "x86_64-linux" ];
maintainers = with maintainers; [ eliandoran ];
};
version = "0.90.4";
in
{

trilium-next-desktop = callPackage ./desktop.nix {
metaCommon = metaCommon;
version = version;
};
trilium-next-server = callPackage ./server.nix {
metaCommon = metaCommon;
version = version;
};

}
114 changes: 114 additions & 0 deletions pkgs/applications/office/trilium-next/desktop.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
stdenv,
lib,
unzip,
autoPatchelfHook,
fetchurl,
makeWrapper,
alsa-lib,
mesa,
nss,
nspr,
systemd,
makeDesktopItem,
copyDesktopItems,
wrapGAppsHook3,
metaCommon,
version,
}:

let
pname = "trilium-next-desktop";
inherit version;

linuxSource.url = "https://github.com/TriliumNext/Notes/releases/download/v${version}/trilium-linux-x64-${version}.tar.xz";
linuxSource.sha256 = "034cqj0g33kkyprkh1gzk0ba4h8j8lw2l4l0jbhv4z9gr21d3va6";

darwinSource.url = "https://github.com/TriliumNext/Notes/releases/download/v${version}/trilium-mac-x64-${version}.zip";
darwinSource.sha256 = "1n0zjbm21ab13ij1rpi6fp854vis78cw3j8zhz39kcbidb5k429d";

meta = metaCommon // {
mainProgram = "trilium";
platforms = [
"x86_64-linux"
"x86_64-darwin"
];
};

linux = stdenv.mkDerivation rec {
inherit pname version meta;

src = fetchurl linuxSource;

# TODO: migrate off autoPatchelfHook and use nixpkgs' electron
nativeBuildInputs = [
autoPatchelfHook
makeWrapper
wrapGAppsHook3
copyDesktopItems
];

buildInputs = [
alsa-lib
mesa
nss
nspr
stdenv.cc.cc
systemd
];

desktopItems = [
(makeDesktopItem {
name = "Trilium";
exec = "trilium";
icon = "trilium";
comment = meta.description;
desktopName = "TriliumNext Notes";
categories = [ "Office" ];
startupWMClass = "trilium notes next";
})
];

# Remove trilium-portable.sh, so trilium knows it is packaged making it stop auto generating a desktop item on launch
postPatch = ''
rm ./trilium-portable.sh
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/share/trilium
mkdir -p $out/share/icons/hicolor/128x128/apps

cp -r ./* $out/share/trilium
ln -s $out/share/trilium/trilium $out/bin/trilium

ln -s $out/share/trilium/icon.png $out/share/icons/hicolor/128x128/apps/trilium.png
runHook postInstall
'';

# LD_LIBRARY_PATH "shouldn't" be needed, remove when possible :)
# Error: libstdc++.so.6: cannot open shared object file: No such file or directory
preFixup = ''
gappsWrapperArgs+=(--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs})
'';

dontStrip = true;

passthru.updateScript = ./update.sh;
};

darwin = stdenv.mkDerivation {
inherit pname version meta;

src = fetchurl darwinSource;
nativeBuildInputs = [ unzip ];

installPhase = ''
mkdir -p $out/Applications
cp -r *.app $out/Applications
'';
};

in
if stdenv.isDarwin then darwin else linux
57 changes: 57 additions & 0 deletions pkgs/applications/office/trilium-next/server.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
stdenv,
autoPatchelfHook,
fetchurl,
nixosTests,
metaCommon,
version,
}:

let
serverSource.url = "https://github.com/TriliumNext/Notes/releases/download/v${version}/trilium-linux-x64-server-${version}.tar.xz";
serverSource.sha256 = "1yxjp0x6iym9k1sm17f8mqj8rm4ikk86wx76hlj0n0a25172igb2";
in
stdenv.mkDerivation {
pname = "trilium-next-server";
inherit version;
meta = metaCommon // {
platforms = [ "x86_64-linux" ];
};

src = fetchurl serverSource;

nativeBuildInputs = [
autoPatchelfHook
];

buildInputs = [
stdenv.cc.cc.lib
];

patches = [
# patch logger to use console instead of rolling files
./0001-Use-console-logger-instead-of-rolling-files.patch
];

installPhase = ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/share/trilium-server

cp -r ./* $out/share/trilium-server
runHook postInstall
'';

postFixup = ''
cat > $out/bin/trilium-server <<EOF
#!${stdenv.cc.shell}
cd $out/share/trilium-server
exec ./node/bin/node src/www
EOF
chmod a+x $out/bin/trilium-server
'';

passthru.tests = {
trilium-server = nixosTests.trilium-server;
};
}
23 changes: 23 additions & 0 deletions pkgs/applications/office/trilium-next/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils curl jq
set -euo pipefail

cd $(dirname "${BASH_SOURCE[0]}")

setKV () {
sed -i "s|$2 = \".*\"|$2 = \"${3:-}\"|" $1
}

version=$(curl -s --show-error "https://api.github.com/repos/TriliumNext/Notes/releases/latest" | jq -r '.tag_name' | tail -c +2)
setKV ./default.nix version $version

# Update desktop application
sha256_linux64=$(nix-prefetch-url --quiet https://github.com/TriliumNext/Notes/releases/download/v${version}/trilium-linux-x64-${version}.tar.xz)
sha256_darwin64=$(nix-prefetch-url --quiet https://github.com/TriliumNext/Notes/releases/download/v${version}/trilium-mac-x64-${version}.zip)
setKV ./desktop.nix linuxSource.sha256 $sha256_linux64
setKV ./desktop.nix darwinSource.sha256 $sha256_darwin64

# Update server
sha256_linux64_server=$(nix-prefetch-url --quiet https://github.com/TriliumNext/Notes/releases/download/v${version}/trilium-linux-x64-server-${version}.tar.xz)
setKV ./server.nix version $version
setKV ./server.nix serverSource.sha256 $sha256_linux64_server
5 changes: 5 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13066,6 +13066,11 @@ with pkgs;
trilium-server
;

inherit (callPackage ../applications/office/trilium-next {})
trilium-next-desktop
trilium-next-server
;

trippy = callPackage ../tools/networking/trippy { };

trousers = callPackage ../tools/security/trousers { };
Expand Down