Run downloads and installs Nix.
(ctx context.Context)
| 72 | |
| 73 | // Run downloads and installs Nix. |
| 74 | func (i *Installer) Run(ctx context.Context) error { |
| 75 | if i.Path == "" { |
| 76 | err := i.Download(ctx) |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | cmd := exec.CommandContext(ctx, i.Path, "install") |
| 83 | switch runtime.GOOS { |
| 84 | case "darwin": |
| 85 | cmd.Args = append(cmd.Args, "macos") |
| 86 | case "linux": |
| 87 | cmd.Args = append(cmd.Args, "linux") |
| 88 | _, err := os.Stat("/run/systemd/system") |
| 89 | if errors.Is(err, os.ErrNotExist) { |
| 90 | // Respect any env var settings from the user. |
| 91 | _, ok := os.LookupEnv("NIX_INSTALLER_INIT") |
| 92 | if !ok { |
| 93 | cmd.Args = append(cmd.Args, "--init", "none") |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | cmd.Args = append(cmd.Args, "--no-confirm") |
| 98 | cmd.Cancel = func() error { |
| 99 | return cmd.Process.Signal(os.Interrupt) |
| 100 | } |
| 101 | cmd.Stdin = os.Stdin |
| 102 | cmd.Stdout = os.Stdout |
| 103 | cmd.Stderr = os.Stderr |
| 104 | if err := cmd.Run(); err != nil { |
| 105 | return fmt.Errorf("run installer: %v", err) |
| 106 | } |
| 107 | _, _ = SourceProfile() |
| 108 | return nil |
| 109 | } |
| 110 | |
| 111 | func writeTempFile(r io.Reader) (path string, err error) { |
| 112 | tempFile, err := os.CreateTemp("", "devbox-nix-installer-") |
no test coverage detected