{ description = "Trilium Notes (experimental flake)"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; pnpm2nix = { url = "github:FliegendeWurst/pnpm2nix-nzbr/main"; inputs = { flake-utils.follows = "flake-utils"; nixpkgs.follows = "nixpkgs"; }; }; }; outputs = { self, nixpkgs, flake-utils, pnpm2nix, }: flake-utils.lib.eachDefaultSystem ( system: let pkgs = import nixpkgs { inherit system; config = { allowUnfreePredicate = pkg: system == "aarch64-darwin" && nixpkgs.lib.getName pkg == "google-chrome"; }; }; electronVersion = packageJsonDesktop.devDependencies.electron; # `or null` because a major bump lands in apps/desktop/package.json long before # nixpkgs has the matching electron_ attribute; without it the flake dies # with an attribute error instead of falling through to the pinned binary below. electronFromNixpkgs = pkgs."electron_${lib.versions.major electronVersion}" or null; # nixpkgs lags behind the Electron version pinned in apps/desktop/package.json — # often by a whole major — and its source build cannot be bumped without # upstream's Chromium dependency hashes. Build the exact pinned version from # Electron's official binary release instead, reusing the nixpkgs builder. # # Don't refresh these by hand — `pnpm chore:update-flake-electron` rewrites both # bindings from the release's SHASUMS256.txt, and the update-nix-flake workflow # opens a PR whenever apps/desktop/package.json moves ahead of the pin. pinnedElectronVersion = "45.2.3"; pinnedElectronHashes = { x86_64-linux = "a87fe741f6d121285117e574da6c9a2e65210d410123bbc04713b099add0263b"; aarch64-linux = "397c060fd9da99ab72b78787d65545b432fcadf13ef6c96658e4f525692aae0f"; aarch64-darwin = "4d7c429064087a47b855d9bd06c76ead4819b7f02b385de232d4a5c37ecef55f"; headers = "0jpkayhvf7779fch0z85cwkpkx0x6vddbixlx6cch3xfj2xfvkqx"; }; mkElectronBin = pkgs.callPackage ( pkgs.path + "/pkgs/development/tools/electron/binary/generic.nix" ) { }; # The nixpkgs Linux builder rewrites the rpath of Electron's ANGLE libraries with # an unguarded `patchelf ... lib*GL*`. Electron 44 links ANGLE into the main binary # and ships no libEGL.so/libGLESv2.so, so the glob expands to nothing and patchelf # exits with "missing filename". Let that one command tolerate an empty match; it # still patches the libraries on releases that do ship them. # # NixOS/nixpkgs@b3041dc18a skips that patchelf for Electron >= 44, so against a # newer nixpkgs (e.g. via `inputs.nixpkgs.follows`) the replacement is a no-op. # Drop this override once flake.lock's nixpkgs includes that commit. angleLibGlob = "$out/libexec/electron/lib*GL*"; tolerateMissingAngleLibs = drv: drv.overrideAttrs (prev: { postFixup = builtins.replaceStrings [ angleLibGlob ] [ "${angleLibGlob} || true" ] prev.postFixup; }); # Guarded on Linux because only that branch of the builder defines postFixup. pinnedElectron = let bin = mkElectronBin pinnedElectronVersion pinnedElectronHashes; in if stdenv.hostPlatform.isLinux then tolerateMissingAngleLibs bin else bin; electron = if electronFromNixpkgs != null && electronFromNixpkgs.version == electronVersion then electronFromNixpkgs else lib.throwIf (pinnedElectronVersion != electronVersion) '' flake.nix pins Electron ${pinnedElectronVersion}, but apps/desktop/package.json wants ${electronVersion}. Refresh pinnedElectronVersion/pinnedElectronHashes in flake.nix, or drop the override if nixpkgs ships ${electronVersion}. '' pinnedElectron; nodejs = pkgs.nodejs_24; # pnpm creates an overly long PATH env variable for child processes. # This patch deduplicates entries in PATH, which results in an equivalent but shorter entry. # https://github.com/pnpm/pnpm/issues/6106 # https://github.com/pnpm/pnpm/issues/8552 pnpm = (pkgs.pnpm_11.overrideAttrs (prev: { postInstall = prev.postInstall + '' patch $out/libexec/pnpm/dist/pnpm.mjs ${./patches/pnpm-PATH-reduction.patch} ''; # pnpm sometimes fails with ERR_PNPM_ENOENT # https://github.com/pnpm/pnpm/issues/12880 # "fix" from https://github.com/dniku/selfhostblocks/commit/ee6fc4f04fe34714fb8676704048d8d76aba85b7 postFixup = (prev.postFixup or "") + (if pkgs.stdenv.hostPlatform.isLinux then '' mv "$out/bin/pnpm" "$out/bin/.pnpm-unwrapped" cat > "$out/bin/pnpm" <