-
Notifications
You must be signed in to change notification settings - Fork 249
[Packages] Introduce the concept of Installable packages #1357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
9a6c804
to
485ec44
Compare
987c28c
to
cacc711
Compare
cacc711
to
9a3354a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have 2 main concerns:
- Changing the signature of packages function to return an error causes significant code churn and can be avoided by pre-computing the system earlier in the call.
- Having 2 similar functions (installable vs config) increases cognitive load on future work. A partial solution is (a) Remove
installablePackageNames
because I think it is not needed. (b) Make configPackages private.
I think longer term we could also get rid of ConfigPackageNames
and just end up with:
- InstallablePackages (public)
- configPackages (private)
internal/devconfig/packages.go
Outdated
return name | ||
} | ||
|
||
func (p *Package) IsEnabledOnPlatform() (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this return (bool, error)
causes large changes in the code base (and generally makes things bit more difficult to read).
If seems like in the follow up PR you implement this using nix.System
Suggestion:
Have nix.EnsureNixInstalled
call nix.ComputeSystem
which stores the system in a package variable.
nix.System returns it (and panics if not set).
I know this has a bunch of stuff stacked on it so I don't know how easy it would be to make this change, but it would prevent a good amount of code/blame churn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this; done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added nix.MustGetSystem
, since nix.System
currently has an error return refactoring which would introduce a lot of unrelated changes. Can cleanup in a followup PR.
internal/plugin/plugin.go
Outdated
@@ -157,13 +157,18 @@ func (m *Manager) createFile( | |||
urlForInput = pkg.URLForFlakeInput() | |||
} | |||
|
|||
packages, err := m.InstallablePackageNames() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine for this to be all package names. Specifically, this is used so that plugin templates know all packages, it is currently used by php and haskell plugins.
If anything, in a follow up we could change this to be Package structs instead of strings. (and it would be backward compatible because the struct has a String()
method.
This would allow us to remove InstallablePackageNames and just keep a single PackageNames
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool; done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anything, in a follow up we could change this to be Package structs instead of strings. (and it would be backward compatible because the struct has a String() method.
Before we rely on .String()
, I'd prefer making Package structs not embed url.URL, so we can properly implement String()
to do what is intended.
…s; and rename ConfigPackageNames to PackageNames; drop error return from ConfigPackages
9bbc3dc
to
3ba264f
Compare
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
…nction API (#1374) ## Summary `nix.System` is widely used. So, in #1357 we wanted to change its API to just return `string` instead of `string, error`. To do so, we cache the result in a `nix` package variable. And populate it during `EnsureNixInstalled`. However, `EnsureNixInstalled` was only called from Cobra command functions. But `devbox` as a library also now needs to call it. IMO, it should always have called it since we do rely on `nix` being installed. This PR adds this. It also fixes up the API to: `System: string` and `ComputeSystem: (string, error)`. NOTE: inside `System`, I still do a best-effort to avoid panic by calling `ComputeSystem`. This can happen in edge-cases like some tests `generate_test/TestWriteFromTemplate` that exercise internal functions reliant on `nix.System` without calling `devbox.Open`. ## How was it tested? tests should pass
Summary
This PR lays some groundwork for introducing platform-specific packages in a later PR (#1358)
This PR makes the following changes to
devbox
struct:devbox.Packages
withConfigPackageNames()
andInstallablePackageNames()
.devbox.PackagesAsInputs
withConfigPackages()
andInstallablePackages()
.Updates callers to call the appropriate one.
devpkg.Package changes
I also introduce a new method
devpkg.PackagesFromConfig
, which enables us to add anisInstallable bool
field on thedevpkg.Package
. I needed this because it affects the implementation of certain methods (such asIsLegacy
changed in #1358).One can still construct via
PackagesFromStrings
which default toisInstallable = true
(as before). I audited the callers.How was it tested?
Did adhoc testing.
Testscript unit tests should pass.