8787be42c8d9
edit: add --dir flag to open config directory instead of file
- time
- 2026-06-15 12:27 UTC · 3 months ago
- machine
- koh2
- agent
- claude-opus-4-8
- session
- murazaki feedback fixes
- parent
- 2f0d457a97ba
↓ nina-8787be42.tar.gzatlas at this save
files changed4 files
src/commands.zig+13 −3src/exec.zig+7 −0src/main.zig+3 −0src/output.zig+1 −0src/commands.zig+13 −3
@@ -837,9 +837,19 @@837837 }838838 839839 pub fn edit(ctx: Ctx) !void {840- const hardware = ctx.args.len > 0 and std.mem.eql(u8, ctx.args[0], "hardware");841- const filename = if (hardware) "hardware-configuration.nix" else "configuration.nix";842- const path = try std.fmt.allocPrint(ctx.gpa, "{s}/{s}", .{ ctx.machine.config_path, filename });840+ // --dir opens the whole config directory (for editors that work better with841+ // a folder open), as root so root-owned config trees like /etc/nixos work.842+ var open_dir = false;843+ for (ctx.args) |arg| {844+ if (std.mem.eql(u8, arg, "--dir")) open_dir = true;845+ }846+ if (open_dir) {847+ output.editOpen(ctx.machine.config_path, ctx.cfg.editor);848+ _ = try exec.openEditorSudo(ctx.io, ctx.gpa, ctx.cfg.editor, ctx.machine.config_path);849+ return;850+ }851+852+ const path = try std.fmt.allocPrint(ctx.gpa, "{s}/configuration.nix", .{ctx.machine.config_path});843853 defer ctx.gpa.free(path);844854 output.editOpen(path, ctx.cfg.editor);845855 _ = try exec.openEditor(ctx.io, ctx.gpa, ctx.cfg.editor, path, null);src/exec.zig+7 −0
@@ -1386,6 +1386,13 @@13861386 return stream(io, &types.Machine{}, gpa, &.{ editor, path });13871387 }13881388 1389+// Open a config directory as root with `sudo -E <editor> <path>` — `-E`1390+// preserves the user's environment (PATH, TERM, EDITOR config) so the editor1391+// behaves the same as it does unprivileged. Used by `nina edit --dir`.1392+pub fn openEditorSudo(io: std.Io, gpa: std.mem.Allocator, editor: []const u8, path: []const u8) !u8 {1393+ return stream(io, &types.Machine{}, gpa, &.{ "sudo", "-E", editor, path });1394+}1395+13891396 pub fn diffClosures(io: std.Io, machine: *const types.Machine, gpa: std.mem.Allocator, a: u32, b: u32) !u8 {13901397 const a_str = try std.fmt.allocPrint(gpa, "/nix/var/nix/profiles/system-{d}-link", .{a});13911398 defer gpa.free(a_str);src/main.zig+3 −0
@@ -294,6 +294,9 @@294294 } else if (std.mem.eql(u8, a, "--switch")) {295295 // --switch flag for `home init` (activate after init)296296 try rest.append(arena, "--switch");297+ } else if (std.mem.eql(u8, a, "--dir")) {298+ // --dir flag for `nina edit` (open the config directory)299+ try rest.append(arena, "--dir");297300 } else if (a.len > 0 and a[0] != '-') {298301 try rest.append(arena, a);299302 }src/output.zig+1 −0
@@ -936,6 +936,7 @@936936 .{ "try <pkg>", "test without installing" },937937 .{ "list", "show installed packages" },938938 .{ "edit", "open configuration.nix" },939+ .{ "edit --dir", "open config directory" },939940 .{ "check", "validate config" },940941 .{ "diff", "changes between generations" },941942 .{ "status", "machine health" },