xonecas.io
56101
Df

dotfiles / commit 91240f5

feat: dot-compose for multiple profiles

Maybe now I'll stop making a mess of things.

xonecas2026-10-13 91240f591d71d1cfcd9eced3df81a1546f3c3b66 parent 87e8b89

19 files changed

.gitignore+3−0
@@ -0,0 +1,3 @@
1+dot-compose/.zig-cache/
2+dot-compose/zig-out/
3+values/secrets.json
README.md+10−14
@@ -1,24 +1,20 @@
11 # Dotfiles
22
3-Personal configuration files for my development environment.
3+Personal configuration files for my development environment, rendered with [`dot-compose`](./dot-compose).
44
5-Each folder is a config. Symlink it to the path the tool already discovers.
5+## Layout
66
7-## Contents
8-
9-- `agents/` — Agents → `~/.agents`
10-- `bash/` — Bash → `~/.bashrc`
11-- `ghostty/` — Ghostty → `~/.config/ghostty/config`
12-- `kitty/` — Kitty → `~/.config/kitty`
13-- `mini-coding-agent/` — mini-coding-agent → `~/.config/mini-coding-agent`
14-- `nvim/` — Neovim → `~/.config/nvim`
7+- `tmpl/` mirrors `$HOME`. `tmpl/.bashrc` renders to `~/.bashrc`.
8+- `values/` holds one JSON file per machine/profile, e.g. `values/kanagawa-arch-dev.json`.
9+- Templates fill machine-specific slots with `{{ key }}` / `{{ nested.key }}`;
10+ everything else is copied verbatim.
1511
1612 ## Usage
1713
14+Render one file with:
15+
1816 ```sh
19-git clone git@github.com:sacenox/dotfiles.git ~/src/dotfiles
17+dot-compose --tmpl tmpl/.bashrc --values values/kanagawa-arch-dev.json
2018 ```
2119
22-Then symlink your desired configs to their respective place (some in `~/.config`, others in `~`).
23-
24-Review each directory before using, as these files are tailored to my personal workflow.
20+Review each file before applying, as these are tailored to my personal workflow.
dot-compose/build.zig+22−0
@@ -0,0 +1,22 @@
1+const std = @import("std");
2+
3+pub fn build(b: *std.Build) void {
4+ const target = b.standardTargetOptions(.{});
5+ const optimize = b.standardOptimizeOption(.{});
6+
7+ const exe = b.addExecutable(.{
8+ .name = "dot-compose",
9+ .root_module = b.createModule(.{
10+ .root_source_file = b.path("src/main.zig"),
11+ .target = target,
12+ .optimize = optimize,
13+ }),
14+ });
15+ b.installArtifact(exe);
16+
17+ const run = b.step("run", "Run dot-compose");
18+ const run_cmd = b.addRunArtifact(exe);
19+ run.dependOn(&run_cmd.step);
20+ run_cmd.step.dependOn(b.getInstallStep());
21+ if (b.args) |args| run_cmd.addArgs(args);
22+}
dot-compose/build.zig.zon+11−0
@@ -0,0 +1,11 @@
1+.{
2+ .name = .dot_compose,
3+ .version = "0.1.0",
4+ .fingerprint = 0xb90fb37088be8f54,
5+ .minimum_zig_version = "0.16.0",
6+ .paths = .{
7+ "build.zig",
8+ "build.zig.zon",
9+ "src",
10+ },
11+}
dot-compose/dot-compose.md+38−0
@@ -0,0 +1,38 @@
1+# Dot Compose
2+
3+A simple CLI to manage dotfiles based on existing template snippets and the user values.
4+
5+Concept initial setup:
6+
7+```sh
8+$ ./dot-compose --skill
9+# Agent instructions to parse existing dotfiles/values into templates and value files
10+...
11+```
12+The user can use that cli path to prompt an LLM/Agent to create their initial templates/values.
13+
14+Concept usage:
15+
16+```sh
17+$ ./dot-compose --tmpl ./tmpl/nvim/lua.init --values ./values/kanagawa-and-lilex-font.json
18+$ cat ~/.config/nvim/init.lua
19+# dot-compose generated init.lua
20+vim.cmd.colorscheme('kanagawa-dragon')
21+```
22+
23+Basically the typical developer dotfiles repo becomes the templates, and the values a json file with them so
24+we can render the template.
25+
26+What does this solve? See `../dotfiles` for how i've been doing dotfile management. My mac setup conflicts with my linux setup.
27+And my vps has a completly different set. I'd like to make the templates from that dotfiles, then configure values for mac, linux, vps, etc...
28+
29+So I can quickly apply/edit configs. For example, my mac uses ghostty with iosevka font and tokyo night themes acrross apps. But my linux setup uses
30+kitty and kanagawa themes and lilax font. My vps uses zellij but neither of the other ones uses it.
31+
32+Another pattern to notice from my dotfiles, is how I use a ~/.keys.json that is not committed to load bash env vars. The machine specific config removes
33+the need for this hack, and I can just set these in a special values json (./values/secrets.json gitignored), where I can keep secrets, safe outside of git.
34+
35+## Tech
36+
37+- zig 0.16.x
38+- memory efficient, fast.
dot-compose/src/main.zig+197−0
@@ -0,0 +1,197 @@
1+const std = @import("std");
2+const Io = std.Io;
3+const Value = std.json.Value;
4+
5+const skill =
6+ \\dot-compose renders dotfile templates with machine-specific values.
7+ \\
8+ \\Layout:
9+ \\ tmpl/ mirrors $HOME. tmpl/.config/nvim/init.lua renders to ~/.config/nvim/init.lua
10+ \\ values/ one JSON file per machine/profile, e.g. values/mac.json
11+ \\
12+ \\Template syntax:
13+ \\ {{ key }} insert a value from the JSON file
14+ \\ {{ nested.key }} walk into nested JSON objects with dots
15+ \\ Everything else is copied verbatim.
16+ \\
17+ \\Values may be strings, numbers or booleans. null renders as empty text.
18+ \\
19+ \\Your task, given an existing dotfiles tree:
20+ \\ 1. Move each config file to tmpl/<its path relative to $HOME>.
21+ \\ 2. Replace every machine-specific literal with a {{ }} slot.
22+ \\ Machine-specific means it differs across machines: fonts, themes,
23+ \\ usernames, hosts, paths, secrets, tools present on only some machines.
24+ \\ 3. Collect those literals into values/<profile>.json. Group related keys
25+ \\ in nested objects, e.g. {"font": {"family": "Lilex Nerd Font Mono"}}.
26+ \\ 4. Put secrets in values/secrets.json and gitignore it.
27+ \\ 5. Leave anything identical on every machine as plain text.
28+ \\
29+;
30+
31+pub fn main(init: std.process.Init) !void {
32+ run(init) catch |e| {
33+ if (e == error.Message) std.process.exit(1);
34+ return e;
35+ };
36+}
37+
38+fn run(init: std.process.Init) !void {
39+ const arena = init.arena.allocator();
40+ const io = init.io;
41+ const args = try init.minimal.args.toSlice(arena);
42+
43+ var tmpl_path: ?[]const u8 = null;
44+ var values_path: ?[]const u8 = null;
45+
46+ var i: usize = 1;
47+ while (i < args.len) : (i += 1) {
48+ const a = args[i];
49+ if (std.mem.eql(u8, a, "--skill")) return stdout(io, skill);
50+ if (std.mem.eql(u8, a, "--tmpl")) {
51+ i += 1;
52+ tmpl_path = try arg(args, i, "--tmpl");
53+ } else if (std.mem.eql(u8, a, "--values")) {
54+ i += 1;
55+ values_path = try arg(args, i, "--values");
56+ } else {
57+ return fail("unknown argument: {s}", .{a});
58+ }
59+ }
60+
61+ const tmpl = tmpl_path orelse return fail("missing --tmpl", .{});
62+ const values = values_path orelse return fail("missing --values", .{});
63+
64+ const home = init.environ_map.get("HOME") orelse return fail("HOME is not set", .{});
65+
66+ const source = Io.Dir.cwd().readFileAlloc(io, tmpl, arena, .unlimited) catch |e|
67+ return fail("cannot read template {s}: {t}", .{ tmpl, e });
68+ const values_json = Io.Dir.cwd().readFileAlloc(io, values, arena, .unlimited) catch |e|
69+ return fail("cannot read values {s}: {t}", .{ values, e });
70+
71+ var parsed = std.json.parseFromSliceLeaky(Value, arena, values_json, .{}) catch |e|
72+ return fail("cannot parse {s}: {t}", .{ values, e });
73+
74+ // Merge a sibling `secrets.json`, if present, so templates can use secret keys directly.
75+ if (secretsPath(arena, values)) |secrets_path| {
76+ if (Io.Dir.cwd().readFileAlloc(io, secrets_path, arena, .unlimited) catch null) |secrets_json| {
77+ const secrets = std.json.parseFromSliceLeaky(Value, arena, secrets_json, .{}) catch |e|
78+ return fail("cannot parse {s}: {t}", .{ secrets_path, e });
79+ parsed = try merge(arena, parsed, secrets);
80+ }
81+ }
82+
83+ const rendered = try render(arena, source, parsed);
84+
85+ const rel = tmplRelPath(arena, tmpl) catch
86+ return fail("template path must live under a 'tmpl' directory: {s}", .{tmpl});
87+ const dest = try std.fs.path.join(arena, &.{ home, rel });
88+
89+ var af = Io.Dir.cwd().createFileAtomic(io, dest, .{ .make_path = true, .replace = true }) catch |e|
90+ return fail("cannot create {s}: {t}", .{ dest, e });
91+ defer af.deinit(io);
92+ try af.file.writeStreamingAll(io, rendered);
93+ try af.replace(io);
94+}
95+
96+fn arg(args: []const []const u8, i: usize, flag: []const u8) ![]const u8 {
97+ if (i >= args.len) return fail("{s} needs a path", .{flag});
98+ return args[i];
99+}
100+
101+// Everything after the `tmpl` path component, relative to $HOME.
102+fn tmplRelPath(arena: std.mem.Allocator, tmpl: []const u8) ![]const u8 {
103+ var it = std.mem.tokenizeScalar(u8, tmpl, '/');
104+ var found = false;
105+ var out: std.ArrayList(u8) = .empty;
106+ while (it.next()) |part| {
107+ if (!found) {
108+ found = std.mem.eql(u8, part, "tmpl");
109+ continue;
110+ }
111+ if (out.items.len != 0) try out.append(arena, '/');
112+ try out.appendSlice(arena, part);
113+ }
114+ if (!found or out.items.len == 0) return error.NotATemplate;
115+ return out.items;
116+}
117+
118+// Path to a sibling `secrets.json` next to the values file, or null when not wanted.
119+fn secretsPath(arena: std.mem.Allocator, values: []const u8) ?[]const u8 {
120+ if (std.mem.eql(u8, std.fs.path.basename(values), "secrets.json")) return null;
121+ const dir = std.fs.path.dirname(values) orelse ".";
122+ return std.fs.path.join(arena, &.{ dir, "secrets.json" }) catch null;
123+}
124+
125+// Shallow merge of two JSON objects; `over` wins on key collisions.
126+fn merge(arena: std.mem.Allocator, base: Value, over: Value) !Value {
127+ const base_obj = switch (base) {
128+ .object => |o| o,
129+ else => return base,
130+ };
131+ const over_obj = switch (over) {
132+ .object => |o| o,
133+ else => return base,
134+ };
135+ var map: std.json.ObjectMap = .empty;
136+ var it = base_obj.iterator();
137+ while (it.next()) |e| try map.put(arena, e.key_ptr.*, e.value_ptr.*);
138+ var it2 = over_obj.iterator();
139+ while (it2.next()) |e| try map.put(arena, e.key_ptr.*, e.value_ptr.*);
140+ return .{ .object = map };
141+}
142+
143+fn render(arena: std.mem.Allocator, tmpl: []const u8, root: Value) ![]const u8 {
144+ var out: std.ArrayList(u8) = .empty;
145+ var i: usize = 0;
146+ while (i < tmpl.len) {
147+ if (tmpl[i] == '{' and i + 1 < tmpl.len and tmpl[i + 1] == '{') {
148+ const close = std.mem.indexOfPos(u8, tmpl, i + 2, "}}") orelse
149+ return fail("unclosed '{{{{' at byte {d}", .{i});
150+ const key = std.mem.trim(u8, tmpl[i + 2 .. close], " \t\r\n");
151+ const v = lookup(root, key) orelse
152+ return fail("no value for '{s}'", .{key});
153+ try emit(arena, &out, key, v);
154+ i = close + 2;
155+ } else {
156+ try out.append(arena, tmpl[i]);
157+ i += 1;
158+ }
159+ }
160+ return out.items;
161+}
162+
163+fn lookup(root: Value, key: []const u8) ?Value {
164+ if (key.len == 0) return null;
165+ var cur = root;
166+ var it = std.mem.splitScalar(u8, key, '.');
167+ while (it.next()) |part| {
168+ cur = switch (cur) {
169+ .object => |o| o.get(part) orelse return null,
170+ else => return null,
171+ };
172+ }
173+ return cur;
174+}
175+
176+fn emit(arena: std.mem.Allocator, out: *std.ArrayList(u8), key: []const u8, v: Value) !void {
177+ switch (v) {
178+ .string => |s| try out.appendSlice(arena, s),
179+ .integer => |n| try out.print(arena, "{d}", .{n}),
180+ .float => |n| try out.print(arena, "{d}", .{n}),
181+ .bool => |b| try out.appendSlice(arena, if (b) "true" else "false"),
182+ .null => {},
183+ else => return fail("value for '{s}' is not a scalar", .{key}),
184+ }
185+}
186+
187+fn stdout(io: Io, text: []const u8) void {
188+ var buf: [4096]u8 = undefined;
189+ var w: Io.File.Writer = .init(.stdout(), io, &buf);
190+ w.interface.writeAll(text) catch {};
191+ w.interface.flush() catch {};
192+}
193+
194+fn fail(comptime fmt: []const u8, args: anytype) error{Message} {
195+ std.debug.print("dot-compose: " ++ fmt ++ "\n", args);
196+ return error.Message;
197+}
ghostty/config+0−3
@@ -1,3 +0,0 @@
1-font-family = Lilex Nerd Font Mono
2-font-size = 12
3-theme = Oxocarbon
mini-coding-agent/config.json+0−14
@@ -1,14 +0,0 @@
1-{
2- "theme": "kanagawa",
3- "provider": "opencode-go",
4- "model": "deepseek-v4.1-flash",
5- "thinkingEffort": "low",
6- "tools": [
7- "edit",
8- "read",
9- "bash"
10- ],
11- "snapshotIgnoreDirs": [
12- ".git"
13- ]
14-}
tmpl/.agents/AGENTS.md+1−2
@@ -11,8 +11,7 @@ Follow all instructions as closely as possible. The instructions are not suggest
1111
1212 These are available to you and already authenticated. Do not read auth keys.
1313
14-- Use `gh` for Github operations.
15-- Use `firecrawl` for web search and web content (scraping).
14+{{ env.tools }}
1615
1716 > You don't have sudo, it's intended. The user does, he can run commands. Never try to bypass or escalate your privileges.
1817
tmpl/.bashrc+8−7
@@ -17,15 +17,16 @@ alias gpo='git push origin'
1717
1818 alias nv='nvim'
1919
20-alias sto='cd /mnt/storage'
21-alias rep='cd /mnt/storage/repos'
20+alias sto='cd {{ paths.storage }}'
21+alias rep='cd {{ paths.repos }}'
2222
23-alias vps='ssh sean@xonecas.io'
23+alias vps='ssh {{ vps.user }}@{{ vps.host }}'
2424
25-# Credentials loaded from ~/.keys.json
26-if [ -f "$HOME/.keys.json" ]; then
27- eval "$(jq -r 'to_entries[] | "export \(.key)=\(.value | @sh)"' "$HOME/.keys.json")"
28-fi
25+export FIRECRAWL_API_KEY='{{ FIRECRAWL_API_KEY }}'
26+export HOSTINGER_API_KEY='{{ HOSTINGER_API_KEY }}'
27+export OPENCODE_API_KEY='{{ OPENCODE_API_KEY }}'
28+export PORKBUN_API_KEY='{{ PORKBUN_API_KEY }}'
29+export PORKBUN_SECRET_API_KEY='{{ PORKBUN_SECRET_API_KEY }}'
2930
3031 greet() {
3132 local cows=(
tmpl/.config/kitty/kanagawa_dragon.conf+0−0
tmpl/.config/kitty/kitty.conf+3−3
@@ -3,14 +3,14 @@ map ctrl+shift+enter launch --location=vsplit
33
44 enable_audio_bell no
55
6-font_family Lilex Nerd Font Mono
6+font_family {{ font.family }}
77 bold_font auto
88 italic_font auto
99 bold_italic_font auto
10-font_size 12.0
10+font_size {{ font.size }}
1111
1212 disable_ligatures always
1313
14-include kanagawa_dragon.conf
14+include {{ kitty.theme }}
1515 #include oxocarbon_dark.conf
1616 # include tokyo_night.conf
tmpl/.config/kitty/oxocarbon_dark.conf+0−0
tmpl/.config/kitty/tokyo_night.conf+0−0
tmpl/.config/mini-coding-agent/config.json+14−0
@@ -0,0 +1,14 @@
1+{
2+ "theme": "{{ agent.theme }}",
3+ "provider": "{{ agent.provider }}",
4+ "model": "{{ agent.model }}",
5+ "thinkingEffort": "{{ agent.thinkingEffort }}",
6+ "tools": [
7+ "edit",
8+ "read",
9+ "bash"
10+ ],
11+ "snapshotIgnoreDirs": [
12+ ".git"
13+ ]
14+}
tmpl/.config/nvim/.luarc.json+0−0
tmpl/.config/nvim/init.lua+1−1
@@ -277,5 +277,5 @@ vim.api.nvim_create_user_command('Q', 'q', {})
277277 vim.api.nvim_create_user_command('W', 'w', {})
278278
279279 -- Set a nice theme?
280-vim.cmd.colorscheme('kanagawa-dragon')
280+vim.cmd.colorscheme('{{ nvim.theme }}')
281281 -- vim.cmd.colorscheme('oxocarbon')
tmpl/.config/nvim/lazy-lock.json+0−0
values/kanagawa-arch-dev.json+14−0
@@ -0,0 +1,14 @@
1+{
2+ "font": { "family": "Lilex Nerd Font Mono", "size": 12 },
3+ "env": { "tools": "- Use `gh` for Github operations.\n- Use `firecrawl` for web search and web content (scraping)." },
4+ "paths": { "storage": "/mnt/storage", "repos": "/mnt/storage/repos" },
5+ "vps": { "user": "sean", "host": "xonecas.io" },
6+ "kitty": { "theme": "kanagawa_dragon.conf" },
7+ "nvim": { "theme": "kanagawa-dragon" },
8+ "agent": {
9+ "theme": "kanagawa",
10+ "provider": "opencode-go",
11+ "model": "deepseek-v4.1-flash",
12+ "thinkingEffort": "low"
13+ }
14+}