Skip to content

Conversation

mikeland73
Copy link
Contributor

Summary

  • If user is logged in, check jetpack API to see if they have nix cache available. If available use it.
  • Adds new provider framework for logged-in/logged-out functionality.

Note: There's a minor issue we need to fix with the access token. It's missing the audience which is needed by the API. Will fix in https://github.com/jetpack-io/opensource

How was it tested?

  • Copied over access token with correct audience
  • Added myself as a trusted user
  • devbox add hello on org that has nix cache. Observed it attempted to use the cache.

## Summary

TSIA

## How was it tested?

builds
Copy link
Collaborator

@mohsenari mohsenari left a comment

Choose a reason for hiding this comment

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

see a couple of comments


type Provider struct{}

var singleton *Provider = &Provider{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do providers need to be singletons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't right now, but I'm hoping to add caching to avoid making multiple API calls. Will do this after testing end to end and understanding where the perf bottlenecks are.

Comment on lines 79 to 99
func ensureTrustedUser(ctx context.Context) {
// we need to ensure that the user can actually use the extra
// substituter. If the user did a root install, then we need to add
// the trusted user/substituter to the nix.conf file and restart the daemon.

// This check is not perfect, so we still try to use the substituter even if
// it fails

// TODOs:
// * Also check if cache is enabled in nix.conf
// * Test on single user install
// * Automate making user trusted if needed
if !nix.IsUserTrusted(ctx) {
ux.Fwarning(
os.Stderr,
"In order to use a custom nix cache you must be a trusted user. Please "+
"add your username to nix.conf (usually located at /etc/nix/nix.conf)"+
" and restart the nix daemon.",
)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

if you're just showing a warning when a user is not trusted then ensureTrustedUser is not the best name for it.
Maybe checkTrustedUser or alternatively we can return NixCacheConfig{} if the user is not trusted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can change the function name. The issue is that I'm not 100% confident we can catch all cases where you are actually allowed to use the substitutor, so returning an empty cache config would be wrong.

Especially since nix build will still work in the bad case (it just shows a warning)

},
IsDev: build.IsDev,
Stderr: d.stderr,
Store: &jetstore.JetpackAPIStore{},
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this change relevant to the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is no longer used when we updated envsec dependency.

Comment on lines 32 to 33
cmd.Env = allowUnfreeEnv(os.Environ())
cmd.Env = append(cmd.Env, args.Env...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can be cmd.Env = append(allowUnfreeEnv(os.Environ()), args.Env...)

@mikeland73 mikeland73 merged commit 28ca84d into main Mar 29, 2024
@mikeland73 mikeland73 deleted the landau/get-cache-config branch March 29, 2024 18:04
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