Skip to content

Commit b100a0b

Browse files
authored
[remove nixpkgs] move installableForPackage to a Package.Installable method (#1258)
## Summary I didn't feel strongly about where this lived. Moving to Package.Installable upon @mikeland73's suggestion in #1255 (comment) ## How was it tested? compiles
1 parent 5becdc1 commit b100a0b

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

internal/devpkg/package.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,34 @@ func (p *Package) URLForFlakeInput() string {
145145
return p.urlWithoutFragment()
146146
}
147147

148-
// URLForInstall is used during `nix profile install`.
148+
// Installable for this package. Installable is a nix concept defined here:
149+
// https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html#installables
150+
func (p *Package) Installable() (string, error) {
151+
inCache, err := p.IsInBinaryCache()
152+
if err != nil {
153+
return "", err
154+
}
155+
156+
if inCache {
157+
// TODO savil: change to ContentAddressablePath?
158+
installable, err := p.InputAddressedPath()
159+
if err != nil {
160+
return "", err
161+
}
162+
return installable, nil
163+
}
164+
165+
installable, err := p.urlForInstall()
166+
if err != nil {
167+
return "", err
168+
}
169+
return installable, nil
170+
}
171+
172+
// urlForInstall is used during `nix profile install`.
149173
// The key difference with URLForFlakeInput is that it has a suffix of
150174
// `#attributePath`
151-
func (p *Package) URLForInstall() (string, error) {
175+
func (p *Package) urlForInstall() (string, error) {
152176
if p.isDevboxPackage() {
153177
entry, err := p.lockfile.Resolve(p.Raw)
154178
if err != nil {

internal/nix/nixprofile/profile.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func ProfileInstall(args *ProfileInstallArgs) error {
228228
fmt.Fprintf(args.Writer, "%s\n", stepMsg)
229229
}
230230

231-
installable, err := installableForPackage(input)
231+
installable, err := input.Installable()
232232
if err != nil {
233233
return err
234234
}
@@ -258,28 +258,3 @@ func ProfileRemoveItems(profilePath string, items []*NixProfileListItem) error {
258258
}
259259
return nix.ProfileRemove(profilePath, indexes)
260260
}
261-
262-
// installableForPackage determines how nix profile should install this package.
263-
// Keeping in `nixprofile` package since its specific to how nix profile works,
264-
// rather than a general property of devpkg.Package
265-
func installableForPackage(pkg *devpkg.Package) (string, error) {
266-
inCache, err := pkg.IsInBinaryCache()
267-
if err != nil {
268-
return "", err
269-
}
270-
271-
if inCache {
272-
// TODO savil: change to ContentAddressablePath?
273-
installable, err := pkg.InputAddressedPath()
274-
if err != nil {
275-
return "", err
276-
}
277-
return installable, nil
278-
}
279-
280-
installable, err := pkg.URLForInstall()
281-
if err != nil {
282-
return "", err
283-
}
284-
return installable, nil
285-
}

0 commit comments

Comments
 (0)