@@ -2,7 +2,6 @@ package devbox
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"fmt"
7
6
"strings"
8
7
@@ -12,39 +11,31 @@ import (
12
11
13
12
// syncFlakeToProfile ensures the buildInputs from the flake's devShell are
14
13
// installed in the nix profile.
15
- func (d * Devbox ) syncFlakeToProfile (ctx context.Context ) error {
14
+ // buildInputs is a space-separated list of store paths from the nix print-dev-env output's buildInputs.
15
+ func (d * Devbox ) syncFlakeToProfile (ctx context.Context , buildInputs string ) error {
16
16
profilePath , err := d .profilePath ()
17
17
if err != nil {
18
18
return err
19
19
}
20
20
21
- // Get the build inputs (i.e. store paths) from the generated flake's devShell.
22
- buildInputPaths , err := nix .Eval (
23
- ctx ,
24
- d .stderr ,
25
- d .flakeDir ()+ "#devShells." + nix .System ()+ ".default.buildInputs" ,
26
- "--json" ,
27
- )
28
- if err != nil {
29
- return fmt .Errorf ("nix eval devShells: %v" , err )
30
- }
31
- storePaths := []string {}
32
- if err := json .Unmarshal (buildInputPaths , & storePaths ); err != nil {
33
- return fmt .Errorf ("unmarshal store paths: %s: %v" , buildInputPaths , err )
21
+ // Get the build inputs (i.e. store paths) from the generated flake's print-dev-env output
22
+ wantStorePaths := []string {}
23
+ if buildInputs != "" { // if buildInputs is empty, then we don't want wantStorePaths to be an array with a single "" entry
24
+ wantStorePaths = strings .Split (buildInputs , " " )
34
25
}
35
26
36
27
// Get the store-paths of the packages currently installed in the nix profile
37
28
items , err := nixprofile .ProfileListItems (ctx , d .stderr , profilePath )
38
29
if err != nil {
39
30
return fmt .Errorf ("nix profile list: %v" , err )
40
31
}
41
- got := make ([]string , 0 , len (items ))
32
+ gotStorePaths := make ([]string , 0 , len (items ))
42
33
for _ , item := range items {
43
- got = append (got , item .StorePaths ()... )
34
+ gotStorePaths = append (gotStorePaths , item .StorePaths ()... )
44
35
}
45
36
46
37
// Diff the store paths and install/remove packages as needed
47
- add , remove := diffStorePaths (got , storePaths )
38
+ add , remove := diffStorePaths (gotStorePaths , wantStorePaths )
48
39
if len (remove ) > 0 {
49
40
packagesToRemove := make ([]string , 0 , len (remove ))
50
41
for _ , p := range remove {
0 commit comments