Skip to content

Commit 4c2cb52

Browse files
authored
[update] Fix update (#1662)
## Summary nix 2.19 changed how `nix flake update` [works](https://nixos.org/manual/nix/stable/release-notes/rl-2.19). This fixes it. ## How was it tested? - [x] Run update on nix < 2.19 and 2.19 - [x] Add update unit test
1 parent 80be512 commit 4c2cb52

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

.github/workflows/cli-tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ jobs:
137137
# Run tests on:
138138
# 1. the oldest supported nix version (which is 2.9.0? But determinate-systems installer has 2.12.0)
139139
# 2. nix version 2.17.0 which introduces a new code path that minimizes nixpkgs downloads.
140-
# 3. latest nix version (currently, that is 2.17.0, so omitted)
141-
nix-version: ["2.12.0", "2.17.0"]
140+
# 3. latest nix version
141+
nix-version: ["2.12.0", "2.17.0", "2.19.2"]
142142
exclude:
143143
- is-main: "not-main"
144144
os: "${{ inputs.run-mac-tests && 'dummy' || 'macos-latest' }}"
@@ -242,7 +242,7 @@ jobs:
242242
strategy:
243243
matrix:
244244
os: [ubuntu-latest, macos-latest]
245-
nix-version: [2.15.1, 2.16.1, 2.17.0, 2.18.0]
245+
nix-version: [2.15.1, 2.16.1, 2.17.0, 2.18.0, 2.19.2]
246246
runs-on: ${{ matrix.os }}
247247
steps:
248248
- uses: actions/checkout@v3

internal/nix/upgrade.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"go.jetpack.io/devbox/internal/redact"
1212
"go.jetpack.io/devbox/internal/ux"
13+
"go.jetpack.io/devbox/internal/vercheck"
1314
)
1415

1516
func ProfileUpgrade(ProfileDir string, idx int) error {
@@ -28,8 +29,16 @@ func ProfileUpgrade(ProfileDir string, idx int) error {
2829
}
2930

3031
func FlakeUpdate(ProfileDir string) error {
32+
version, err := Version()
33+
if err != nil {
34+
return err
35+
}
3136
ux.Finfo(os.Stderr, "Running \"nix flake update\"\n")
32-
cmd := exec.Command("nix", "flake", "update", ProfileDir)
37+
cmd := exec.Command("nix", "flake", "update")
38+
if vercheck.SemverCompare(version, "2.19.0") >= 0 {
39+
cmd.Args = append(cmd.Args, "--flake")
40+
}
41+
cmd.Args = append(cmd.Args, ProfileDir)
3342
cmd.Args = append(cmd.Args, ExperimentalFlags()...)
3443
out, err := cmd.CombinedOutput()
3544
if err != nil {

testscripts/update/update.test.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Testscript for exercising devbox update
2+
3+
exec devbox install
4+
5+
exec devbox update
6+
7+
-- devbox.json --
8+
{
9+
"packages": [
10+
"hello@latest",
11+
]
12+
}
13+
14+
-- devbox.lock --
15+
{
16+
"lockfile_version": "1",
17+
"packages": {
18+
19+
"last_modified": "2022-01-26T13:01:16Z",
20+
"resolved": "github:NixOS/nixpkgs/e722007bf05802573b41701c49da6c8814878171#hello",
21+
"source": "devbox-search",
22+
"version": "2.10",
23+
"systems": {
24+
"aarch64-darwin": {
25+
"store_path": "/nix/store/c24460c0iw7kai6z5aan6mkgfclpl2qj-hello-2.10"
26+
},
27+
"x86_64-darwin": {
28+
"store_path": "/nix/store/6wzargj47480y84cqqnm7n30xwqlbyrm-hello-2.10"
29+
},
30+
"x86_64-linux": {
31+
"store_path": "/nix/store/nndmy96lswhxc4xp49n950i1905qlfpy-hello-2.10"
32+
}
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)