monogok

module
v0.0.0-...-2219c39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: BSD-3-Clause

README

monogok

monogok is an opinionated alternative to gokrazy's gok tool, designed for building gokrazy appliance images from within a Go monorepo.

Ideally this monorepo build mode would be added to gok itself (see https://github.com/gokrazy/gokrazy/discussions/361), making this tool unnecessary. Until then, monogok exists as a stopgap.

[!NOTE] This code was largely generated by AI (Claude) based on a human-written specification, with human review and editing. Bugs are likely.

Motivation

The standard gok tool creates a separate Go build directory with its own go.mod for each binary package declared in the appliance config. It then runs go get and go build independently in each of those directories. This works well for standalone projects, but is awkward in monorepo setups where all packages already share a single go.mod and you want them built together as normal module dependencies.

monogok removes that per-package build directory indirection. Instead, it finds the nearest go.mod above the appliance's config.json and builds all declared packages directly from that module root, exactly as go build would for any other package in the module. No separate build directories, no go get, no go.mod migration. If the packages resolve from your module, they build.

Usage

monogok overwrite --full /dev/sdX       # write a full disk image to a device
monogok overwrite --full disk.img \
    --target_storage_bytes 1258291200   # write a full disk image to a file
monogok gendep                          # generate gokrazydeps.go for go mod tidy
monogok update                          # build and deploy over HTTP (not yet implemented)

All subcommands discover the appliance config by walking up from the current directory looking for config.json (or use --config to specify it explicitly), then find the enclosing Go module root by walking up from there looking for go.mod.

monogok overwrite

Builds all packages and writes a full gokrazy disk image. Supports the same partition layout as gok overwrite (GPT + hybrid MBR, FAT32 boot, SquashFS root).

monogok gendep

Generates a gokrazydeps.go file next to config.json:

//go:build ignore

package gokrazydeps

import (
    _ "github.com/gokrazy/gokrazy/cmd/dhcp"
    _ "github.com/gokrazy/gokrazy/cmd/ntp"
    _ "example.com/cmd/myapp"
    // ...all packages from config.json
)

This file exists solely for go mod tidy — the //go:build ignore tag prevents it from being compiled, but the imports ensure all appliance packages and their dependencies are tracked in go.mod/go.sum.

monogok update

Network-based update over HTTP/HTTPS. Not yet implemented.

Key difference from gok

gok monogok
Build directories One per package, each with its own go.mod Single module root
Dependency resolution go get in each build dir Already in go.mod
Module boundary Each package is an independent module build All packages share the enclosing module
Use case Standalone gokrazy projects Monorepos with gokrazy appliance configs

Code origin

This repository contains code duplicated from gokrazy/internal and gokrazy/tools. It does not import gokrazy/internal as a dependency, since that package is not a stable API boundary. Instead, the needed types and logic (FAT32 writer, SquashFS writer, MBR, config types, etc.) are copied into internal/ packages here.

License

BSD 3-Clause, same as gokrazy. See LICENSE.

Directories

Path Synopsis
cmd
monogok command
monogok builds gokrazy images from a monorepo using a single go.mod.
monogok builds gokrazy images from a monorepo using a single go.mod.
internal
build
Package build provides Go build invocation for monogok.
Package build provides Go build invocation for monogok.
config
Package config allows reading gokrazy instance configuration from config.json.
Package config allows reading gokrazy instance configuration from config.json.
deviceconfig
Package deviceconfig contains any device-specific configuration.
Package deviceconfig contains any device-specific configuration.
eeprom
Package eeprom implements the Raspberry Pi EEPROM update file format.
Package eeprom implements the Raspberry Pi EEPROM update file format.
fat
gendep
Package gendep generates a gokrazydeps.go file listing all packages from config.json as blank imports, for the purpose of making `go mod tidy` aware of the gokrazy packages in a monorepo.
Package gendep generates a gokrazydeps.go file listing all packages from config.json as blank imports, for the purpose of making `go mod tidy` aware of the gokrazy packages in a monorepo.
mbr
Package mbr provides a configured version of Sebastian Plotz's minimal stage1-only Linux bootloader, to be written to a Master Boot Record.
Package mbr provides a configured version of Sebastian Plotz's minimal stage1-only Linux bootloader, to be written to a Master Boot Record.
packer
Package packer builds and deploys a gokrazy image.
Package packer builds and deploys a gokrazy image.
squashfs
Package squashfs implements writing SquashFS file system images using zlib compression for data blocks (inodes and directory entries are written uncompressed for simplicity).
Package squashfs implements writing SquashFS file system images using zlib compression for data blocks (inodes and directory entries are written uncompressed for simplicity).
systemdboot
Package systemdboot provides a bundled copy of the systemd-boot UEFI app.
Package systemdboot provides a bundled copy of the systemd-boot UEFI app.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL