Skip to content

minnows flow: init - #4

Merged
colemickens merged 9 commits into
mainfrom
colemickens/flow-init2
Jul 30, 2026
Merged

minnows flow: init#4
colemickens merged 9 commits into
mainfrom
colemickens/flow-init2

Conversation

@colemickens

@colemickens colemickens commented Jul 29, 2026

Copy link
Copy Markdown
Member

I recommend reviewing commit-by-commit!

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added a minimal FlakeHub edge cache service for edge deployments.
    • Exposed a new minnowsFlows.default output to make the edge cache deployment available by default.
  • Improvements
    • Routed Nginx error and access logs to syslog via /dev/log.
    • Made Nginx listen directives explicitly configurable and reflected them in the generated configuration.
  • Refactor
    • Modularized edge cache configuration and option wiring to improve maintainability.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d782248a-b58b-4165-9f37-e7b3f2851bf7

📥 Commits

Reviewing files that changed from the base of the PR and between 5e424d8 and a4b14e2.

📒 Files selected for processing (1)
  • modules/configuration.nix

📝 Walkthrough

Walkthrough

Adds a FlakeHub edge-cache Flow with systemd wiring, modular Nginx options and logging, and configurable runtime resources and listen addresses.

Changes

Edge cache service

Layer / File(s) Summary
Cache module options
modules/options.nix, modules/default.nix
Extracts Nginx configuration generation and defines cache, DNS, TLS, filesystem, and listen options.
Nginx logging configuration
modules/configuration.nix
Routes Nginx error and access logs to the local syslog socket while retaining the /log endpoint’s 404 response.
Flow and systemd wiring
flake.nix, flow.nix
Exports the Flow, declares metadata and resources, generates runtime configuration, creates and owns the cache directory, and starts Nginx through the flakehub-edge-cache systemd service.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: cole-h

Sequence Diagram(s)

sequenceDiagram
  participant Flow
  participant Systemd
  participant Nginx
  participant Syslog
  Flow->>Systemd: Start flakehub-edge-cache
  Systemd->>Systemd: Create and own cache directory
  Systemd->>Nginx: Run with generated configuration
  Nginx->>Syslog: Write access and error logs to /dev/log
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is relevant but too generic to describe the new FlakeHub Cache flow and related Nix changes. Use a more specific title such as "minnows flow: add FlakeHub Cache flow".
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch colemickens/flow-init2

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

@colemickens
colemickens force-pushed the colemickens/flow-init2 branch from 7bb25d0 to f24e323 Compare July 29, 2026 22:41
@colemickens
colemickens force-pushed the colemickens/flow-init2 branch from f24e323 to b358ce2 Compare July 29, 2026 22:54
@colemickens
colemickens marked this pull request as ready for review July 29, 2026 22:54

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (6)
flow.nix (3)

58-68: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Stale TODO and dead commented-out option.

Line 93 already resolves sslTrustedCertificate via pkgs.cacert, so this block and its TODO are obsolete — remove them.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@flow.nix` around lines 58 - 68, Remove the obsolete TODO and fully
commented-out sslTrustedCertificate option block near the existing flow
configuration; retain the active sslTrustedCertificate resolution that uses
pkgs.cacert.

118-125: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Drop the sleep 10 / set -x debug scaffolding before this leaves draft.

The unit already declares Wants/After on network-online.target; a fixed sleep adds 10s to every start and still races on slow networks. If nginx is failing to resolve at startup, resolver with per-request resolution (already configured) should cover it. set -x also leaks the full command line into the journal on every start.

Want me to open an issue to track removing this hack?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@flow.nix` around lines 118 - 125, Remove the fixed `sleep 10` delay and `set
-x` tracing from the `startScript` shell script, leaving the existing nginx
execution command and network-online unit dependencies unchanged.

128-135: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Restart = "no" leaves the cache down permanently after any crash.

A pull-through cache that dies takes builds with it until someone notices. Prefer Restart = "on-failure" with a modest RestartSec, unless the intent is to surface failures loudly during bring-up.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@flow.nix` around lines 128 - 135, Update the systemd service configuration in
flakehub-edge-cache’s Service attribute set to restart the cache automatically
after failures: change Restart from "no" to "on-failure" and add a modest
RestartSec delay. Leave the existing ExecStartPre and ExecStart commands
unchanged.
modules/default.nix (1)

26-30: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

tempDirectory on /tmp defeats the rename optimization.

With PrivateTmp = true, /tmp is typically a separate (often tmpfs) mount from cacheDirectory under /var, so nginx must copy each completed NAR across filesystems instead of rename()-ing it into the cache — extra I/O plus tmpfs memory pressure for large NARs. Defaulting the temp dir to a subdirectory of cacheDirectory (or null) avoids this. Note flow.nix already places both under flowContext.stateDir.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/default.nix` around lines 26 - 30, Update the tempDirectory option
default near tempDirectory to avoid /tmp and keep temporary files on the same
filesystem as cacheDirectory: use a subdirectory of cacheDirectory or null,
consistent with the existing flow.nix stateDir placement. Preserve the null
behavior where nginx uses only its cache storage.
modules/options.nix (1)

4-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duration/size regexes are stricter than nginx's own syntax.

nginx accepts compound durations (1h30m), millisecond suffixes (500ms), bare seconds (30), and uppercase size suffixes (10M, 1G). All of these are rejected here, so operators hit an eval error for valid nginx values.

