Skip to content

Conversation

tetov
Copy link
Contributor

@tetov tetov commented Jun 13, 2025

Next.js image optimizer is trying to create directories in the nix store whenever a link is added, and in my personal instance that meant that I got no details except the URL visible in the app.

This PR (which is based on PR #412414) solves this by changing a function call in the built package, making the cache dir configurable using an environment variable.

This is coupled with setting that variable to $CACHE_DIR in the nixos module so the systemd unit takes care of it.

I haven't been able to test this in noninteractive nixosTest since I need to create an account in the browser before I can use the CLI.

Here's what it looked like before:

$ journalctl -xeu karakeep-web
maj 30 12:24:17 sulaco start-web[8283]:  ⨯ Failed to write image to cache 5rfdRTXxSUJzUihFGQs5wXX6pm9rcWtWebn42P0Mm8s= Error: ENOENT: no such file or directory, mkdir '/nix/store/ccwqm7sbbk4ik1cc06kza6vz4ff92cyj-karakeep-0.24.1/lib/karakeep/apps/web/.next/standalone/apps/web/.next/cache'
maj 30 12:24:17 sulaco start-web[8283]:     at async Object.mkdir (node:internal/fs/promises:857:10)
maj 30 12:24:17 sulaco start-web[8283]:     at async writeToCacheDir (/nix/store/ccwqm7sbbk4ik1cc06kza6vz4ff92cyj-karakeep-0.24.1/lib/karakeep/apps/web/.next/standalone/node_modules/next/dist/server/image-optimizer.js:178:5)
maj 30 12:24:17 sulaco start-web[8283]:     at async ImageOptimizerCache.set (/nix/store/ccwqm7sbbk4ik1cc06kza6vz4ff92cyj-karakeep-0.24.1/lib/karakeep/apps/web/.next/standalone/node_modules/next/dist/server/image-optimizer.js:451:13)
maj 30 12:24:17 sulaco start-web[8283]:     at async /nix/store/ccwqm7sbbk4ik1cc06kza6vz4ff92cyj-karakeep-0.24.1/lib/karakeep/apps/web/.next/standalone/node_modules/next/dist/server/response-cache/index.js:121:25
maj 30 12:24:17 sulaco start-web[8283]:     at async /nix/store/ccwqm7sbbk4ik1cc06kza6vz4ff92cyj-karakeep-0.24.1/lib/karakeep/apps/web/.next/standalone/node_modules/next/dist/lib/batcher.js:45:32 {
maj 30 12:24:17 sulaco start-web[8283]:   errno: -2,
maj 30 12:24:17 sulaco start-web[8283]:   code: 'ENOENT',
maj 30 12:24:17 sulaco start-web[8283]:   syscall: 'mkdir',
maj 30 12:24:17 sulaco start-web[8283]:   path: '/nix/store/ccwqm7sbbk4ik1cc06kza6vz4ff92cyj-karakeep-0.24.1/lib/karakeep/apps/web/.next/standalone/apps/web/.next/cache'
maj 30 12:24:17 sulaco start-web[8283]: }

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other contributing documentation in corresponding paths.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jun 13, 2025
@tetov tetov force-pushed the karakeep_cache_dir branch from 8a1e76e to e4c84e1 Compare June 15, 2025 18:35
@tetov
Copy link
Contributor Author

tetov commented Jun 19, 2025

nixpkgs-review result

Generated using nixpkgs-review-gha

Command: nixpkgs-review pr 416531

Logs: https://github.com/tetov/nixpkgs-review-gha/actions/runs/15757864012


x86_64-linux (sandbox = true)

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 1 package built:
  • karakeep

aarch64-linux (sandbox = true)

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 1 package built:
  • karakeep

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 26, 2025
@tetov tetov force-pushed the karakeep_cache_dir branch from e4c84e1 to b8346b9 Compare August 6, 2025 13:29
@tetov tetov marked this pull request as ready for review August 6, 2025 13:30
@tetov
Copy link
Contributor Author

tetov commented Aug 6, 2025

Rebased against master instead of basing on PR #412414, making this much easier to review.

If you were previously replacing the module based on this PR you could use https://github.com/tetov/nixpkgs/tree/karakeep_combined_prs instead which includes #412414, #416531, #418146 & #426982.

@tetov tetov requested a review from three August 6, 2025 13:31
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 6, 2025
@tetov tetov force-pushed the karakeep_cache_dir branch from b8346b9 to 1df2d89 Compare August 6, 2025 13:37
@tetov tetov mentioned this pull request Aug 7, 2025
13 tasks
Copy link
Contributor

@three three left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this on my own setup and I don't see the cache errors anymore. Thanks for this fix!

# provide a environment variable to override the cache directory
# https://github.com/vercel/next.js/discussions/58864
# solution copied from nextjs-ollama-llm-ui
substituteInPlace $out/lib/karakeep/apps/web/.next/standalone/node_modules/next/dist/server/image-optimizer.js \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a patch instead?

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants