Skip to content

Commit 4730065

Browse files
committed
chore: refactor repo structure for clarity (#15)
Unify the hosts/ folder naming, clarify hosts/ is only for our own self-managed things, rename pkgs/ -> packages/ with one folder per package, and move package derivations out of nixos/ modules. - Rename hosts/_appliance_iso -> hosts/_appliance-iso so every managed host uses hyphens; follow the rename through the flake attr, Makefile, .gitignore, image modules, and docs. - Clarify in flake.nix and .gitignore that hosts/ holds only the hosts we manage centrally (our machines + the appliance/installer image builds); user-dropped hosts stay gitignored. - Rename pkgs/ -> packages/ with one folder per package (coder, coder-binary, coder-from-source, coderd-provider, terraform-binary, sysbox-runc), each with a default.nix. Move the sysbox-runc vendor tarball alongside its package. - Add nixos/modules/ for the service modules and split the two monolithic, mutually-exclusive k3s files into a shared k3s base plus podman and sysbox add-ons (each mkDefault-enables the base). New options: services.coder-nixos.{k3s,podman,sysbox}.enable. Move tailscale/screenconnect under nixos/modules/ too. - Extract the inline sysbox-ce .deb derivation into packages/sysbox-ce/default.nix. - Delete the unused hosts/qemu-arm64 host. Note on #18: packages/sysbox-runc/sysbox-runc-vendor-0.7.0.tar.gz cannot be gitignored as-is. It is consumed via builtins.path and is a hand-built `go mod vendor` output that cannot be reproduced inside a sandboxed fixed-output derivation, so it is not fetchable from anywhere; gitignoring it would delete it and break the build. Satisfying #18 needs the tarball to become a fetchable release asset (separate change). Validated with `nix flake check` (all configs evaluate) via zsh.
1 parent 6dde981 commit 4730065

36 files changed

Lines changed: 724 additions & 2787 deletions

File tree

‎.gitignore‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ out/
1010
*.qcow2
1111
*.raw
1212

13-
# Let users drop their OWN hosts into hosts/ without git noise: ignore the
14-
# whole hosts/ directory, then un-ignore only the hosts we manage centrally
15-
# (the ones we ship + write to). A user-added hosts/<their-host>/ stays
16-
# untracked; our managed hosts remain version-controlled as usual.
13+
# hosts/ holds ONLY the hosts we manage centrally — our own real machines plus
14+
# the appliance/installer image builds we ship. Ignore the whole hosts/
15+
# directory, then un-ignore each managed host explicitly. A user who drops their
16+
# OWN hosts/<their-host>/ into the repo stays untracked (no git noise); our
17+
# managed hosts remain version-controlled as usual.
1718
hosts/*
1819
!hosts/_appliance-disk/
19-
!hosts/_appliance_iso/
20+
!hosts/_appliance-iso/
2021
!hosts/_installer-iso/
21-
!hosts/coder-thinkcentre/
2222
!hosts/incus-vm/
23-
!hosts/qemu-arm64/
23+
!hosts/coder-thinkcentre/

‎Makefile‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ installer/drv:
126126
installer/drv/%:
127127
$(call box_instantiate,_installer-iso,isoImage,,$*)
128128

129-
# ── appliance/iso — ephemeral appliance ISO (hosts/_appliance_iso) ───────────
129+
# ── appliance/iso — ephemeral appliance ISO (hosts/_appliance-iso) ───────────
130130
appliance/iso:
131-
$(call box_iso,_appliance_iso,isoImageDir,,)
131+
$(call box_iso,_appliance-iso,isoImageDir,,)
132132
appliance/iso/%:
133-
$(call box_iso,_appliance_iso,isoImageDir,,$*)
133+
$(call box_iso,_appliance-iso,isoImageDir,,$*)
134134

135135
# ── appliance/drv — instantiate the appliance ISO derivation (no build) ───────
136136
appliance/drv:
137-
$(call box_instantiate,_appliance_iso,isoImage,,)
137+
$(call box_instantiate,_appliance-iso,isoImage,,)
138138
appliance/drv/%:
139-
$(call box_instantiate,_appliance_iso,isoImage,,$*)
139+
$(call box_instantiate,_appliance-iso,isoImage,,$*)
140140

141141
# ── appliance/qcow2 — persistent disk image (hosts/_appliance-disk) ──────────
142142
appliance/qcow2:

‎README.md‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ NixOS configuration for Coder demo and workshop boxes.
1717

1818
> **Demo box setup**. This repo configures one or more single-purpose physical machines running Coder + k3s as self-contained workshop and demo environments. It is intentionally simple: no HA, no remote state, no cloud provider. Each machine's secrets (IPs, auth keys, passwords) live in a per-host gitignored `hosts/<host>/local.nix` file. Each box runs a Coder server, k3s (single-node), and a set of workspace templates managed by Terraform via the `coderd` provider.
1919
20-
## Machines
21-
22-
| Hostname | Hardware | LAN IP | Tailscale IP | Status |
23-
|---|---|---|---|---|
24-
| `coder-thinkcentre` | Lenovo ThinkCentre M70q Gen 2 | n/a | n/a | active |
25-
2620
## Repo Structure
2721

2822
```
@@ -35,31 +29,42 @@ local.nix.example # template copied to hosts/<host>/local.nix by instal
3529
install.sh # one-shot installer: disko + nixos-install + bake /etc/nixos-repo
3630
nixos/
3731
disko-standard.nix # shared disko config: 1 GB EFI + ZFS root pool on a single disk
38-
tailscale.nix # Tailscale module (auth key, no --ssh flag)
39-
k3s-sysbox.nix # k3s + sysbox-runc runtime class
40-
k3s-podman.nix # k3s + rootless Podman socket
41-
screenconnect.nix # optional ScreenConnect remote access client
32+
modules/ # NixOS service modules (services.coder-nixos.*)
33+
k3s/ # base single-node k3s server
34+
podman/ # k3s + rootless Podman socket runtime (enable one of podman/sysbox)
35+
sysbox/ # k3s + sysbox-runc runtime class
36+
tailscale/ # Tailscale module (auth key, no --ssh flag)
37+
screenconnect/ # optional ScreenConnect remote access client
4238
_images/ # prebuilt-image modules (appliance + installer)
4339
box-turnkey.nix # shared turn-key Coder box (login + Coder bootstrap); all image hosts
4440
base/ # primitives shared by every image
4541
hardware.nix # all-hardware (boot on arbitrary hardware)
4642
iso.nix # ISO mechanics (iso-image.nix, EFI/BIOS/USB bootable, bootloader)
4743
appliance/
48-
iso.nix # appliance ISO module (hosts/_appliance_iso)
44+
iso.nix # appliance ISO module (hosts/_appliance-iso)
4945
installer/
5046
iso.nix # installer ISO module (hosts/_installer-iso)
51-
pkgs/
52-
coder.nix # custom Coder server package
53-
coderd-provider.nix # terraform-provider-coderd package
54-
hosts/
47+
packages/ # one folder per package, each with a default.nix
48+
coder/ # custom Coder server package (binary or from-source selector)
49+
coder-binary/ # prebuilt Coder release binary
50+
coder-from-source/ # Coder built from source (buildGoModule)
51+
coderd-provider/ # terraform-provider-coderd package
52+
terraform-binary/ # prebuilt Terraform release binary (BSL — not in cache.nixos.org)
53+
sysbox-runc/ # sysbox-runc 0.7.0 from source (+ vendored deps tarball)
54+
sysbox-ce/ # sysbox-mgr / sysbox-fs extracted from the CE .deb
55+
hosts/ # ONLY hosts we manage centrally (see .gitignore)
5556
coder-thinkcentre/ # folder name = hostname; default.nix has a header comment with hardware model
5657
default.nix # host module: imports facter/legacy hardware-config + local.nix
5758
hardware-configuration.nix # legacy nixos-generate-config output (fallback)
5859
facter.json # OPTIONAL: nixos-facter hardware report; supersedes hardware-configuration.nix
5960
local.nix # gitignored: admin creds, secrets, SSH users
6061
templates/
6162
nook-android/ # Workspace: build trmnl-nook-simple-touch APK
62-
_appliance_iso/ # `_appliance_iso` host: ephemeral appliance ISO (no disk install)
63+
incus-vm/ # template host config for a box running inside an Incus VM
64+
default.nix # copy to hosts/<hostname>/; imports incus-vm.nix + local.nix
65+
incus-vm.nix # QEMU guest agents, networkd DHCP, headless (no desktop stack)
66+
README.md # Incus VM setup guide
67+
_appliance-iso/ # `_appliance-iso` host: ephemeral appliance ISO (no disk install)
6368
default.nix # imports nixos/_images/appliance/iso.nix (no disko/facter/hardware-config)
6469
_appliance-disk/ # `_appliance-disk` host: persistent qcow2/raw disk image
6570
default.nix # imports disko-standard.nix + nixos/_images/box-turnkey.nix
@@ -81,7 +86,7 @@ is also the hostname, so `nixos-rebuild switch --flake .` auto-selects the
8186
right config on the running box. Adding a new host means creating a host
8287
folder, no flake.nix edit. The installer does this for you.
8388

84-
Hosts whose folder name starts with an underscore (`_appliance_iso`,
89+
Hosts whose folder name starts with an underscore (`_appliance-iso`,
8590
`_appliance-disk`, `_installer-iso`) are image builds, not per-machine installs: they
8691
do **not** get the folder-name hostname and instead inherit the central
8792
default `networking.hostName = "coder-box"` (set in `configuration.nix`).
@@ -141,7 +146,7 @@ These prebuilt images are called **appliances** (the box, prebuilt — no
141146
142147
| Format | Host | State | Status | Build |
143148
|---|---|---|---|---|
144-
| **iso** (live, ephemeral) | `_appliance_iso` | tmpfs overlay — wiped on reboot | verified | `make appliance/iso` |
149+
| **iso** (live, ephemeral) | `_appliance-iso` | tmpfs overlay — wiped on reboot | verified | `make appliance/iso` |
145150
| **qcow2** (persistent disk) | `_appliance-disk` | persists across reboots | ⚠️ untested | `make appliance/qcow2` |
146151
| **raw** (persistent disk) | `_appliance-disk` | persists across reboots | ⚠️ untested | `make appliance/raw` |
147152
@@ -170,11 +175,11 @@ desktop, and admin `admin@coder.com` / `PleaseChangeMe1234`. Coder comes up at
170175
`/etc/motd`). Change these before sharing an image by dropping a gitignored
171176
`hosts/<host>/local.nix` (same shape as `local.nix.example`).
172177

173-
### Appliance ISO (`_appliance_iso`)
178+
### Appliance ISO (`_appliance-iso`)
174179

175180
The appliance root filesystem is the squashfs + tmpfs overlay from nixpkgs'
176181
`iso-image.nix`, so there's no partition to format or mount and **all state is
177-
discarded on reboot**. `hosts/_appliance_iso/default.nix` imports
182+
discarded on reboot**. `hosts/_appliance-iso/default.nix` imports
178183
[`nixos/_images/appliance/iso.nix`](nixos/_images/appliance/iso.nix) (which pulls in `base/iso.nix` + `box-turnkey.nix`) —
179184
**no** `disko-standard.nix`, `hardware-configuration.nix`, or `facter.json`.
180185
The installed-machine `systemd-boot` / EFI-variable settings are forced off; the

‎agents.md‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ it and use `--flake .`) — see the `/etc/nixos` pitfall below.
4444
4545
## Tailscale
4646

47-
Tailscale is managed by `nixos/tailscale.nix`. Auth key is set as `authKey` in `hosts/<host>/local.nix` (gitignored). Get a reusable key from https://login.tailscale.com/admin/settings/keys.
47+
Tailscale is managed by `nixos/modules/tailscale`. Auth key is set as `authKey` in `hosts/<host>/local.nix` (gitignored). Get a reusable key from https://login.tailscale.com/admin/settings/keys.
4848

4949
**IMPORTANT:** Do NOT add `--ssh` to `extraUpFlags` in `hosts/<host>/local.nix`. Tailscale SSH takes over port 22 with browser-based auth, which will lock you out of the machine. Standard OpenSSH on port 22 is used instead.
5050

@@ -198,21 +198,28 @@ sudo k3s kubectl describe pod -n coder-workspaces <pod-name>
198198
local.nix.example # template for hosts/<host>/local.nix
199199
nixos/
200200
disko-standard.nix # shared disko config: UEFI + single-disk layout for new hosts
201-
tailscale.nix # Tailscale module
202-
k3s-sysbox.nix # k3s + sysbox runtime
203-
k3s-podman.nix # k3s + rootless Podman socket
204-
screenconnect.nix # ScreenConnect remote access client
201+
modules/ # NixOS service modules (services.coder-nixos.*)
202+
k3s/ # base single-node k3s server
203+
podman/ # k3s + rootless Podman socket runtime
204+
sysbox/ # k3s + sysbox-runc runtime
205+
tailscale/ # Tailscale module
206+
screenconnect/ # ScreenConnect remote access client
205207
_images/ # prebuilt-image modules (appliance + installer)
206208
box-turnkey.nix # shared turn-key Coder box (login + Coder bootstrap); all image hosts
207209
base/hardware.nix # all-hardware (boot on arbitrary hardware)
208210
base/iso.nix # shared ISO mechanics (iso-image.nix, EFI/BIOS/USB bootable, bootloader)
209-
appliance/iso.nix # appliance ISO module (imported by hosts/_appliance_iso)
211+
appliance/iso.nix # appliance ISO module (imported by hosts/_appliance-iso)
210212
installer/iso.nix # installer ISO module (imported by hosts/_installer-iso)
211-
pkgs/
212-
coder.nix # Coder server package derivation
213-
coderd-provider.nix # terraform-provider-coderd derivation
214-
hosts/
215-
_appliance_iso/ # `_appliance_iso` host: ephemeral appliance ISO; no disko/facter/hardware-config
213+
packages/ # one folder per package, each with a default.nix
214+
coder/ # Coder server package (binary or from-source selector)
215+
coder-binary/ # prebuilt Coder release binary
216+
coder-from-source/ # Coder built from source
217+
coderd-provider/ # terraform-provider-coderd derivation
218+
terraform-binary/ # prebuilt Terraform release binary
219+
sysbox-runc/ # sysbox-runc 0.7.0 from source (+ vendored deps tarball)
220+
sysbox-ce/ # sysbox-mgr / sysbox-fs from the CE .deb
221+
hosts/ # ONLY hosts we manage centrally (see .gitignore)
222+
_appliance-iso/ # `_appliance-iso` host: ephemeral appliance ISO; no disko/facter/hardware-config
216223
# build: make appliance/iso (or appliance/iso/<arch>)
217224
_appliance-disk/ # `_appliance-disk` host: persistent qcow2/raw disk image (disko image builder)
218225
# build: make appliance/qcow2 | make appliance/raw (or .../<arch>)

‎coderd/templates/k3s-podman/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ Workspaces run as Kubernetes pods on k3s. The host's **rootless Podman socket**
3838

3939
## Requirements
4040

41-
Host must have rootless Podman running as the `coder` user and the socket exposed. Enable via `nixos/k3s-podman.nix` in the NixOS configuration.
41+
Host must have rootless Podman running as the `coder` user and the socket exposed. Enable via `services.coder-nixos.podman.enable = true;` (module: `nixos/modules/podman`) in the NixOS configuration.

‎coderd/templates/k3s-sysbox/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ Workspaces run as Kubernetes pods using the **sysbox-runc** runtime, which provi
3737

3838
## Requirements
3939

40-
Host must have sysbox-runc installed and registered as a k3s runtime class. Enable via `nixos/k3s-sysbox.nix` in the NixOS configuration.
40+
Host must have sysbox-runc installed and registered as a k3s runtime class. Enable via `services.coder-nixos.sysbox.enable = true;` (module: `nixos/modules/sysbox`) in the NixOS configuration.

‎configuration.nix‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
{ config, pkgs, lib, ... }:
1616

1717
let
18-
coder = pkgs.callPackage ./pkgs/coder.nix {
18+
coder = pkgs.callPackage ./packages/coder {
1919
channel = "mainline";
2020
};
21-
coderdProvider = pkgs.callPackage ./pkgs/coderd-provider.nix {};
21+
coderdProvider = pkgs.callPackage ./packages/coderd-provider {};
2222

2323
# UID 991 is pinned so the DOCKER_HOST socket path is deterministic.
2424
# NixOS won't change an existing user's UID live, so this must stay 991.
@@ -44,9 +44,11 @@ in
4444
# ./hosts/<host>/ and are auto-discovered by flake.nix from the directory
4545
# listing. This shared config covers what every box has in common.
4646
imports = [
47-
./nixos/k3s-sysbox.nix # single-node k3s + sysbox-runc (isolated Docker per workspace)
48-
./nixos/tailscale.nix # optional Tailscale (enable in hosts/<host>/local.nix)
49-
./nixos/screenconnect.nix # optional ScreenConnect client (enable in hosts/<host>/local.nix)
47+
./nixos/modules/k3s # base single-node k3s server
48+
./nixos/modules/podman # optional: rootless Podman socket runtime (enable one of podman/sysbox)
49+
./nixos/modules/sysbox # optional: sysbox-runc runtime (isolated Docker per workspace)
50+
./nixos/modules/tailscale # optional Tailscale (enable in hosts/<host>/local.nix)
51+
./nixos/modules/screenconnect # optional ScreenConnect client (enable in hosts/<host>/local.nix)
5052
];
5153

5254
# ── NixOS option: SSH key sync ─────────────────────────────────────────────
@@ -89,7 +91,7 @@ in
8991
# systemPackages, the template-deploy scripts) picks it up. Works on arm64 too.
9092
nixpkgs.overlays = [
9193
(final: prev: {
92-
terraform = final.callPackage ./pkgs/terraform-binary.nix {};
94+
terraform = final.callPackage ./packages/terraform-binary {};
9395
})
9496
];
9597

@@ -154,7 +156,7 @@ in
154156
# Central default hostname. Install hosts override this: flake.nix's mkHost
155157
# injects `networking.hostName = lib.mkDefault <folder-name>` for every
156158
# non-underscore host (so coder-thinkcentre stays coder-thinkcentre, etc.).
157-
# Underscore-prefixed image/appliance hosts (_appliance_iso, _appliance-disk)
159+
# Underscore-prefixed image/appliance hosts (_appliance-iso, _appliance-disk)
158160
# get no injection and so inherit "coder-box".
159161
#
160162
# Priority 1250 (mkOverride) is deliberately BETWEEN mkDefault (1000) and
@@ -308,10 +310,11 @@ in
308310
};
309311
boot.kernel.sysctl."user.max_user_namespaces" = 65536;
310312

311-
# k3s-sysbox is the workspace runtime for every shipped template (k3s-*
312-
# pods and the docker-CLI sandbox). Enable by default so a fresh install
313-
# actually has k3s running; hosts can opt out from their local.nix.
314-
services.coder-nixos.k3s-sysbox.enable = lib.mkDefault true;
313+
# sysbox is the workspace runtime for every shipped template (k3s-* pods and
314+
# the docker-CLI sandbox). It pulls in the base k3s server. Enable by default
315+
# so a fresh install actually has k3s running; hosts can opt out from their
316+
# local.nix.
317+
services.coder-nixos.sysbox.enable = lib.mkDefault true;
315318

316319
# ── Coder user ────────────────────────────────────────────────────────────
317320
# UID 991 is below 1000 so isSystemUser is required (isNormalUser rejects it).

‎flake.nix‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
systems = [ "x86_64-linux" "aarch64-linux" ];
3737
forAllSystems = lib.genAttrs systems;
3838

39-
# Each subdirectory of ./hosts that contains a default.nix becomes a
40-
# nixosConfigurations entry. For install hosts the folder name IS the
41-
# hostname, so `nixos-rebuild switch --flake .` auto-selects the right
39+
# ./hosts holds ONLY the hosts we manage centrally — our own real machines
40+
# plus the appliance/installer image builds we ship (see .gitignore, which
41+
# ignores user-dropped hosts). Each subdirectory that contains a default.nix
42+
# becomes a nixosConfigurations entry. For install hosts the folder name IS
43+
# the hostname, so `nixos-rebuild switch --flake .` auto-selects the right
4244
# config on the running box without needing `.#<attr>`. Adding a new host
4345
# means just creating ./hosts/<hostname>/default.nix; no flake.nix edit.
44-
# (Underscore-prefixed folders like _appliance_iso, _appliance-disk, and
46+
# (Underscore-prefixed folders like _appliance-iso, _appliance-disk, and
4547
# _installer-iso are image builds that skip the folder-name hostname; see
4648
# mkHost below.)
4749
hostNames = lib.attrNames (lib.filterAttrs
@@ -64,7 +66,7 @@
6466
]
6567
# Install hosts use their folder name as the hostname so
6668
# `nixos-rebuild switch --flake .` auto-selects the right config on the
67-
# running box. Underscore-prefixed folders (e.g. _appliance_iso,
69+
# running box. Underscore-prefixed folders (e.g. _appliance-iso,
6870
# _appliance-disk) are image/appliance builds whose names aren't valid
6971
# hostnames and aren't installed per-machine; they fall through to the
7072
# central default (networking.hostName = "coder-box" in

‎hosts/_appliance-disk/default.nix‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Folder name = nixosConfigurations attribute (see flake.nix host
44
# auto-discovery), so this host is exposed as `nixosConfigurations._appliance-disk`.
5-
# Unlike the appliance ISO (hosts/_appliance_iso), this builds a *persistent* disk
5+
# Unlike the appliance ISO (hosts/_appliance-iso), this builds a *persistent* disk
66
# image (qcow2 or raw) using disko's image builder: it carries the real on-disk
77
# GPT layout (1 GB ESP + ZFS root pool from nixos/disko-standard.nix) and state
88
# survives reboots, exactly like a machine you ran install.sh on.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Live "Box" ISO appliance host — "it's just The Box™", not an installer.
22
#
33
# Folder name = nixosConfigurations attribute (see flake.nix host
4-
# auto-discovery), so this host is exposed as `nixosConfigurations._appliance_iso`.
4+
# auto-discovery), so this host is exposed as `nixosConfigurations._appliance-iso`.
55
# It's normally built via the Makefile rather than by attribute:
66
#
77
# make appliance/iso # → out/appliance-iso/iso/coder-box-appliance-*.iso
88
# # equivalently:
9-
# nix build .#nixosConfigurations._appliance_iso.config.system.build.isoImage
9+
# nix build .#nixosConfigurations._appliance-iso.config.system.build.isoImage
1010
#
11-
# Unlike the install hosts (coder-thinkcentre, qemu-arm64), this host does NOT
11+
# Unlike normal install hosts (hosts/<hostname>/), this host does NOT
1212
# import nixos/disko-standard.nix, hardware-configuration.nix, or facter.json:
1313
# the appliance root filesystem is the squashfs + tmpfs overlay provided by
1414
# nixos/_images/appliance/iso.nix. All of the appliance-ISO wiring lives there.

0 commit comments

Comments
 (0)