Generates Go flags and NixOS module options from a CUE schema.
go tool gen --schema schema.cue --go args.gen.go --nix nix/options.gen.nix
-check reports stale outputs instead of writing them.
-go-type; nested: lowerCamel label + -go-type-suffix, e.g. sshArgs)defaultArgs() returns the CUE defaultsregisterFlags(fs, c) defines a flag per fieldc.validate() checks bounds, enums, regexes and !=""Flags are named by path (ssh.clone-url), fields by PascalCase label with initialisms (CloneURL). List flags are repeatable; the first use replaces the default.
A { lib }: function returning options for an RFC 42 settings submodule. Types follow the constraints: ints.between, enum, strMatching, nonEmptyStr, and nullOr (default null) for optional fields.
Like @go(type, parse), @nix(type, apply) lets a field look different in Nix than on the wire. apply also runs on the default, so a non-empty CUE default must fit the Nix type; set @nix(default) if it doesn't.
Set on a field or on a referenced definition (e.g. #Port); the field wins, then the nearest definition.
| Attribute | Meaning |
|---|---|
@go(name=X) |
Go field name (field only) |
@go(type=T) |
Go type name of a struct |
@go(type=T, parse=F, import=P) |
Custom type; F is your func(string) (T, error), P space-separated imports. On a list, T is the element type |
@nix(type=E) |
Raw Nix type (whole list, on a list) |
@nix(apply=F) |
Nix function mapping the option's value back to what the app expects (whole list, on a list; mapped over elements when set on the element's definition) |
@nix(import=N) |
Space-separated names that F/E use; each becomes an argument of the generated function for you to pass in |
@nix(default=V) |
NixOS default (field only); a string for string fields, CUE otherwise |
@nix(skip) |
Omit from Nix |
bool, int, float, number, string, open lists of those, nested structs, literal enums, and bounds, regexes and !="" on scalars. Anything else is an error.
Example supplementary wiring files are provided in contrib.