Skip to content

[nix.System] call EnsureNixInstalled from devbox.Open, and cleanup function API #1374

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 9 commits into from
Aug 15, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Aug 14, 2023

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

Copy link
Collaborator Author

savil commented Aug 14, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@savil savil force-pushed the savil/fix-nix-compute branch from fd2fab6 to 55e9d30 Compare August 14, 2023 19:15
@savil savil requested a review from mikeland73 August 14, 2023 19:15
}
}
return cachedSystem
}

var cachedSystem string

// TODO: rename to ComputeSystem or ComputePlatform?
func System() (string, error) {
func ComputeSystem() (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ComputeSystem should only return error (we always discard the string)

@savil savil force-pushed the savil/fix-nix-compute branch from 55e9d30 to 7380cb8 Compare August 15, 2023 04:39
@savil savil merged commit 1c4b8a9 into main Aug 15, 2023
@savil savil deleted the savil/fix-nix-compute branch August 15, 2023 19:17
@savil
Copy link
Collaborator Author

savil commented Aug 15, 2023

I had to bump the test-timeout to land this. We needed this PR for correctness. But I will pursue a fix to improve the test times.

@sentry-io
Copy link

sentry-io bot commented Aug 16, 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
  • ‼️ **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 👎

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