Skip to content

[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

Merged
merged 6 commits into from
Aug 11, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Aug 9, 2023

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:

  1. Replace devbox.Packages with ConfigPackageNames() and InstallablePackageNames().
  2. Replace devbox.PackagesAsInputs with ConfigPackages() and InstallablePackages().
    Updates callers to call the appropriate one.

devpkg.Package changes
I also introduce a new method devpkg.PackagesFromConfig, which enables us to add an isInstallable bool field on the devpkg.Package. I needed this because it affects the implementation of certain methods (such as IsLegacy changed in #1358).

One can still construct via PackagesFromStrings which default to isInstallable = true (as before). I audited the callers.

How was it tested?

Did adhoc testing.
Testscript unit tests should pass.

@savil savil changed the title [Packages] Introduce ConfigPackages and PlatformPackage functions [Packages] Introduce ConfigPackages and InstallablePackages functions Aug 9, 2023
@savil savil force-pushed the savil/config-pkg-to-devpkg branch from 9a6c804 to 485ec44 Compare August 9, 2023 23:06
@savil savil changed the title [Packages] Introduce ConfigPackages and InstallablePackages functions Split devbox.Packages() into ConfigPackages() and InstallablePackages() methods Aug 9, 2023
@savil savil changed the title Split devbox.Packages() into ConfigPackages() and InstallablePackages() methods [Packages] Introduce the concept of Installable packages Aug 10, 2023
@savil savil force-pushed the savil/config-pkg-to-devpkg branch from 987c28c to cacc711 Compare August 10, 2023 00:58
@savil savil force-pushed the savil/config-pkg-to-devpkg branch from cacc711 to 9a3354a Compare August 10, 2023 01:03
@savil savil requested review from gcurtis and mikeland73 August 10, 2023 01:04
@savil savil marked this pull request as ready for review August 10, 2023 01:05
Copy link
Contributor

@mikeland73 mikeland73 left a 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)

return name
}

func (p *Package) IsEnabledOnPlatform() (bool, error) {
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this; done

Copy link
Collaborator Author

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.

@@ -157,13 +157,18 @@ func (m *Manager) createFile(
urlForInput = pkg.URLForFlakeInput()
}

packages, err := m.InstallablePackageNames()
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool; done

Copy link
Collaborator Author

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.

@savil savil force-pushed the savil/config-pkg-to-devpkg branch from 9bbc3dc to 3ba264f Compare August 11, 2023 22:36
@savil savil merged commit 89ef96b into main Aug 11, 2023
@savil savil deleted the savil/config-pkg-to-devpkg branch August 11, 2023 23:05
@sentry-io
Copy link

sentry-io bot commented Aug 15, 2023

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ **exec.ExitError: <redacted errors.withStack>: <redacted exec.ExitError> go.jetpack.io/devbox/internal/nix in System View Issue

Did you find this useful? React with a 👍 or 👎

savil added a commit that referenced this pull request Aug 15, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants