Skip to content

Commit e4c507d

Browse files
committed
feat: default state-dir to /var/lib/cocoon-macos (mirror cocoon's /var/lib/cocoon)
Was ~/.cocoon-macos; now /var/lib/cocoon-macos so a system-installed binary (/usr/bin/cocoon-macos, run as root for KVM/netns/qemu-nbd) keeps VM state, the cloudimg store and shared firmware in the canonical system location, parallel to cocoon. --state-dir and $COCOON_MACOS_HOME still override.
1 parent 9392a33 commit e4c507d

7 files changed

Lines changed: 9 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ disk image to ghcr; a thin Go CLI clones that image and boots VMs from it.
3838
```bash
3939
go build -o cocoon-macos .
4040

41-
# pull the golden qcow2 from ghcr into the local store (cocoon cloudimg; ~/.cocoon-macos)
41+
# pull the golden qcow2 from ghcr into the local store (cocoon cloudimg; /var/lib/cocoon-macos)
4242
cocoon-macos image pull ghcr.io/cocoonstack/cocoon-macos/tahoe:26
4343
cocoon-macos image list # also: inspect, rm
4444

@@ -72,7 +72,7 @@ cocoon-macos vm clone m1 -n m2 --ssh-port 2223 --random-smbios
7272
`vm run` does: `qemu-img create -b <golden> overlay.qcow2` (instant CoW clone) → copy a
7373
per-VM `OVMF_VARS` → launch `qemu-system-x86_64` (validated OSX-KVM recipe in `qemu/launch.go`:
7474
Skylake-Client CPU spoofing GenuineIntel + `isa-applesmc` OSK + OVMF + OpenCore + the macOS
75-
qcow2) daemonized, recording state under `$COCOON_MACOS_HOME` (default `~/.cocoon-macos`).
75+
qcow2) daemonized, recording state under `--state-dir` / `$COCOON_MACOS_HOME` (default `/var/lib/cocoon-macos`, mirroring cocoon's `/var/lib/cocoon`).
7676

7777
With `--random-smbios`, `create` also copies OpenCore per-VM and injects a generated identity
7878
into its `config.plist` `PlatformInfo/Generic` (via `qemu-nbd` mount); the model stays `iMac19,1`

cmd/firmware/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Actions interface {
1212
// Command builds the `firmware` subcommand tree.
1313
func Command(h Actions) *cobra.Command {
1414
fwCmd := &cobra.Command{Use: "firmware", Short: "Manage shared OpenCore/OVMF firmware under <state-dir>/firmware"}
15-
fwCmd.PersistentFlags().String("state-dir", "", "VM state root (default $COCOON_MACOS_HOME or ~/.cocoon-macos)")
15+
fwCmd.PersistentFlags().String("state-dir", "", "VM state root (default $COCOON_MACOS_HOME or /var/lib/cocoon-macos)")
1616

1717
installCmd := &cobra.Command{
1818
Use: "install",

cmd/firmware/handler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ func stateDir(cmd *cobra.Command) string {
3131
if d := os.Getenv("COCOON_MACOS_HOME"); d != "" {
3232
return d
3333
}
34-
home, _ := os.UserHomeDir()
35-
return filepath.Join(home, ".cocoon-macos")
34+
return "/var/lib/cocoon-macos" // mirrors cocoon's /var/lib/cocoon
3635
}
3736

3837
func dir(cmd *cobra.Command) string { return filepath.Join(stateDir(cmd), "firmware") }

cmd/image/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Actions interface {
1313
// Command builds the `image` subcommand tree against the given handler.
1414
func Command(h Actions) *cobra.Command {
1515
imageCmd := &cobra.Command{Use: "image", Short: "Manage macOS disk images (reuses cocoon's cloudimg store)"}
16-
imageCmd.PersistentFlags().String("state-dir", "", "image/VM state root (default $COCOON_MACOS_HOME or ~/.cocoon-macos)")
16+
imageCmd.PersistentFlags().String("state-dir", "", "image/VM state root (default $COCOON_MACOS_HOME or /var/lib/cocoon-macos)")
1717

1818
pull := &cobra.Command{
1919
Use: "pull REF",

cmd/image/handler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ func stateDir(cmd *cobra.Command) string {
3030
if d := os.Getenv("COCOON_MACOS_HOME"); d != "" {
3131
return d
3232
}
33-
home, _ := os.UserHomeDir()
34-
return filepath.Join(home, ".cocoon-macos")
33+
return "/var/lib/cocoon-macos" // mirrors cocoon's /var/lib/cocoon
3534
}
3635

3736
func (h *Handler) store(cmd *cobra.Command) (context.Context, *cloudimg.CloudImg, error) {

cmd/vm/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Actions interface {
2424
func Command(h Actions) *cobra.Command {
2525
vmCmd := &cobra.Command{Use: "vm", Short: "Manage macOS VMs"}
2626
// state-dir applies to every subcommand (locating VM records), so make it persistent
27-
vmCmd.PersistentFlags().String("state-dir", "", "VM state root (default $COCOON_MACOS_HOME or ~/.cocoon-macos)")
27+
vmCmd.PersistentFlags().String("state-dir", "", "VM state root (default $COCOON_MACOS_HOME or /var/lib/cocoon-macos)")
2828

2929
createCmd := &cobra.Command{
3030
Use: "create [flags] IMAGE",

cmd/vm/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
const (
2727
qemuBinary = "qemu-system-x86_64"
2828
stopGracePeriod = 10 * time.Second
29+
defaultStateDir = "/var/lib/cocoon-macos" // mirrors cocoon's /var/lib/cocoon; override via --state-dir or $COCOON_MACOS_HOME
2930
)
3031

3132
// resolveBase returns the immutable base qcow2 for IMAGE: a direct filesystem path (legacy), else
@@ -134,8 +135,7 @@ func stateDir(cmd *cobra.Command) string {
134135
if d := os.Getenv("COCOON_MACOS_HOME"); d != "" {
135136
return d
136137
}
137-
home, _ := os.UserHomeDir()
138-
return filepath.Join(home, ".cocoon-macos")
138+
return defaultStateDir // /var/lib/cocoon-macos, mirroring cocoon's /var/lib/cocoon
139139
}
140140

141141
func vmDir(cmd *cobra.Command, name string) string {

0 commit comments

Comments
 (0)