Skip to content

Commit 2563283

Browse files
authored
[bugs] Fix shell.nix bug and ensure current symlink (#1015)
## Summary Fixes 2 unrelated bugs: * Create current symlink if needed. This has no user impact, but is causing devbox cloud to break. It is also needed for future multi-profile support. * Ensure shell.nix works by including correct URL in fetchTarball. This affects direnv users that have a legacy .envrc file. New/updated users are unaffected. Fixes #1010 cc: @Lagoja ## How was it tested? * Deleted current symlink, and saw it being recreated. * `nix-shell .devbox/gen/shell.nix`
1 parent 12e46f4 commit 2563283

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

internal/impl/global.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package impl
55

66
import (
77
"fmt"
8+
"io/fs"
89
"net/url"
910
"os"
1011
"path/filepath"
@@ -162,7 +163,21 @@ func (d *Devbox) addFromPull(pullCfg *Config) error {
162163

163164
func GlobalDataPath() (string, error) {
164165
path := xdg.DataSubpath(filepath.Join("devbox/global", currentGlobalProfile))
165-
return path, errors.WithStack(os.MkdirAll(path, 0755))
166+
if err := os.MkdirAll(path, 0755); err != nil {
167+
return "", errors.WithStack(err)
168+
}
169+
170+
nixProfilePath := filepath.Join(path, "profile")
171+
currentPath := xdg.DataSubpath("devbox/global/current")
172+
173+
// For now default is always current. In the future we will support multiple
174+
// and allow user to switch.
175+
err := os.Symlink(nixProfilePath, currentPath)
176+
if err != nil && !errors.Is(err, fs.ErrExist) {
177+
return "", errors.WithStack(err)
178+
}
179+
180+
return path, nil
166181
}
167182

168183
func GlobalNixProfilePath() (string, error) {

internal/impl/tmpl/shell.nix.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let
22
pkgs = import
33
(fetchTarball {
4-
url = "{{ .NixpkgsInfo.URL }}";
4+
url = "{{ .NixpkgsInfo.TarURL }}";
55
})
66
{ };
77
{{- range .Definitions}}

internal/planner/plansdk/plansdk.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,22 @@ func WelcomeMessage(s string) string {
8585
// TODO: We can probably get rid of this once we remove the haskell and php
8686
// planners
8787
type NixpkgsInfo struct {
88-
URL string
88+
URL string
89+
TarURL string
8990
}
9091

9192
// The commit hash for nixpkgs-unstable on 2023-01-25 from status.nixos.org
9293
const DefaultNixpkgsCommit = "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
9394

9495
func GetNixpkgsInfo(commitHash string) *NixpkgsInfo {
95-
mirror := nixpkgsMirrorURL(commitHash)
96-
if mirror != "" {
97-
return &NixpkgsInfo{
98-
URL: mirror,
99-
}
96+
url := fmt.Sprintf("github:NixOS/nixpkgs/%s", commitHash)
97+
if mirror := nixpkgsMirrorURL(commitHash); mirror != "" {
98+
url = mirror
10099
}
101100
return &NixpkgsInfo{
102-
URL: fmt.Sprintf("github:NixOS/nixpkgs/%s", commitHash),
101+
URL: url,
102+
// legacy, used for shell.nix (which is no longer used, but some direnv users still need it)
103+
TarURL: fmt.Sprintf("https://github.com/nixos/nixpkgs/archive/%s.tar.gz", commitHash),
103104
}
104105
}
105106

0 commit comments

Comments
 (0)