♻️ Suggested loosening
-  nginxDurationType = lib.types.strMatching "^[0-9]+[dhms]$";
-  nginxSizeType = lib.types.strMatching "^[0-9]+[kmg]$";
+  # nginx time: sequence of number+unit pairs, units y M w d h m s ms, bare number = seconds
+  nginxDurationType = lib.types.strMatching "^([0-9]+(ms|[yMwdhms])?)+$";
+  nginxSizeType = lib.types.strMatching "^[0-9]+[kKmMgG]?$";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/options.nix` around lines 4 - 5, Update the nginxDurationType and
nginxSizeType regexes to accept nginx’s valid syntax: compound duration values,
millisecond suffixes, bare numeric seconds, and uppercase size suffixes, while
preserving numeric validation and rejecting malformed values.
modules/configuration.nix (1)

39-47: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the redundant minCacheFree check. minCacheFree is non-nullable in modules/options.nix, so cfg.minCacheFree != null is always true; emit min_free unconditionally or make the option nullable if it should be optional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/configuration.nix` around lines 39 - 47, Update the proxy_cache_path
construction to remove the redundant cfg.minCacheFree != null guard, since
minCacheFree is non-nullable; emit the min_free directive unconditionally while
preserving the existing formatting and other optional directives.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@flow.nix`:
- Around line 87-94: Update the cfg construction in flow.nix to assign the
allocated listenAddrs value to the listen field consumed by
modules/configuration.nix, replacing the unused addr assignment. Preserve the
existing listenAddrs value so the allocated listeningPort is used by nginx.

In `@modules/configuration.nix`:
- Line 31: The nginx access log target in modules/configuration.nix must not be
hardcoded to /var/log/nginx/access.log. Add a configurable cfg.accessLog option
with /dev/stderr as the default and use it in the access_log directive; in
flow.nix lines 111-116, configure that option to a path under
flowContext.stateDir or update preStartScriptRoot to create and assign the
required log directory to the worker user.

---

Nitpick comments:
In `@flow.nix`:
- Around line 58-68: Remove the obsolete TODO and fully commented-out
sslTrustedCertificate option block near the existing flow configuration; retain
the active sslTrustedCertificate resolution that uses pkgs.cacert.
- Around line 118-125: Remove the fixed `sleep 10` delay and `set -x` tracing
from the `startScript` shell script, leaving the existing nginx execution
command and network-online unit dependencies unchanged.
- Around line 128-135: Update the systemd service configuration in
flakehub-edge-cache’s Service attribute set to restart the cache automatically
after failures: change Restart from "no" to "on-failure" and add a modest
RestartSec delay. Leave the existing ExecStartPre and ExecStart commands
unchanged.

In `@modules/configuration.nix`:
- Around line 39-47: Update the proxy_cache_path construction to remove the
redundant cfg.minCacheFree != null guard, since minCacheFree is non-nullable;
emit the min_free directive unconditionally while preserving the existing
formatting and other optional directives.

In `@modules/default.nix`:
- Around line 26-30: Update the tempDirectory option default near tempDirectory
to avoid /tmp and keep temporary files on the same filesystem as cacheDirectory:
use a subdirectory of cacheDirectory or null, consistent with the existing
flow.nix stateDir placement. Preserve the null behavior where nginx uses only
its cache storage.

In `@modules/options.nix`:
- Around line 4-5: Update the nginxDurationType and nginxSizeType regexes to
accept nginx’s valid syntax: compound duration values, millisecond suffixes,
bare numeric seconds, and uppercase size suffixes, while preserving numeric
validation and rejecting malformed values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe0d9af3-4928-40b4-893d-e5ec352e7547

📥 Commits

Reviewing files that changed from the base of the PR and between 92c0e99 and b358ce2.

⛔ Files ignored due to path filters (1)
  • flake.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • flake.nix
  • flow.nix
  • modules/configuration.nix
  • modules/default.nix
  • modules/options.nix

Comment thread flow.nix
Comment thread modules/configuration.nix Outdated
lib.optionalString (cfg.extraLogFields != "") " ${cfg.extraLogFields}"
} upstream_status=$upstream_status upstream_addr=$upstream_addr upstream_connect_time=$upstream_connect_time';

access_log /var/log/nginx/access.log main;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Access log path is provisioned only on the NixOS path. modules/configuration.nix hardcodes /var/log/nginx/access.log, which modules/default.nix satisfies via LogsDirectory = "nginx"; the Flow path provisions no such directory, and nginx refuses to start when it cannot open the access log.

  • modules/configuration.nix#L31-L31: parameterize the access log target (e.g. a cfg.accessLog option defaulting to /dev/stderr) instead of hardcoding the NixOS layout.
  • flow.nix#L111-L116: either set the new option to a path under flowContext.stateDir / journal, or extend preStartScriptRoot to create the log directory owned by the worker user.
📍 Affects 2 files
  • modules/configuration.nix#L31-L31 (this comment)
  • flow.nix#L111-L116
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/configuration.nix` at line 31, The nginx access log target in
modules/configuration.nix must not be hardcoded to /var/log/nginx/access.log.
Add a configurable cfg.accessLog option with /dev/stderr as the default and use
it in the access_log directive; in flow.nix lines 111-116, configure that option
to a path under flowContext.stateDir or update preStartScriptRoot to create and
assign the required log directory to the worker user.

Comment thread modules/configuration.nix Outdated
Comment thread modules/configuration.nix
Documentation implies that sendfile, tcp_nopush, and aio options should
be considered and configured together. Given the introduction of
an alternative local-cache (satellite), I'm opting to punt this
investigation and let nginx defualts prevail.
@colemickens
colemickens merged commit 10089ae into main Jul 30, 2026
7 checks passed
@colemickens
colemickens deleted the colemickens/flow-init2 branch July 30, 2026 21:04
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