Skip to content

Commit 3aac497

Browse files
authored
[Remove Nixpkgs] remove feature flag (#2142)
## Summary We've had this feature launched for quite a while. Initially, I was reluctant to remove the feature-flag so that we could debug code paths for users on old versions of nix (which cannot benefit from the binary cache. IIRC nix < 1.17). However, in the time since I relied on this exactly once for some perf-related task, and not otherwise. At this point, I think we should remove it, and even print messages to users about updating their nix version if needed. ## How was it tested? It compiles. I could do `devbox shell` in this project.
1 parent 6549b43 commit 3aac497

File tree

14 files changed

+161
-326
lines changed

14 files changed

+161
-326
lines changed

internal/boxcli/featureflag/remove_nixpkgs.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

internal/devbox/update.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99

1010
"github.com/pkg/errors"
11-
"go.jetpack.io/devbox/internal/boxcli/featureflag"
1211
"go.jetpack.io/devbox/internal/devbox/devopt"
1312
"go.jetpack.io/devbox/internal/devpkg"
1413
"go.jetpack.io/devbox/internal/lock"
@@ -143,39 +142,36 @@ func (d *Devbox) mergeResolvedPackageToLockfile(
143142
}
144143

145144
// Add any missing system infos for packages whose versions did not change.
146-
if featureflag.RemoveNixpkgs.Enabled() {
147-
148-
if lockfile.Packages[pkg.Raw].Systems == nil {
149-
lockfile.Packages[pkg.Raw].Systems = map[string]*lock.SystemInfo{}
150-
}
145+
if lockfile.Packages[pkg.Raw].Systems == nil {
146+
lockfile.Packages[pkg.Raw].Systems = map[string]*lock.SystemInfo{}
147+
}
151148

152-
userSystem := nix.System()
153-
updated := false
154-
for sysName, newSysInfo := range resolved.Systems {
155-
// Check whether we are actually updating any system info.
156-
if sysName == userSystem {
157-
// The resolved pkg has a system info for the user's system, so add/overwrite it.
158-
if !newSysInfo.Equals(existing.Systems[userSystem]) {
159-
// We only guard this so that the ux messaging is accurate. We could overwrite every time.
160-
updated = true
161-
}
162-
} else {
163-
// Add other system infos if they don't exist, or if we have a different StorePath. This may
164-
// overwrite an existing StorePath, but to ensure correctness we should ensure that all StorePaths
165-
// come from the same package version.
166-
existingSysInfo, exists := existing.Systems[sysName]
167-
if !exists || !existingSysInfo.Equals(newSysInfo) {
168-
updated = true
169-
}
149+
userSystem := nix.System()
150+
updated := false
151+
for sysName, newSysInfo := range resolved.Systems {
152+
// Check whether we are actually updating any system info.
153+
if sysName == userSystem {
154+
// The resolved pkg has a system info for the user's system, so add/overwrite it.
155+
if !newSysInfo.Equals(existing.Systems[userSystem]) {
156+
// We only guard this so that the ux messaging is accurate. We could overwrite every time.
157+
updated = true
158+
}
159+
} else {
160+
// Add other system infos if they don't exist, or if we have a different StorePath. This may
161+
// overwrite an existing StorePath, but to ensure correctness we should ensure that all StorePaths
162+
// come from the same package version.
163+
existingSysInfo, exists := existing.Systems[sysName]
164+
if !exists || !existingSysInfo.Equals(newSysInfo) {
165+
updated = true
170166
}
171167
}
172-
if updated {
173-
// if we are updating the system info, then we should also update the other fields
174-
useResolvedPackageInLockfile(lockfile, pkg, resolved, existing)
168+
}
169+
if updated {
170+
// if we are updating the system info, then we should also update the other fields
171+
useResolvedPackageInLockfile(lockfile, pkg, resolved, existing)
175172

176-
ux.Finfo(d.stderr, "Updated system information for %s\n", pkg)
177-
return nil
178-
}
173+
ux.Finfo(d.stderr, "Updated system information for %s\n", pkg)
174+
return nil
179175
}
180176

181177
ux.Finfo(d.stderr, "Already up-to-date %s %s\n", pkg, existing.Version)

internal/devbox/update_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/stretchr/testify/require"
7-
"go.jetpack.io/devbox/internal/boxcli/featureflag"
87
"go.jetpack.io/devbox/internal/devpkg"
98
"go.jetpack.io/devbox/internal/lock"
109
"go.jetpack.io/devbox/internal/nix"
@@ -29,7 +28,6 @@ func TestUpdateNewPackageIsAdded(t *testing.T) {
2928
}
3029

3130
func TestUpdateNewCurrentSysInfoIsAdded(t *testing.T) {
32-
featureflag.RemoveNixpkgs.EnableForTest(t)
3331
devbox := devboxForTesting(t)
3432

3533
@@ -67,7 +65,6 @@ func TestUpdateNewCurrentSysInfoIsAdded(t *testing.T) {
6765
}
6866

6967
func TestUpdateNewSysInfoIsAdded(t *testing.T) {
70-
featureflag.RemoveNixpkgs.EnableForTest(t)
7168
devbox := devboxForTesting(t)
7269

7370
@@ -127,7 +124,6 @@ func TestUpdateNewSysInfoIsAdded(t *testing.T) {
127124
}
128125

129126
func TestUpdateOtherSysInfoIsReplaced(t *testing.T) {
130-
featureflag.RemoveNixpkgs.EnableForTest(t)
131127
devbox := devboxForTesting(t)
132128

133129

internal/devpkg/narinfo_cache.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/aws/aws-sdk-go-v2/aws"
1414
"github.com/aws/aws-sdk-go-v2/service/s3"
1515
"github.com/pkg/errors"
16-
"go.jetpack.io/devbox/internal/boxcli/featureflag"
1716
"go.jetpack.io/devbox/internal/debug"
1817
"go.jetpack.io/devbox/internal/devbox/providers/nixcache"
1918
"go.jetpack.io/devbox/internal/goutil"
@@ -59,9 +58,6 @@ func (p *Package) IsInBinaryCache() (bool, error) {
5958
// Callers of IsInBinaryCache may call this function first as a perf-optimization.
6059
func FillNarInfoCache(ctx context.Context, packages ...*Package) error {
6160
defer debug.FunctionTimer().End()
62-
if !featureflag.RemoveNixpkgs.Enabled() {
63-
return nil
64-
}
6561

6662
eligiblePackages := []*Package{}
6763
for _, p := range packages {
@@ -240,10 +236,6 @@ func (p *Package) isEligibleForBinaryCache() (bool, error) {
240236
// Hence, we compute nix.Version, nix.System and lockfile.Resolve prior to calling this
241237
// function from within a goroutine.
242238
func (p *Package) sysInfoIfExists() (*lock.SystemInfo, error) {
243-
if !featureflag.RemoveNixpkgs.Enabled() {
244-
return nil, nil
245-
}
246-
247239
if !p.isVersioned() {
248240
return nil, nil
249241
}

internal/lock/resolve.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ func (f *File) FetchResolvedPackage(pkg string) (*Package, error) {
5656
return nil, errors.Wrapf(nix.ErrPackageNotFound, "%s@%s", name, version)
5757
}
5858

59-
sysInfos := map[string]*SystemInfo{}
60-
if featureflag.RemoveNixpkgs.Enabled() {
61-
sysInfos, err = buildLockSystemInfos(packageVersion)
62-
if err != nil {
63-
return nil, err
64-
}
59+
sysInfos, err := buildLockSystemInfos(packageVersion)
60+
if err != nil {
61+
return nil, err
6562
}
6663
packageInfo, err := selectForSystem(packageVersion.Systems)
6764
if err != nil {

internal/nix/nix.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"time"
2121

2222
"github.com/pkg/errors"
23-
"go.jetpack.io/devbox/internal/boxcli/featureflag"
2423
"go.jetpack.io/devbox/internal/boxcli/usererr"
2524
"go.jetpack.io/devbox/internal/redact"
2625
"golang.org/x/mod/semver"
@@ -117,10 +116,7 @@ func FlakeNixpkgs(commit string) string {
117116
}
118117

119118
func ExperimentalFlags() []string {
120-
options := []string{"nix-command", "flakes"}
121-
if featureflag.RemoveNixpkgs.Enabled() {
122-
options = append(options, "fetch-closure")
123-
}
119+
options := []string{"nix-command", "flakes", "fetch-closure"}
124120
return []string{
125121
"--extra-experimental-features", "ca-derivations",
126122
"--option", "experimental-features", strings.Join(options, " "),

internal/shellgen/flake_input.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
"github.com/samber/lo"
12-
"go.jetpack.io/devbox/internal/boxcli/featureflag"
1312
"go.jetpack.io/devbox/internal/devpkg"
1413
"go.jetpack.io/devbox/internal/nix"
1514
)
@@ -168,15 +167,13 @@ func flakeInputs(ctx context.Context, packages []*devpkg.Package) []flakeInput {
168167

169168
// Don't include cached packages (like local or remote flakes)
170169
// that can be fetched from a Binary Cache Store.
171-
if featureflag.RemoveNixpkgs.Enabled() {
172-
// TODO(savil): return error?
173-
cached, err := pkg.IsInBinaryCache()
174-
if err != nil {
175-
slog.Error("error checking if package is in binary cache", "err", err)
176-
}
177-
if err == nil && cached {
178-
continue
179-
}
170+
// TODO(savil): return error?
171+
cached, err := pkg.IsInBinaryCache()
172+
if err != nil {
173+
slog.Error("error checking if package is in binary cache", "err", err)
174+
}
175+
if err == nil && cached {
176+
continue
180177
}
181178

182179
// Packages that need a glibc patch are assigned to the special

internal/shellgen/generate.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"text/template"
1717

1818
"github.com/pkg/errors"
19-
"go.jetpack.io/devbox/internal/boxcli/featureflag"
2019
"go.jetpack.io/devbox/internal/cuecfg"
2120
"go.jetpack.io/devbox/internal/debug"
2221
"go.jetpack.io/devbox/internal/redact"
@@ -184,9 +183,5 @@ var templateFuncs = template.FuncMap{
184183

185184
func makeFlakeFile(d devboxer, plan *flakePlan) error {
186185
flakeDir := FlakePath(d)
187-
templateName := "flake.nix"
188-
if featureflag.RemoveNixpkgs.Enabled() {
189-
templateName = "flake_remove_nixpkgs.nix"
190-
}
191-
return writeFromTemplate(flakeDir, plan, templateName, "flake.nix")
186+
return writeFromTemplate(flakeDir, plan, "flake.nix", "flake.nix")
192187
}

internal/shellgen/generate_test.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919
// update overwrites golden files with the new test results.
2020
var update = flag.Bool("update", false, "update the golden files with the test results")
2121

22+
// TestWriteFromTemplate will verify that the flake.nix code generation works as expected.
23+
// Note: this test was derived from an older flake.nix, prior to having the builtins.FetchClosures
24+
// and so may be a bit out of date. It could be updated to be better and more exhaustive.
2225
func TestWriteFromTemplate(t *testing.T) {
2326
t.Setenv("__DEVBOX_NIX_SYSTEM", "x86_64-linux")
2427
dir := filepath.Join(t.TempDir(), "makeme")
@@ -37,12 +40,15 @@ func TestWriteFromTemplate(t *testing.T) {
3740
cmpGoldenFile(t, outPath, "testdata/flake.nix.golden")
3841
})
3942
t.Run("WriteModifiedSmaller", func(t *testing.T) {
40-
emptyPlan := struct {
41-
NixpkgsInfo struct {
42-
URL string
43-
}
44-
FlakeInputs []flakeInput
45-
}{}
43+
emptyPlan := &flakePlan{
44+
NixpkgsInfo: &NixpkgsInfo{
45+
URL: "",
46+
TarURL: "",
47+
},
48+
Packages: []*devpkg.Package{},
49+
FlakeInputs: []flakeInput{},
50+
System: "x86_64-linux",
51+
}
4652
err = writeFromTemplate(dir, emptyPlan, "flake.nix", "flake.nix")
4753
if err != nil {
4854
t.Fatal("got error writing flake template:", err)
@@ -82,17 +88,12 @@ If the new file is correct, you can update the golden file with:
8288

8389
var (
8490
locker = &lockmock{}
85-
testFlakeTmplPlan = &struct {
86-
NixpkgsInfo struct {
87-
URL string
88-
}
89-
FlakeInputs []flakeInput
90-
}{
91-
NixpkgsInfo: struct {
92-
URL string
93-
}{
94-
URL: "https://github.com/nixos/nixpkgs/archive/b9c00c1d41ccd6385da243415299b39aa73357be.tar.gz",
91+
testFlakeTmplPlan = &flakePlan{
92+
NixpkgsInfo: &NixpkgsInfo{
93+
URL: "https://github.com/nixos/nixpkgs/archive/b9c00c1d41ccd6385da243415299b39aa73357be.tar.gz",
94+
TarURL: "", // TODO savil
9595
},
96+
Packages: []*devpkg.Package{}, // TODO savil
9697
FlakeInputs: []flakeInput{
9798
{
9899
Name: "nixpkgs",
@@ -123,6 +124,7 @@ var (
123124
},
124125
},
125126
},
127+
System: "x86_64-linux",
126128
}
127129
)
128130

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
{
2-
description = "A devbox shell";
2+
description = "A devbox shell";
33

4-
inputs = {
5-
nixpkgs.url = "";
6-
flake-utils.url = "github:numtide/flake-utils";
7-
};
4+
inputs = {
5+
nixpkgs.url = "";
6+
};
87

9-
outputs = {
10-
self,
11-
nixpkgs,
12-
flake-utils
13-
}:
14-
flake-utils.lib.eachDefaultSystem (system:
8+
outputs = {
9+
self,
10+
nixpkgs,
11+
}:
1512
let
16-
pkgs = (import nixpkgs {
17-
inherit system;
18-
config.allowUnfree = true;
19-
});
13+
pkgs = nixpkgs.legacyPackages.x86_64-linux;
2014
in
2115
{
22-
devShell = pkgs.mkShell {
23-
buildInputs = with pkgs; [
16+
devShells.x86_64-linux.default = pkgs.mkShell {
17+
buildInputs = [
2418
];
2519
};
26-
}
27-
);
28-
}
20+
};
21+
}

0 commit comments

Comments
 (0)