1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
---@meta
-- Zoi Package Definitions for lua-language-server (LSP)
---@class SystemInfo
---@field OS "linux"|"macos"|"windows" The operating system name.
---@field ARCH "amd64"|"arm64" The CPU architecture.
---@field DISTRO string? The Linux distribution ID (e.g., "ubuntu", "arch").
---@field DISTRO_VER string? The version of the distribution (e.g., "22.04", "14.1").
---@field DE string? The detected Desktop Environment (e.g., "kde", "gnome", "windows").
---@field SERVER string? The display server in use (e.g., "x11", "wayland", "quartz").
---@field KERNEL_VER string? The kernel version of the operating system.
---@field CPU string? CPU model information.
---@field GPU string? GPU model information.
---@field MANAGER string? The detected native package manager (e.g., "apt", "pacman").
SYSTEM =
---@class ZoiInfo
---@field VERSION string The version of the package being built.
---@field PATH { user: string, system: string } Zoi installation paths.
---@field PKG { store: string, template: string, root: string, home: string, lua: string } Package-specific absolute paths.
ZOI =
---@class Maintainer
---@field name string Maintainer name.
---@field email string Maintainer email.
---@field website string? Maintainer website.
---@class Author
---@field name string Author name.
---@field email string? Author email.
---@field website string? Author website.
---@class CiConfig
---@field tags table<string, string>? Runner tags per OS (e.g., { linux = "saas-linux-medium-amd64" }).
---@class PkgMetadata
---@field name string Required. The name of the package.
---@field repo string Required. The repository tier (e.g., "core", "community").
---@field version string? The package version.
---@field revision string? The package revision (defaults to "1").
---@field versions table<string, string>? A map of channels to versions (e.g., { stable = "1.2.3" }).
---@field description string Required. A short description of the package.
---@field website string? The official website URL.
---@field git string? The source code's git repository URL.
---@field man string? A URL to the package's manual page.
---@field maintainer Maintainer Required. The package maintainer.
---@field author Author? The original software author.
---@field license string? The SPDX license identifier.
---@field bins string[]? List of binary names to link.
---@field conflicts string[]? List of conflicting packages.
---@field provides string[]? List of virtual packages provided.
---@field replaces string[]? List of packages this one replaces.
---@field backup string[]? List of config files to preserve during upgrades.
---@field types string[] Required. Supported build methods (e.g., "source", "pre-compiled").
---@field platforms string[]? Supported platforms (e.g., "linux", "macos", "windows", "ci:windows-amd64:linux" for cross-build).
---@field ci CiConfig? CI runner configuration for build pipelines.
---@field type "package"|"collection"|"app"|"extension"? The type of package.
---@field scope "user"|"system"|"project"? Default installation scope.
---@field sub_packages string[]? List of sub-package names.
---@field main_subs string[]? Default sub-packages to install.
---@field tags string[]? Keywords for search.
---@field readme string? URL to the package's README.
---@field rollback boolean? Whether to enable rollback for this package.
---@field installed_size integer? Expected size on disk (bytes).
---@field archive_size integer? Size of the pre-compiled archive (bytes).
PKG =
---@type string Absolute path to the temporary build directory.
BUILD_DIR = ""
---@type string Absolute path to the staging directory.
STAGING_DIR = ""
---@type "source"|"pre-compiled" The build method requested by the user.
BUILD_TYPE = ""
---@type string? For split packages, the name of the sub-package being processed.
SUBPKG = nil
---@class DependencyOptions
---@field name string Group name.
---@field desc string Group description.
---@field all boolean? Whether all options can be selected.
---@field depends string[] List of dependency strings.
---@class DependencyGroup
---@field required string[]? List of required dependencies.
---@field optional string[]? List of optional dependencies.
---@field options DependencyOptions[]? List of selectable dependency groups.
---@field sub_packages table<string, DependencyGroup>? Per-sub-package dependencies.
---@class TypedBuildDependencies
---@field types table<string, DependencyGroup> Map of build type to dependencies.
---@class Dependencies
---@field runtime DependencyGroup? Runtime dependencies.
---@field build (DependencyGroup|TypedBuildDependencies)? Build-time dependencies.
---@class Service
---@field run string The command to run the service.
---@field run_at_load boolean? Start on boot/login.
---@field working_dir string? Working directory.
---@field env table<string, string>? Environment variables.
---@field log_path string? stdout log path.
---@field error_log_path string? stderr log path.
---@class HookPlatformMap
---@field linux string[]? Commands for Linux.
---@field macos string[]? Commands for macOS.
---@field windows string[]? Commands for Windows.
---@field default string[]? Fallback commands.
---@alias HookCommands string[] | HookPlatformMap
---@class Hooks
---@field pre_install HookCommands?
---@field post_install HookCommands?
---@field pre_upgrade HookCommands?
---@field post_upgrade HookCommands?
---@field pre_remove HookCommands?
---@field post_remove HookCommands?
---@class UpdateNotice
---@field type "update"|"change"|"vulnerability"
---@field message string
--- Declares package static information.
---@param meta PkgMetadata
--- Declares package dependencies.
---@param deps Dependencies
--- Declares structured update notices.
---@param notices UpdateNotice[]
--- Declares lifecycle hooks.
---@param hooks_def Hooks
--- Declares a background service.
---@param svc Service
--- Lifecycle: Fetch source code or binaries into BUILD_DIR.
---@param args { sub: string? }?
--- Lifecycle: Optional compilation step in BUILD_DIR (between prepare and package).
---@param args { sub: string? }?
--- Lifecycle: Compile and stage files into STAGING_DIR.
---@param args { sub: string? }?
--- Lifecycle: Verify integrity and authenticity of downloaded files.
---@param args { sub: string? }?
---@return boolean
--- Lifecycle: Optional function to run integration tests.
---@param args { sub: string? }?
---@return boolean
--- Lifecycle: Cleanup tasks outside the package store.
--- Executes a shell command within BUILD_DIR.
---@param command string
---@return string stdout, string stderr, integer exit_code
--- Stages a file or directory for inclusion in the final package.
---@param source string Path relative to BUILD_DIR or ${pkgluadir}.
---@param destination string Destination using ${pkgstore}, ${usrroot}, etc.
--- Copies a license file to the package store (${pkgstore}/LICENSE).
---@param source string Path relative to BUILD_DIR or ${pkgluadir}.
--- Copies a documentation file to the package store (${pkgstore}/doc/{filename}).
---@param source string Path relative to BUILD_DIR or ${pkgluadir}.
--- Stages a shell completion file for a specific shell.
--- The file is copied to ${pkgstore}/shell/{shell}/{filename} and symlinked
--- into the global completions directory (~/.zoi/pkgs/shell/{shell}/{package}/).
---@param source string Path relative to BUILD_DIR or ${pkgluadir}.
---@param shell string The shell name: "bash", "zsh", "fish", or "elvish".
--- Performs a regular expression replacement on a file within the build directory.
---@param pattern string The regex pattern to match.
---@param replacement string The string to replace the matched pattern.
---@param file string The path to the file relative to BUILD_DIR.
--- Applies a patch file to the build directory using the 'patch' command.
---@param patch_file string The path to the patch file relative to BUILD_DIR.
---@param strip integer? The number of leading path components to strip (default is 1).
--- Creates a symbolic link in the package.
---@param target string
---@param link string
--- Sets permissions of a staged file or directory.
---@param path string
---@param mode integer Octal mode (e.g., 493 for 0755).
--- Sets ownership of a staged file or directory.
---@param path string
---@param owner string|integer
---@param group string|integer
--- Creates a directory in the package.
---@param path string
--- Removes a file/directory (used in uninstall()).
---@param path string
--- Reads a file from the same directory as the .pkg.lua.
---@param filename string
---@return any content Parsed table for .json/.yaml/.toml, else string.
--- Executes another Lua script in the same directory.
---@param filename string
--- Verifies a file's checksum.
---@param file_path string
---@param hash_spec string e.g., "sha256-..."
---@return boolean
--- Verifies a PGP detached signature.
---@param file_path string
---@param sig_path string
---@param key_name_or_url string
---@return boolean
--- Adds a PGP key to Zoi's keyring.
---@param url_or_path string
---@param name string
---@return boolean
UTILS =
UTILS. =
--- Fetches a URL's content as a string.
---@param url string
---@return string
---@class GithubLatestArgs
---@field repo string "owner/repo"
---@field domain string? Optional API domain.
---@field branch string? Optional branch.
UTILS.. =
---@param args GithubLatestArgs
---@return string
---@param args GithubLatestArgs
---@return string
---@param args GithubLatestArgs
---@return string
UTILS.. =
---@param args GithubLatestArgs
---@return string
---@param args GithubLatestArgs
---@return string
---@param args GithubLatestArgs
---@return string
UTILS. =
---@param str string
---@return table?
---@param str string
---@return table?
---@param str string
---@return table?
---@param content string
---@param filename string
---@return string?
--- Downloads a file from a URL to a local path.
---@param url string
---@param path string
UTILS. =
---@param path string
---@return boolean
---@param src string
---@param dest string
---@return boolean
---@param src string
---@param dest string
---@return boolean
---@param path string
---@param mode integer
UTILS. =
---@param dir string
---@param name string
---@return string?
UTILS. =
---@param path string
---@return string[]
--- Downloads and extracts an archive.
---@param source string URL or local path.
---@param out_dir string Subdirectory in BUILD_DIR.