Skip to content

Commit a25dd4d

Browse files
authored
[Flakes] Changes to local flakes should reflect in shell after devbox install (#1063)
## Summary **Problem:** Changes to local flakes would not be reflected in the current shell. **Product workflow after this fix:** 1. User should edit the flake.nix file. 2. User should run `devbox install`. 3. The newly updated binaries from the flake should be available in their environment. This PR makes two fixes: 1. Changes the `devbox.ConfigHash` to incorporate the contents of local flake files i.e. local inputs. 2. Calls `wrapnix.CreateWrappers` in `devbox.PrintEnv` to ensure that we re-create the binary wrappers to point to the latest binaries installed by the local flake. ## How was it tested? the below was run within `devbox shell` of each example. in `examples/flakes/php/my-php-flake/flake.nix`, removed `ds` extension. Ran `devbox install`. And confirmed `ds` was removed via getting no output from `php -m | grep ds`. I then re-added `ds` extension back, re-ran `devbox install` and this time `php -m | grep ds` returned a result. in `examples/flakes/go-mod/ory-cli`, I changed the post-install binary's name from `ory` to `ory-renamed`. Ran `devbox install` and `which ory-renamed` returned a path to the binary.
1 parent 25b9081 commit a25dd4d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

internal/impl/devbox.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ func (d *Devbox) Config() *devconfig.Config {
110110
}
111111

112112
func (d *Devbox) ConfigHash() (string, error) {
113-
return d.cfg.Hash()
113+
hashes := lo.Map(d.packagesAsInputs(), func(i *nix.Input, _ int) string { return i.Hash() })
114+
h, err := d.cfg.Hash()
115+
if err != nil {
116+
return "", err
117+
}
118+
return cuecfg.Hash(h + strings.Join(hashes, ""))
114119
}
115120

116121
func (d *Devbox) NixPkgsCommitHash() string {
@@ -280,6 +285,10 @@ func (d *Devbox) PrintEnv(ctx context.Context, includeHooks bool) (string, error
280285
return "", err
281286
}
282287

288+
if err := wrapnix.CreateWrappers(ctx, d); err != nil {
289+
return "", err
290+
}
291+
283292
envStr := exportify(envs)
284293

285294
if includeHooks {

internal/nix/input.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var inputNameRegex = regexp.MustCompile("[^a-zA-Z0-9-]+")
6464
func (i *Input) InputName() string {
6565
result := ""
6666
if i.IsLocal() {
67-
result = filepath.Base(i.Path) + "-" + i.hash()
67+
result = filepath.Base(i.Path) + "-" + i.Hash()
6868
} else if i.IsGithub() {
6969
result = "gh-" + strings.Join(strings.Split(i.Opaque, "/"), "-")
7070
} else if url := i.URLForInput(); IsGithubNixpkgsURL(url) {
@@ -74,7 +74,7 @@ func (i *Input) InputName() string {
7474
}
7575
result = "nixpkgs-" + u
7676
} else {
77-
result = i.String() + "-" + i.hash()
77+
result = i.String() + "-" + i.Hash()
7878
}
7979
return inputNameRegex.ReplaceAllString(result, "-")
8080
}
@@ -221,7 +221,7 @@ func (i *Input) urlWithoutFragment() string {
221221
return u.String()
222222
}
223223

224-
func (i *Input) hash() string {
224+
func (i *Input) Hash() string {
225225
// For local flakes, use content hash of the flake.nix file to ensure
226226
// user always gets newest input.
227227
if i.IsLocal() {

0 commit comments

Comments
 (0)