Skip to content

Commit 5becdc1

Browse files
authored
[remove nixpkgs] Naming: update Package methods to InputAddressedPath and ContentAddressedPath, and s/BinaryStore/BinaryCache (#1257)
## Summary This PR is a follow up to this request from @gcurtis: #1256 (review) BUT having `NixStorePath` and `ContentAddressedPath` seemed odd since content-addressed paths are also nix store paths. So, in this PR, I'm explicit about `NixStorePath` being `InputAddressedPath`. Also - changed `BinaryStore` to `BinaryCache`. **RFC**: I didn't change the `lock.SystemInfo` struct, I've left it as: ``` type SystemInfo struct { // StorePath is the input-addressed path for the nix package in /nix/store // It is the cache key in the Binary Cache Store (cache.nixos.org) // It is of the form <hash>-<name>-<version> // <name> may be different from the canonicalName so we store the full store path. StorePath string `json:"store_path,omitempty"` // CAStorePath is the content-addressed path for the nix package in /nix/store // It is of the form <hash>-<name>-<version> CAStorePath string `json:"ca_store_path,omitempty"` } ``` I think this could be okay, because the default `store_path` for nix is input-addressed, for now at least. If you'd like I can change `StorePath` to be explicitly: ``` InputAddrStorePath string `json:"input_addr_path, omitempty" ContentAddrStorePath string `json:"content_addr_path, omitempty" ``` Let me know! ## How was it tested? compiles
1 parent ad6725d commit 5becdc1

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

internal/devpkg/package.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ func (p *Package) ValidateExists() (bool, error) {
328328
return false, usererr.New("No version specified for %q.", p.Path)
329329
}
330330

331-
isInStore, err := p.IsInBinaryStore()
331+
inCache, err := p.IsInBinaryCache()
332332
if err != nil {
333333
return false, err
334334
}
335-
if isInStore {
335+
if inCache {
336336
return true, nil
337337
}
338338

@@ -391,11 +391,11 @@ func (p *Package) LegacyToVersioned() string {
391391

392392
func (p *Package) EnsureNixpkgsPrefetched(w io.Writer) error {
393393

394-
isInStore, err := p.IsInBinaryStore()
394+
inCache, err := p.IsInBinaryCache()
395395
if err != nil {
396396
return err
397397
}
398-
if isInStore {
398+
if inCache {
399399
// We can skip prefetching nixpkgs, if this package is in the binary
400400
// cache store.
401401
return nil
@@ -426,13 +426,11 @@ func (p *Package) HashFromNixPkgsURL() string {
426426
return nix.HashFromNixPkgsURL(p.URLForFlakeInput())
427427
}
428428

429-
// BinaryCacheStore is the store from which to fetch this package's binaries.
429+
// BinaryCache is the store from which to fetch this package's binaries.
430430
// It is used as FromStore in builtins.fetchClosure.
431-
// TODO savil: rename to BinaryCache
432-
const BinaryCacheStore = "https://cache.nixos.org"
431+
const BinaryCache = "https://cache.nixos.org"
433432

434-
// TODO savil: rename to IsInBinaryCache
435-
func (p *Package) IsInBinaryStore() (bool, error) {
433+
func (p *Package) IsInBinaryCache() (bool, error) {
436434
if !featureflag.RemoveNixpkgs.Enabled() {
437435
return false, nil
438436
}
@@ -460,13 +458,12 @@ func (p *Package) IsInBinaryStore() (bool, error) {
460458
return ok, nil
461459
}
462460

463-
// PathInBinaryStore is the key in the BinaryCacheStore for this package
464-
// This is used as StorePath in builtins.fetchClosure
465-
// TODO savil: rename to PathInBinaryCache
466-
func (p *Package) PathInBinaryStore() (string, error) {
467-
if isInStore, err := p.IsInBinaryStore(); err != nil {
461+
// InputAddressedPath is the input-addressed path in /nix/store
462+
// It is also the key in the BinaryCache for this package
463+
func (p *Package) InputAddressedPath() (string, error) {
464+
if inCache, err := p.IsInBinaryCache(); err != nil {
468465
return "", err
469-
} else if !isInStore {
466+
} else if !inCache {
470467
return "",
471468
errors.Errorf("Package %q cannot be fetched from binary cache store", p.Raw)
472469
}
@@ -485,11 +482,12 @@ func (p *Package) PathInBinaryStore() (string, error) {
485482
return sysInfo.StorePath, nil
486483
}
487484

488-
func (p *Package) ContentAddressedStorePath() (string, error) {
485+
// ContentAddressedPath is the content-addressed form of Package.InputAddressedPath
486+
func (p *Package) ContentAddressedPath() (string, error) {
489487

490-
if isInStore, err := p.IsInBinaryStore(); err != nil {
488+
if inCache, err := p.IsInBinaryCache(); err != nil {
491489
return "", err
492-
} else if !isInStore {
490+
} else if !inCache {
493491
return "",
494492
errors.Errorf("Package %q cannot be fetched from binary cache store", p.Raw)
495493
}

internal/impl/packages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (d *Devbox) addPackagesToProfile(ctx context.Context, mode installMode) err
243243

244244
// If packages are in profile but nixpkgs has been purged, the experience
245245
// will be poor when we try to run print-dev-env. So we ensure nixpkgs is
246-
// prefetched for all relevant packages (those not in binary store).
246+
// prefetched for all relevant packages (those not in binary cache).
247247
for _, input := range d.PackagesAsInputs() {
248248
if err := input.EnsureNixpkgsPrefetched(d.writer); err != nil {
249249
return err

internal/lock/lockfile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ type Package struct {
3838
}
3939

4040
type SystemInfo struct {
41-
// StorePath is the cache key in the Binary Cache Store (cache.nixos.org)
41+
// StorePath is the input-addressed path for the nix package in /nix/store
42+
// It is the cache key in the Binary Cache Store (cache.nixos.org)
4243
// It is of the form <hash>-<name>-<version>
4344
// <name> may be different from the canonicalName so we store the full store path.
4445
StorePath string `json:"store_path,omitempty"`

internal/nix/nixprofile/profile.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ func ProfileListIndex(args *ProfileListIndexArgs) (int, error) {
6969
}
7070
}
7171

72-
inStore, err := args.Input.IsInBinaryStore()
72+
inCache, err := args.Input.IsInBinaryCache()
7373
if err != nil {
7474
return -1, err
7575
}
76-
if inStore {
77-
pathInStore, err := args.Input.PathInBinaryStore()
76+
if inCache {
77+
// TODO savil: change to ContentAddressedPath?
78+
pathInStore, err := args.Input.InputAddressedPath()
7879
if err != nil {
7980
return -1, err
8081
}
@@ -209,12 +210,12 @@ type ProfileInstallArgs struct {
209210
func ProfileInstall(args *ProfileInstallArgs) error {
210211
input := devpkg.PackageFromString(args.Package, args.Lockfile)
211212

212-
isInBinaryStore, err := input.IsInBinaryStore()
213+
inCache, err := input.IsInBinaryCache()
213214
if err != nil {
214215
return err
215216
}
216217

217-
if !isInBinaryStore && nix.IsGithubNixpkgsURL(input.URLForFlakeInput()) {
218+
if !inCache && nix.IsGithubNixpkgsURL(input.URLForFlakeInput()) {
218219
if err := nix.EnsureNixpkgsPrefetched(args.Writer, input.HashFromNixPkgsURL()); err != nil {
219220
return err
220221
}
@@ -262,14 +263,14 @@ func ProfileRemoveItems(profilePath string, items []*NixProfileListItem) error {
262263
// Keeping in `nixprofile` package since its specific to how nix profile works,
263264
// rather than a general property of devpkg.Package
264265
func installableForPackage(pkg *devpkg.Package) (string, error) {
265-
isInBinaryStore, err := pkg.IsInBinaryStore()
266+
inCache, err := pkg.IsInBinaryCache()
266267
if err != nil {
267268
return "", err
268269
}
269270

270-
if isInBinaryStore {
271-
// TODO savil: change to ContentAddressablePath when that is implemented
272-
installable, err := pkg.PathInBinaryStore()
271+
if inCache {
272+
// TODO savil: change to ContentAddressablePath?
273+
installable, err := pkg.InputAddressedPath()
273274
if err != nil {
274275
return "", err
275276
}

internal/shellgen/flake_input.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func flakeInputs(ctx context.Context, packages []*devpkg.Package) ([]*flakeInput
8080
return true
8181
}
8282

83-
inStore, err := item.IsInBinaryStore()
83+
inCache, err := item.IsInBinaryCache()
8484
if err != nil {
8585
// Ignore this error for now. TODO savil: return error?
8686
return true
8787
}
88-
return !inStore
88+
return !inCache
8989
})
9090

9191
order := []string{}

internal/shellgen/flake_plan.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
// flakePlan contains the data to populate the top level flake.nix file
1212
// that builds the devbox environment
1313
type flakePlan struct {
14-
BinaryCacheStore string
15-
NixpkgsInfo *NixpkgsInfo
16-
FlakeInputs []*flakeInput
17-
Packages []*devpkg.Package
18-
System string
14+
BinaryCache string
15+
NixpkgsInfo *NixpkgsInfo
16+
FlakeInputs []*flakeInput
17+
Packages []*devpkg.Package
18+
System string
1919
}
2020

2121
func newFlakePlan(ctx context.Context, devbox devboxer) (*flakePlan, error) {
@@ -73,10 +73,10 @@ func newFlakePlan(ctx context.Context, devbox devboxer) (*flakePlan, error) {
7373
}
7474

7575
return &flakePlan{
76-
BinaryCacheStore: devpkg.BinaryCacheStore,
77-
FlakeInputs: flakeInputs,
78-
NixpkgsInfo: nixpkgsInfo,
79-
Packages: packages,
80-
System: system,
76+
BinaryCache: devpkg.BinaryCache,
77+
FlakeInputs: flakeInputs,
78+
NixpkgsInfo: nixpkgsInfo,
79+
Packages: packages,
80+
System: system,
8181
}, nil
8282
}

internal/shellgen/tmpl/flake_remove_nixpkgs.nix.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
devShells.{{ .System }}.default = pkgs.mkShell {
3131
buildInputs = [
3232
{{- range .Packages }}
33-
{{- if .IsInBinaryStore }}
33+
{{- if .IsInBinaryCache }}
3434
(builtins.fetchClosure{
35-
fromStore = "{{ $.BinaryCacheStore }}";
36-
fromPath = "{{ .PathInBinaryStore }}";
37-
toPath = "{{ .ContentAddressedStorePath }}";
35+
fromStore = "{{ $.BinaryCache }}";
36+
fromPath = "{{ .InputAddressedPath }}";
37+
toPath = "{{ .ContentAddressedPath }}";
3838
})
3939
{{- end }}
4040
{{- end }}

0 commit comments

Comments
 (0)