Skip to content

Add setting narinfo-cache-meta-ttl#355

Merged
edolstra merged 1 commit intomainfrom
eelcodolstra/nix-305-make-nix-store-info-refresh-override-the-7-day-ttl
Feb 17, 2026
Merged

Add setting narinfo-cache-meta-ttl#355
edolstra merged 1 commit intomainfrom
eelcodolstra/nix-305-make-nix-store-info-refresh-override-the-7-day-ttl

Conversation

@edolstra
Copy link
Collaborator

@edolstra edolstra commented Feb 16, 2026

Motivation

This makes the current hard-coded 7-day nix-cache-info TTL configurable, making --offline and --refresh do the right thing.

Context

Summary by CodeRabbit

  • New Features

    • Added configurable TTL for NarInfo metadata cache (narinfo-cache-meta-ttl), defaulting to 7 days.
  • Bug Fixes

    • Improved offline and refresh behavior to correctly invalidate NarInfo metadata cache when requested.
  • Tests

    • Added functional tests verifying NarInfo metadata caching with HTTP and the effect of --refresh.

@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

A new public setting ttlNarInfoCacheMeta controls the TTL for NarInfo metadata caching (default 7 days). Code now uses this setting instead of a hardcoded constant; defaults are adjusted in disableNet and reset on --refresh. Tests added to verify behavior.

Changes

Cohort / File(s) Summary
Configuration Setting
src/libstore/include/nix/store/globals.hh
Added Setting<unsigned int> ttlNarInfoCacheMeta (default 7243600) with help text for binary cache metadata TTL (narinfo-cache-meta-ttl).
Cache Implementation
src/libstore/nar-info-disk-cache.cc
Removed hardcoded cacheInfoTtl field and updated cache cutoff calculation to use settings.ttlNarInfoCacheMeta.
CLI Defaults & Refresh
src/nix/main.cc
Set ttlNarInfoCacheMeta to UINT_MAX in disableNet defaulting; reset it to 0 during --refresh handling alongside other TTLs.
Functional Tests
tests/functional/binary-cache.sh
Added scenario to validate HTTP metadata caching behavior, persistence after removing nix-cache-info, and the effect of --refresh on metadata TTL/cache usage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 I nibble at TTLs under moonlight bright,
A seven-day morsel, tidy and light.
Settings now dance where constants once lay,
Refresh gives a hop, then clears them away.
Cache and carrot, kept just right. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: adding a new configurable setting for narinfo cache metadata TTL, which is the primary objective across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch eelcodolstra/nix-305-make-nix-store-info-refresh-override-the-7-day-ttl

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/functional/binary-cache.sh (1)

330-332: Consider clarifying the expected error condition in the comment.

The comment states the failure is due to "nix-cache-info is gone and the cached metadata TTL is overridden to 0," but the expected error message is "uploading.*is not supported". This suggests the store attempts to create/upload cache info when it can't be fetched, rather than simply failing to read it.

Consider updating the comment to explain this behavior more explicitly for future maintainers:

 # But with --refresh, it should fail because nix-cache-info is gone
-# and the cached metadata TTL is overridden to 0.
+# and the cached metadata TTL is overridden to 0. When nix-cache-info
+# cannot be fetched, the HTTP store falls back to trying to create it,
+# which fails because uploading is not supported.
 _NIX_FORCE_HTTP=1 expectStderr 1 nix store info --store "file://$cacheDir" --refresh | grepQuiet "uploading.*is not supported"

@github-actions
Copy link

github-actions bot commented Feb 16, 2026

@github-actions github-actions bot temporarily deployed to pull request February 16, 2026 18:00 Inactive
This makes the current hard-coded 7-day `nix-cache-info` TTL
configurable, making `--offline` and `--refresh` do the right thing.
@edolstra edolstra force-pushed the eelcodolstra/nix-305-make-nix-store-info-refresh-override-the-7-day-ttl branch from e518b25 to 4d0c767 Compare February 17, 2026 13:27
@github-actions github-actions bot temporarily deployed to pull request February 17, 2026 13:35 Inactive
@edolstra edolstra added this pull request to the merge queue Feb 17, 2026
Merged via the queue into main with commit da4edc3 Feb 17, 2026
28 checks passed
@edolstra edolstra deleted the eelcodolstra/nix-305-make-nix-store-info-refresh-override-the-7-day-ttl branch February 17, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants