aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-25 12:24:39 +0000
committertv <tv@krebsco.de>2026-11-25 12:27:25 +0000
commit39012ddac260255a60bbf99777e9cf1ba9bb219b (patch)
tree26288cb3ce97d62893fae22833a137f1082e7c05
parent312605171f6e3ef59a0f7c0cffc69e98c346a60c (diff)
layers/nix.nix: fc-drop-caches, for 9P's stale caches
9P with cache=loose (the host's store; /nixpkgs with --nixpkgs-cache=loose, which evaluates three times as fast as without) never asks the host again: a file changed on the host keeps its old size and contents in the guest (nix then reads a truncated aliases.nix), and a name looked up before the host had it stays missing, until the guest drops its cached dentries and inodes, which only root can. fc-drop-caches lets anyone: a setuid wrapper for a program that takes no input and only ever writes 2 to drop_caches.
-rw-r--r--layers/nix.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/layers/nix.nix b/layers/nix.nix
index b679539..42d4729 100644
--- a/layers/nix.nix
+++ b/layers/nix.nix
@@ -119,4 +119,30 @@ in
noCheck = true;
options = [ "ro" "x-systemd.automount" "nofail" ];
};
+
+ # 9P with cache=loose (the host's store, and /nixpkgs with
+ # --nixpkgs-cache=loose) never asks the host again: a file changed on
+ # the host keeps its old size and contents in the guest, and a name
+ # looked up before the host had it stays missing, until the guest drops
+ # its cached dentries and inodes, which fc-drop-caches lets anyone do
+ # (setuid; no input, it only ever writes 2 to drop_caches).
+ security.wrappers.fc-drop-caches = {
+ setuid = true;
+ owner = "root";
+ group = "root";
+ source = lib.getExe (pkgs.writeCBin "fc-drop-caches" ''
+ #include <fcntl.h>
+ #include <stdio.h>
+ #include <unistd.h>
+ int main(void) {
+ sync();
+ int fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+ if (fd < 0 || write(fd, "2\n", 2) != 2) {
+ perror("fc-drop-caches: /proc/sys/vm/drop_caches");
+ return 1;
+ }
+ return 0;
+ }
+ '');
+ };
}