MCPcopy Index your code
hub / github.com/jetify-com/devbox / Download

Method Download

nix/install.go:23–71  ·  view source on GitHub ↗

Download downloads the Nix installer without running it.

(ctx context.Context)

Source from the content-addressed store, hash-verified

21
22// Download downloads the Nix installer without running it.
23func (i *Installer) Download(ctx context.Context) error {
24 if i.Path != "" {
25 return fmt.Errorf("installer already downloaded: %s", i.Path)
26 }
27
28 system := ""
29 switch runtime.GOARCH {
30 case "amd64":
31 switch runtime.GOOS {
32 case "darwin":
33 system = "x86_64-darwin"
34 case "linux":
35 system = "x86_64-linux"
36 }
37 case "arm64":
38 switch runtime.GOOS {
39 case "darwin":
40 system = "aarch64-darwin"
41 case "linux":
42 system = "aarch64-linux"
43 }
44 }
45
46 url := "https://artifacts.nixos.org/experimental-installer/nix-installer-" + system
47 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
48 if err != nil {
49 return fmt.Errorf("create request: %v", err)
50 }
51
52 resp, err := http.DefaultClient.Do(req)
53 if err != nil {
54 return fmt.Errorf("do request: %v", err)
55 }
56 defer resp.Body.Close()
57
58 if resp.StatusCode != http.StatusOK {
59 return fmt.Errorf("status %s", resp.Status)
60 }
61 installer, err := writeTempFile(resp.Body)
62 if err != nil {
63 return err
64 }
65 err = os.Chmod(installer, 0o755)
66 if err != nil {
67 return fmt.Errorf("chmod 0755 installer: %v", err)
68 }
69 i.Path = installer
70 return nil
71}
72
73// Run downloads and installs Nix.
74func (i *Installer) Run(ctx context.Context) error {

Callers 4

RunMethod · 0.95
EnsureNixInstalledFunction · 0.95
PullToTmpFunction · 0.80
secretsDownloadCmdFunction · 0.80

Calls 2

writeTempFileFunction · 0.85
DoMethod · 0.45

Tested by

no test coverage detected