Merge pull request #2075 from TriliumNext/feature/nix_flake

Nix flake
This commit is contained in:
Elian Doran 2025-06-02 08:58:22 +03:00 committed by GitHub
commit 089bf75ee2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 170 additions and 1 deletions

2
.gitignore vendored
View File

@ -44,3 +44,5 @@ upload
.rollup.cache .rollup.cache
*.tsbuildinfo *.tsbuildinfo
/result

61
flake.lock generated Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1748437600,
"narHash": "sha256-hYKMs3ilp09anGO7xzfGs3JqEgUqFMnZ8GMAqI6/k04=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "7282cb574e0607e65224d33be8241eae7cfe0979",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"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",
"version": 7
}

106
flake.nix Normal file
View File

@ -0,0 +1,106 @@
{
description = "TriliumNext Notes (experimental flake)";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
packageJSON = builtins.fromJSON (builtins.readFile ./package.json);
pkgs = import nixpkgs { inherit system; };
electron = pkgs.electron_35;
inherit (pkgs)
copyDesktopItems
lib
makeBinaryWrapper
makeDesktopItem
nodejs
pnpm
stdenv
wrapGAppsHook3
;
desktop = stdenv.mkDerivation (finalAttrs: {
pname = "triliumnext-desktop";
version = packageJSON.version;
src = lib.cleanSource ./.;
nativeBuildInputs = [
pnpm.configHook
nodejs
nodejs.python
copyDesktopItems
makeBinaryWrapper
wrapGAppsHook3
];
dontWrapGApps = true;
buildPhase = ''
runHook preBuild
# Disable NX interaction
export NX_TUI=false
export NX_DAEMON=false
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
node_modules/.pnpm/sass-embedded-linux-x64@*/node_modules/sass-embedded-linux-x64/dart-sass/src/dart
pnpm nx run desktop:build --outputStyle stream --verbose
# Rebuild dependencies
export npm_config_nodedir=${electron.headers}
pnpm nx run desktop:rebuild-deps --outputStyle stream --verbose
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,share/icons/hicolor/512x512/apps,opt/trilium}
cp --archive apps/desktop/dist/* $out/opt/trilium
cp apps/client/src/assets/icon.png $out/share/icons/hicolor/512x512/apps/trilium.png
makeWrapper ${lib.getExe electron} $out/bin/trilium \
"''${gappsWrapperArgs[@]}" \
--set-default ELECTRON_IS_DEV 0 \
--add-flags $out/opt/trilium/main.cjs
runHook postInstall
'';
desktopItems = [
(makeDesktopItem {
name = "TriliumNext Notes";
exec = finalAttrs.meta.mainProgram;
icon = "trilium";
comment = finalAttrs.meta.description;
desktopName = "TriliumNext Notes";
categories = [ "Office" ];
startupWMClass = "Trilium Notes Next";
})
];
pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pname version src;
hash = "sha256-xC0u1h92wtthylOAw+IF9mpFi0c4xajJhUcA9pqzcAw=";
};
meta = {
description = "Free and open-source, cross-platform hierarchical note taking application with focus on building large personal knowledge bases";
mainProgram = "trilium";
};
});
in
{
packages.default = desktop;
}
);
}