Skip to content

Commit d323c8e

Browse files
authored
[filegen] move NixpkgsInfo into filegen (no more plansdk) (#1192)
## Summary 1. Move `NixpkgsInfo` into package `filegen`. 2. Make its functions internal, since it is only used within filegen. 3. Move DefaultNixpkgsCommit to devconfig package, since it is only used there. ## How was it tested? compiles
1 parent 0cb96c1 commit d323c8e

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

internal/devconfig/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import (
1111
"strings"
1212

1313
"github.com/pkg/errors"
14-
1514
"go.jetpack.io/devbox/internal/boxcli/usererr"
1615
"go.jetpack.io/devbox/internal/cuecfg"
1716
"go.jetpack.io/devbox/internal/impl/shellcmd"
18-
"go.jetpack.io/devbox/internal/planner/plansdk"
1917
)
2018

2119
const DefaultName = "devbox.json"
@@ -86,8 +84,11 @@ func (c *Config) Equals(other *Config) bool {
8684
}
8785

8886
func (c *Config) NixPkgsCommitHash() string {
87+
// The commit hash for nixpkgs-unstable on 2023-01-25 from status.nixos.org
88+
const DefaultNixpkgsCommit = "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
89+
8990
if c == nil || c.Nixpkgs == nil || c.Nixpkgs.Commit == "" {
90-
return plansdk.DefaultNixpkgsCommit
91+
return DefaultNixpkgsCommit
9192
}
9293
return c.Nixpkgs.Commit
9394
}

internal/filegen/flake_input.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/samber/lo"
99
"go.jetpack.io/devbox/internal/goutil"
1010
"go.jetpack.io/devbox/internal/nix"
11-
"go.jetpack.io/devbox/internal/planner/plansdk"
1211
)
1312

1413
type flakeInput struct {
@@ -39,7 +38,7 @@ func (f *flakeInput) URLWithCaching() string {
3938
return f.URL
4039
}
4140
hash := nix.HashFromNixPkgsURL(f.URL)
42-
return plansdk.GetNixpkgsInfo(hash).URL
41+
return getNixpkgsInfo(hash).URL
4342
}
4443

4544
func (f *flakeInput) PkgImportName() string {

internal/filegen/flake_plan.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ package filegen
33
import (
44
"context"
55
"runtime/trace"
6-
7-
"go.jetpack.io/devbox/internal/planner/plansdk"
86
)
97

10-
// FlakePlan contains the data to populate the top level flake.nix file
8+
// flakePlan contains the data to populate the top level flake.nix file
119
// that builds the devbox environment
12-
type FlakePlan struct {
13-
NixpkgsInfo *plansdk.NixpkgsInfo
10+
type flakePlan struct {
11+
NixpkgsInfo *NixpkgsInfo
1412
FlakeInputs []*flakeInput
1513
}
1614

17-
func newFlakePlan(ctx context.Context, devbox devboxer) (*FlakePlan, error) {
15+
func newFlakePlan(ctx context.Context, devbox devboxer) (*flakePlan, error) {
1816
ctx, task := trace.NewTask(ctx, "devboxFlakePlan")
1917
defer task.End()
2018

@@ -37,20 +35,20 @@ func newFlakePlan(ctx context.Context, devbox devboxer) (*FlakePlan, error) {
3735
}
3836
}
3937

40-
shellPlan := &FlakePlan{}
38+
shellPlan := &flakePlan{}
4139
var err error
4240
shellPlan.FlakeInputs, err = flakeInputs(ctx, devbox)
4341
if err != nil {
4442
return nil, err
4543
}
4644

47-
nixpkgsInfo := plansdk.GetNixpkgsInfo(devbox.Config().NixPkgsCommitHash())
45+
nixpkgsInfo := getNixpkgsInfo(devbox.Config().NixPkgsCommitHash())
4846

4947
// This is an optimization. Try to reuse the nixpkgs info from the flake
5048
// inputs to avoid introducing a new one.
5149
for _, input := range shellPlan.FlakeInputs {
5250
if input.IsNixpkgs() {
53-
nixpkgsInfo = plansdk.GetNixpkgsInfo(input.HashFromNixPkgsURL())
51+
nixpkgsInfo = getNixpkgsInfo(input.HashFromNixPkgsURL())
5452
break
5553
}
5654
}

internal/filegen/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ var templateFuncs = template.FuncMap{
148148
"debug": debug.IsEnabled,
149149
}
150150

151-
func makeFlakeFile(outPath string, plan *FlakePlan) error {
151+
func makeFlakeFile(outPath string, plan *flakePlan) error {
152152
flakeDir := filepath.Join(outPath, "flake")
153153
err := writeFromTemplate(flakeDir, plan, "flake.nix")
154154
if err != nil {

internal/planner/plansdk/plansdk.go renamed to internal/filegen/nixpkgs.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023 Jetpack Technologies Inc and contributors. All rights reserved.
22
// Use of this source code is governed by the license in the LICENSE file.
33

4-
package plansdk
4+
package filegen
55

66
import (
77
"fmt"
@@ -18,10 +18,7 @@ type NixpkgsInfo struct {
1818
TarURL string
1919
}
2020

21-
// The commit hash for nixpkgs-unstable on 2023-01-25 from status.nixos.org
22-
const DefaultNixpkgsCommit = "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
23-
24-
func GetNixpkgsInfo(commitHash string) *NixpkgsInfo {
21+
func getNixpkgsInfo(commitHash string) *NixpkgsInfo {
2522
url := fmt.Sprintf("github:NixOS/nixpkgs/%s", commitHash)
2623
if mirror := nixpkgsMirrorURL(commitHash); mirror != "" {
2724
url = mirror

0 commit comments

Comments
 (0)