diff --git a/.gitignore b/.gitignore index cf2fa89dd..ecb8c9edf 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,6 @@ apps/*/out upload .rollup.cache -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo + +/result \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..07c8f8b86 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..a2dd0197b --- /dev/null +++ b/flake.nix @@ -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; + } + ); +}