Repository navigation
[pkgdef 3/6] feat(pkgdef): wire package definitions into add, lock, install and env - #3002
mikeland73 wants to merge 13 commits into
Conversation
Teach Devbox the "pkg:<ref>@<version>" package string behind the DEVBOX_FEATURE_PKG_DEFS flag (on in dev builds). See specs/package-definitions.md. - pkgtype.IsPkgDef recognizes the scheme and keeps it out of flake detection; devpkg treats such packages as non-nix so shellgen and the nix store paths skip them, and ValidateExists resolves them through the lockfile so `devbox add` surfaces the definition's own errors. - devbox.lock gains definition_hash and per-system url/sha256. Remote definitions are pinned to the hash except on `devbox update`; a definition without a checksum source gets its digest recorded by the first install (trust on first use) and kept across updates. - installPackages installs package definitions next to runx packages into $XDG_CACHE_HOME/devbox/pkgs and computeEnv appends their bin directories to PATH. A definition that does not support the current system fails with an --exclude-platform hint. - Each resolved package definition becomes a plugin config so its env, shell.init_hook and create_files apply through the plugin manager, with InstallDir, Version, CacheDir, System, OS and Arch template variables. Local definition files feed the config hash so edits trigger a reinstall. - Relative file:// URLs in a local definition resolve against its directory, which keeps the new testscript self-contained. Co-Authored-By: Claude Fable 5.1 <[email protected]>
ccbb54d to
332643a
Compare
# Conflicts: # internal/devpkg/package.go
[Medium impact] The PR appears safe to merge with the stack, with a non-blocking checksum sync issue.
|
# Conflicts: # internal/devbox/packages.go # internal/devbox/update_test.go
…em and PATH Fixes the PR 3 findings from the audit in specs/package-definitions.md: - Activation templates: render every string in a definition's env, shell and create_files with the package definition template functions (now exported as pkgdef.TemplateFuncs) and the plugin variables before marshalling, instead of templating the JSON-escaped plugin.json. Errors loading a definition's activation are shown as a warning (once per message) instead of being logged at debug level; config load still succeeds so `devbox rm`/`update` keep working. - `devbox update` always re-resolves pkg: entries, versioned or not. - With DEVBOX_FEATURE_PKG_DEFS off, pkg: packages fail early (add, lockfile Resolve/FetchResolvedPackage) with a hint to set the flag, instead of a slow nixpkgs search or "unsupported flake reference". - `devbox info pkg:...` loads the definition and resolves the version locally; `devbox search pkg:...` points to `devbox info`. Neither contacts the search service. - Package definitions use nix.SystemOrHost, which falls back to GOOS/GOARCH when nix isn't installed. - PATH: package definition bin dirs now come first, next to the nix profile bin dir and ahead of the stdenv and inherited PATH. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Bqy92oAnwydcLrbSE7nkVH
# Conflicts: # internal/pkgdef/checksum.go # internal/pkgdef/definition.go # internal/pkgdef/install.go # internal/pkgdef/versions.go
|
@greptileai review Generated by Claude Code |
|
@greptileai review Generated by Claude Code |
- Key installs by the resolved file:// URL so relative artifacts from different definition directories don't share an install. - Re-lock a local definition's entry (keeping its version) when the file changed, so an edited install recipe doesn't install the old artifact. - Reload the config after locking "pkg:" entries added by editing devbox.json, so the first command gets their env, init hook and files. - Honor disable_plugin for package definitions. - Skip (with a warning) a definition whose name collides with another's, instead of letting both write into pkgdef-<name>. - Include local definitions' create_files sources in the config hash. - Remove a package definition's plugin dir (pkgdef-<name>) on devbox rm. - Read the existing lock entry under the lockfile mutex. - Set last_modified on package definition lock entries so multi-project lockfile sync picks them up (kept unchanged when nothing changed). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Bqy92pwczBpH2NQmF4hzg5
Resolve conflicts with the project-less 'devbox info' refactor from main: the package-definition check moves into packageInfo so definitions are never sent to the search service with or without a project, and pkgDefInfo takes the project dir, locker and stderr instead of *Devbox. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Bqy92mV11RTGiKeSuiHtuV
…ck entries - PR 3 spec text: flag-off pkg: strings fail with an error (they are not unrecognized); local definition edits re-lock the entry; pkg-def entries set last_modified; same-name definitions, disable_plugin and create_files edits in Activation; info/search never contact the search service. - Unit tests for last_modified on pkg-def lock entries and RelockPkgDef. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Bqy92pwczBpH2NQmF4hzg5
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Bqy92pwczBpH2NQmF4hzg5
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
|
@greptileai review Generated by Claude Code |
| locked.Systems[system].URL = url | ||
| locked.Systems[system].Sha256 = sha256 | ||
| return f.Save() |
There was a problem hiding this comment.
Sync misses recorded checksums
SetArtifactForPackage saves a newly learned checksum without changing LastModified. If two projects start with the same lock entry and one installs the package, SyncLockfiles skips the other project because their timestamps still match. The second project keeps trusting its next download instead of using the checksum already recorded by the first.
Update the timestamp when recording a changed artifact, or make sync compare the artifact fields too.
Knowledge Base Used: Dependency lock resolution
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/lock/pkgdef.go
Line: 131-133
Comment:
**Sync misses recorded checksums**
`SetArtifactForPackage` saves a newly learned checksum without changing `LastModified`. If two projects start with the same lock entry and one installs the package, `SyncLockfiles` skips the other project because their timestamps still match. The second project keeps trusting its next download instead of using the checksum already recorded by the first.
Update the timestamp when recording a changed artifact, or make sync compare the artifact fields too.
**Knowledge Base Used:** [Dependency lock resolution](https://app.greptile.com/-/switch-tenant?tenant=mike-s-org&next=%2Fcustom-context%2Fknowledge-base%2Fjetify-com%2Fdevbox%2F-%2Fdocs%2Fdependency-lock-resolution.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Stack (merge in order):
internal/pkgdeflibraryDEVBOX_FEATURE_PKG_DEFS) 👈 this PRSummary
Third PR of the package definitions stack. Teaches Devbox the
pkg:<ref>@<version>package string, behind theDEVBOX_FEATURE_PKG_DEFSflag (on in dev builds). With the flag off,pkg:strings fail with an error telling the user to set the flag.pkgtype.IsPkgDefrecognizespkg:and keeps it out of flake detection. Indevpkg, such packages:@;devbox addsurfaces the definition's own errors instead of falling back to nixpkgs.devbox.lockgainsdefinition_hashand per-systemurl/sha256(additive;lockfile_versionunchanged).devbox update. Update also records a changed hash when version and artifacts are unchanged. Everypkg:entry is eligible for update, including ones written without a version.installPackagesinstalls package definitions next to runx packages, andcomputeEnvadds their bin dirs toPATH.--exclude-platformhint.file://URLs stay relative in the lockfile and resolve against the definition's directory when fetching, so lockfiles are portable.pkgdef-<name>), soenv,shell.init_hookandcreate_filesapply through the plugin manager. Templates getInstallDir,Version,CacheDir,System,OSandArch.devbox updateanddevbox rmalways work.definition_hash, the install step first re-locks the entry at the locked version, sourl/sha256follow the edited recipe.The spec's status table is updated accordingly.
Audit fixes
These come from the cross-stack audit recorded in the spec.
{{ if eq .OS "darwin" }}broke on JSON escaping, andtrimPrefixand friends were undefined.devbox infoanddevbox searchwithpkg:never contact the search service.infoloads the definition and prints its name, version, description, homepage and platforms. It goes throughpackageInfo, so it also works outside a project (main's project-lessdevbox info).nix.SystemOrHost()falls back to GOOS/GOARCH. Before, a machine without nix silently lost the definition's env and failed installs.PATH. They used to be appended last, losing to nix packages and system binaries.Review fixes
From Greptile's review of this PR:
file://path, so two definitions in different folders using the same relative URL never share an install. The lockfile keeps the relative URL.devbox.json. The config is reloaded once the install locks a newpkg:entry, so the firstdevbox rungets its env, init hook and created files.disable_pluginis honored. A second definition with the samenameis skipped with a warning instead of writing into the samepkgdef-<name>dir. Editing a local definition'screate_filessource changes the config hash.devbox rmremoves the definition'spkgdef-<name>dir instead of a path built from the rawpkg:string.pkg-defentries setlast_modified(kept when re-resolving yields the same entry), so multi-project lockfile sync no longer skips them.Test plan
testscripts/pkgdef/pkgdef.test.txtcovers:eq/replacetemplates,info,search, updating an unversioned entry, flag-off errorsinternal/pkgdef,internal/devpkg,internal/devbox(the update merge records a changed definition hash),internal/plugin(activation, disabled plugin, duplicate names, create_files hash),internal/lock(last_modified, re-locking an edited definition),internal/boxcli(search) andinternal/nixpkgs/go/go.pkg.jsonon macOS arm64 installs Go 1.22.12 from go.dev with all four platform checksums locked.which goandgo env GOROOTpoint into the cache.go vetandgofmtclean.golangci-lintwas clean before the review fixes and has not been re-run since.https://claude.ai/code/session_01Bqy92oAnwydcLrbSE7nkVH
Generated by Claude Code