Skip to content

[remove nixpkgs] Naming: update Package methods to InputAddressedPath and ContentAddressedPath, and s/BinaryStore/BinaryCache #1257

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 2 commits 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
34 changes: 16 additions & 18 deletions internal/devpkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ func (p *Package) ValidateExists() (bool, error) {
return false, usererr.New("No version specified for %q.", p.Path)
}

isInStore, err := p.IsInBinaryStore()
inCache, err := p.IsInBinaryCache()
if err != nil {
return false, err
}
if isInStore {
if inCache {
return true, nil
}

Expand Down Expand Up @@ -391,11 +391,11 @@ func (p *Package) LegacyToVersioned() string {

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

isInStore, err := p.IsInBinaryStore()
inCache, err := p.IsInBinaryCache()
if err != nil {
return err
}
if isInStore {
if inCache {
// We can skip prefetching nixpkgs, if this package is in the binary
// cache store.
return nil
Expand Down Expand Up @@ -426,13 +426,11 @@ func (p *Package) HashFromNixPkgsURL() string {
return nix.HashFromNixPkgsURL(p.URLForFlakeInput())
}

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

// TODO savil: rename to IsInBinaryCache
func (p *Package) IsInBinaryStore() (bool, error) {
func (p *Package) IsInBinaryCache() (bool, error) {
if !featureflag.RemoveNixpkgs.Enabled() {
return false, nil
}
Expand Down Expand Up @@ -460,13 +458,12 @@ func (p *Package) IsInBinaryStore() (bool, error) {
return ok, nil
}

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

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

if isInStore, err := p.IsInBinaryStore(); err != nil {
if inCache, err := p.IsInBinaryCache(); err != nil {
return "", err
} else if !isInStore {
} else if !inCache {
return "",
errors.Errorf("Package %q cannot be fetched from binary cache store", p.Raw)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/impl/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (d *Devbox) addPackagesToProfile(ctx context.Context, mode installMode) err

// If packages are in profile but nixpkgs has been purged, the experience
// will be poor when we try to run print-dev-env. So we ensure nixpkgs is
// prefetched for all relevant packages (those not in binary store).
// prefetched for all relevant packages (those not in binary cache).
for _, input := range d.PackagesAsInputs() {
if err := input.EnsureNixpkgsPrefetched(d.writer); err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion internal/lock/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type Package struct {
}

type SystemInfo struct {
// StorePath is the cache key in the Binary Cache Store (cache.nixos.org)
// 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"`
Expand Down
19 changes: 10 additions & 9 deletions internal/nix/nixprofile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ func ProfileListIndex(args *ProfileListIndexArgs) (int, error) {
}
}

inStore, err := args.Input.IsInBinaryStore()
inCache, err := args.Input.IsInBinaryCache()
if err != nil {
return -1, err
}
if inStore {
pathInStore, err := args.Input.PathInBinaryStore()
if inCache {
// TODO savil: change to ContentAddressedPath?
pathInStore, err := args.Input.InputAddressedPath()
if err != nil {
return -1, err
}
Expand Down Expand Up @@ -209,12 +210,12 @@ type ProfileInstallArgs struct {
func ProfileInstall(args *ProfileInstallArgs) error {
input := devpkg.PackageFromString(args.Package, args.Lockfile)

isInBinaryStore, err := input.IsInBinaryStore()
inCache, err := input.IsInBinaryCache()
if err != nil {
return err
}

if !isInBinaryStore && nix.IsGithubNixpkgsURL(input.URLForFlakeInput()) {
if !inCache && nix.IsGithubNixpkgsURL(input.URLForFlakeInput()) {
if err := nix.EnsureNixpkgsPrefetched(args.Writer, input.HashFromNixPkgsURL()); err != nil {
return err
}
Expand Down Expand Up @@ -262,14 +263,14 @@ func ProfileRemoveItems(profilePath string, items []*NixProfileListItem) error {
// 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) {
isInBinaryStore, err := pkg.IsInBinaryStore()
inCache, err := pkg.IsInBinaryCache()
if err != nil {
return "", err
}

if isInBinaryStore {
// TODO savil: change to ContentAddressablePath when that is implemented
installable, err := pkg.PathInBinaryStore()
if inCache {
// TODO savil: change to ContentAddressablePath?
installable, err := pkg.InputAddressedPath()
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/shellgen/flake_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func flakeInputs(ctx context.Context, packages []*devpkg.Package) ([]*flakeInput
return true
}

inStore, err := item.IsInBinaryStore()
inCache, err := item.IsInBinaryCache()
if err != nil {
// Ignore this error for now. TODO savil: return error?
return true
}
return !inStore
return !inCache
})

order := []string{}
Expand Down
20 changes: 10 additions & 10 deletions internal/shellgen/flake_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
// flakePlan contains the data to populate the top level flake.nix file
// that builds the devbox environment
type flakePlan struct {
BinaryCacheStore string
NixpkgsInfo *NixpkgsInfo
FlakeInputs []*flakeInput
Packages []*devpkg.Package
System string
BinaryCache string
NixpkgsInfo *NixpkgsInfo
FlakeInputs []*flakeInput
Packages []*devpkg.Package
System string
}

func newFlakePlan(ctx context.Context, devbox devboxer) (*flakePlan, error) {
Expand Down Expand Up @@ -73,10 +73,10 @@ func newFlakePlan(ctx context.Context, devbox devboxer) (*flakePlan, error) {
}

return &flakePlan{
BinaryCacheStore: devpkg.BinaryCacheStore,
FlakeInputs: flakeInputs,
NixpkgsInfo: nixpkgsInfo,
Packages: packages,
System: system,
BinaryCache: devpkg.BinaryCache,
FlakeInputs: flakeInputs,
NixpkgsInfo: nixpkgsInfo,
Packages: packages,
System: system,
}, nil
}
8 changes: 4 additions & 4 deletions internal/shellgen/tmpl/flake_remove_nixpkgs.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
devShells.{{ .System }}.default = pkgs.mkShell {
buildInputs = [
{{- range .Packages }}
{{- if .IsInBinaryStore }}
{{- if .IsInBinaryCache }}
(builtins.fetchClosure{
fromStore = "{{ $.BinaryCacheStore }}";
fromPath = "{{ .PathInBinaryStore }}";
toPath = "{{ .ContentAddressedStorePath }}";
fromStore = "{{ $.BinaryCache }}";
fromPath = "{{ .InputAddressedPath }}";
toPath = "{{ .ContentAddressedPath }}";
})
{{- end }}
{{- end }}
Expand Down