Created
October 24, 2026 07:29
-
-
Save ivan/f4d6bd9d3dda5aa57de7c8427a527965 to your computer and use it in GitHub Desktop.
nix-serve-ng: don't flush after every NAR piece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 782cfff08973ded7ea655c58513ebd2c0f428325 Mon Sep 17 00:00:00 2001 | |
| From: Ivan Kozik <ivan@ludios.org> | |
| Date: Sat, 24 Oct 2026 07:24:02 +0000 | |
| Subject: [PATCH] nix-serve-ng: don't flush after every NAR piece | |
| Nix's NAR dumper hands over many tiny pieces per file (names, lengths, | |
| padding), and nix-serve-ng flushed after each one, so Warp sent each as | |
| its own packet. Over a ~190 ms RTT link, small-file-heavy parts of a | |
| NAR then dropped from ~11 MB/s to ~1.4 MB/s, stalling remote Hydra | |
| builders on "Sending inputs" for minutes. | |
| Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> | |
| --- | |
| .../haskell-modules/configuration-nix.nix | 2 ++ | |
| .../nix-serve-ng-stream-nar-unflushed.patch | 34 +++++++++++++++++++ | |
| 2 files changed, 36 insertions(+) | |
| create mode 100644 pkgs/development/haskell-modules/patches/nix-serve-ng-stream-nar-unflushed.patch | |
| diff --git a/pkgs/development/haskell-modules/configuration-nix.nix b/pkgs/development/haskell-modules/configuration-nix.nix | |
| index b108be58aa8a..dbce2c6e151f 100644 | |
| --- a/pkgs/development/haskell-modules/configuration-nix.nix | |
| +++ b/pkgs/development/haskell-modules/configuration-nix.nix | |
| @@ -550,6 +550,8 @@ builtins.intersectAttrs super { | |
| version = "1.1.0-unstable-2026-03-26"; | |
| }) | |
| + (appendPatch ./patches/nix-serve-ng-stream-nar-unflushed.patch) | |
| + | |
| (overrideCabal (old: { | |
| # Doesn't declare boost dependency | |
| pkg-configDepends = (old.pkg-configDepends or [ ]) ++ [ pkgs.boost.dev ]; | |
| diff --git a/pkgs/development/haskell-modules/patches/nix-serve-ng-stream-nar-unflushed.patch b/pkgs/development/haskell-modules/patches/nix-serve-ng-stream-nar-unflushed.patch | |
| new file mode 100644 | |
| index 000000000000..5bb892946010 | |
| --- /dev/null | |
| +++ b/pkgs/development/haskell-modules/patches/nix-serve-ng-stream-nar-unflushed.patch | |
| @@ -0,0 +1,34 @@ | |
| +Model-output: Claude Opus 5.5 | |
| + | |
| +Stop flushing after every piece of a NAR. Nix's dumper hands over tiny | |
| +pieces (names, lengths, padding) for each file, and flushing each one | |
| +makes Warp send it as its own packet. For small-file-heavy NARs over a | |
| +~190 ms RTT link, that cut throughput from ~11 MB/s to ~1.4 MB/s. | |
| + | |
| +diff --git a/src/Main.hs b/src/Main.hs | |
| +index 9a90b69..ed40fd3 100644 | |
| +--- a/src/Main.hs | |
| ++++ b/src/Main.hs | |
| +@@ -250,16 +250,16 @@ makeApplication ApplicationOptions{..} request respond = do | |
| + | |
| + done response | |
| + | |
| +- let streamingBody write flush = do | |
| +- result <- Nix.dumpPath hashPart callback | |
| ++ -- Nix hands over the NAR in many small pieces (names, | |
| ++ -- lengths, padding). Don't flush each one: let Warp fill | |
| ++ -- its send buffer, or high-latency links see a stream of | |
| ++ -- tiny packets. | |
| ++ let streamingBody write _flush = do | |
| ++ result <- Nix.dumpPath hashPart write | |
| + | |
| + case result of | |
| + Left exception -> Exception.throwIO exception | |
| + Right x -> return x | |
| +- where | |
| +- callback builder = do | |
| +- () <- write builder | |
| +- flush | |
| + | |
| + let headers = [ ("Content-Type", "text/plain") ] | |
| + | |
| -- | |
| 2.56.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment