Skip to content

[remove nixpkgs] move installableForPackage to a Package.Installable method #1258

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 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions internal/devpkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,34 @@ func (p *Package) URLForFlakeInput() string {
return p.urlWithoutFragment()
}

// URLForInstall is used during `nix profile install`.
// Installable for this package. Installable is a nix concept defined here:
// https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html#installables
func (p *Package) Installable() (string, error) {
inCache, err := p.IsInBinaryCache()
if err != nil {
return "", err
}

if inCache {
// TODO savil: change to ContentAddressablePath?
installable, err := p.InputAddressedPath()
if err != nil {
return "", err
}
return installable, nil
}

installable, err := p.urlForInstall()
if err != nil {
return "", err
}
return installable, nil
}

// urlForInstall is used during `nix profile install`.
// The key difference with URLForFlakeInput is that it has a suffix of
// `#attributePath`
func (p *Package) URLForInstall() (string, error) {
func (p *Package) urlForInstall() (string, error) {
if p.isDevboxPackage() {
entry, err := p.lockfile.Resolve(p.Raw)
if err != nil {
Expand Down
27 changes: 1 addition & 26 deletions internal/nix/nixprofile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func ProfileInstall(args *ProfileInstallArgs) error {
fmt.Fprintf(args.Writer, "%s\n", stepMsg)
}

installable, err := installableForPackage(input)
installable, err := input.Installable()
if err != nil {
return err
}
Expand Down Expand Up @@ -258,28 +258,3 @@ func ProfileRemoveItems(profilePath string, items []*NixProfileListItem) error {
}
return nix.ProfileRemove(profilePath, indexes)
}

// installableForPackage determines how nix profile should install this package.
// Keeping in `nixprofile` package since its specific to how nix profile works,
// rather than a general property of devpkg.Package
func installableForPackage(pkg *devpkg.Package) (string, error) {
inCache, err := pkg.IsInBinaryCache()
if err != nil {
return "", err
}

if inCache {
// TODO savil: change to ContentAddressablePath?
installable, err := pkg.InputAddressedPath()
if err != nil {
return "", err
}
return installable, nil
}

installable, err := pkg.URLForInstall()
if err != nil {
return "", err
}
return installable, nil
}