b8edd2a2e22d

store: add nina store optimise (deduplicates store with hard links), accept optimize alias

time
2026-06-15 12:28 UTC · 3 months ago
machine
koh2
agent
claude-opus-4-8
session
murazaki feedback fixes
parent
f1282c9a5b31
3 files src/commands.zig+8 −0src/exec.zig+6 −0src/output.zig+9 −0
src/commands.zig+8 −0
@@ -1699,6 +1699,7 @@16991699     .{ "info", "store size and counts" },17001700     .{ "path <attr>", "store path of a package" },17011701     .{ "gc", "collect garbage" },1702+    .{ "optimise", "deduplicate store paths with hard links" },17021703     .{ "verify", "verify store integrity" },17031704     .{ "repair", "repair corrupted paths" },17041705 };@@ -1707,6 +1708,13 @@17071708     if (ctx.sub.len == 0 or std.mem.eql(u8, ctx.sub, "help")) return output.subcommandHelp("store", &store_help, null);17081709     if (std.mem.eql(u8, ctx.sub, "gc")) {17091710         _ = try exec.storeGc(ctx.io, &ctx.machine, ctx.gpa);1711+        return;1712+    }1713+    // Accept both spellings — optimise (en) and optimize (us).1714+    if (std.mem.eql(u8, ctx.sub, "optimise") or std.mem.eql(u8, ctx.sub, "optimize")) {1715+        output.storeOptimiseStart(ctx.machine.name);1716+        _ = try exec.storeOptimise(ctx.io, &ctx.machine, ctx.gpa);1717+        output.storeOptimiseDone();17101718         return;17111719     }17121720     if (std.mem.eql(u8, ctx.sub, "verify")) {

view file

src/exec.zig+6 −0
@@ -931,6 +931,12 @@931931     return stream(io, machine, gpa, &.{ "nix", "store", "verify", "--all" });932932 }933933 934+// Deduplicate identical store files via hard links — frees space without935+// garbage-collecting any paths.936+pub fn storeOptimise(io: std.Io, machine: *const types.Machine, gpa: std.mem.Allocator) !u8 {937+    return stream(io, machine, gpa, &.{ "nix", "store", "optimise" });938+}939+934940 pub const SystemStatus = struct { size: []u8, age: []u8 };935941 936942 // One read-only pass for `nina status`: the current system's closure size (a

view file

src/output.zig+9 −0
@@ -1278,6 +1278,15 @@12781278     p("{s}verifying store\n", .{hdr()});12791279 }12801280 1281+pub fn storeOptimiseStart(machine: []const u8) void {1282+    p("{s}optimising store  {s}\n", .{ hdr(), machine });1283+    printSubstep("nix store optimise", .{});1284+}1285+1286+pub fn storeOptimiseDone() void {1287+    p("{s}done\n", .{hdr()});1288+}1289+12811290 pub fn storeGcDone(freed: []const u8) void {12821291     p("{s}freed {s}\n", .{ hdr(), freed });12831292 }

view file