Skip to content
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

nix: make System, Version, SourceProfile public #2443

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

gcurtis
Copy link
Collaborator

@gcurtis gcurtis commented Dec 10, 2024

Note: most of this large diff is just moving code from internal/nix/nix[_test].go to nix/nix[_test].go.

As part of some cleanup for making the DetSys installer the default, move the code related to getting the Nix version and system to the non-internal go.jetpack.io/devbox/nix package. It also merges in some nearly-duplicate code from the search indexer's Nix code (which will eventually use this package instead).

Some of the changes taken from the indexer are:

  • Calling any function or method automatically...
    • sources the Nix profile if necessary.
    • looks for Nix in some well-known places if it isn't in PATH.
  • nix.Version and nix.System are cached behind a sync.Once by default.

All top-level functions map to a method on a default Nix struct, following the same pattern found in flags, slog, etc.

const Version2_12 = "2.12.0" ...
var Default = &Nix{}
func AtLeast(version string) bool
func SourceProfile() (sourced bool, err error)
func System() string
func Version() string
type Info struct{ ... }
	func (i Info) AtLeast(version string) bool
type Nix struct{ ... }
	func (n *Nix) Info() (Info, error)
	func (n *Nix) System() string
	func (n *Nix) Version() string

@gcurtis gcurtis force-pushed the gcurtis/export-nix-version branch 4 times, most recently from 71029a6 to 7e51e05 Compare December 11, 2024 22:00
As part of some cleanup for making the DetSys installer the default,
move the code related to getting the Nix version and system to the
non-internal go.jetpack.io/devbox/nix package. It also merges in some
nearly-duplicate code from the search indexer's Nix code (which will
eventually use this package instead).

Some of the changes taken from the indexer are:

- Calling any function or method automatically...
	- sources the Nix profile if necessary.
	- looks for Nix in some well-known places if it isn't in PATH.
- `nix.Version` and `nix.System` are cached behind a `sync.Once` by
  default.

All top-level functions map to a method on a default Nix struct,
following the same pattern found in `flags`, `slog`, etc.

	const Version2_12 = "2.12.0" ...
	var Default = &Nix{}
	func AtLeast(version string) bool
	func SourceProfile() (sourced bool, err error)
	func System() string
	func Version() string
	type Info struct{ ... }
	    func (i Info) AtLeast(version string) bool
	type Nix struct{ ... }
	    func (n *Nix) Info() (Info, error)
	    func (n *Nix) System() string
	    func (n *Nix) Version() string
@gcurtis gcurtis force-pushed the gcurtis/export-nix-version branch from 7e51e05 to 921ba51 Compare December 11, 2024 22:10
@gcurtis gcurtis requested review from savil and mikeland73 December 11, 2024 23:28
@gcurtis gcurtis merged commit 6d759b4 into main Dec 12, 2024
29 checks passed
@gcurtis gcurtis deleted the gcurtis/export-nix-version branch December 12, 2024 02:56
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