-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dxvm: rosetta, silent boot and other enhancements
A bunch of new miscellaneous new features and improvements: - Rosetta is enabled on `aarch64-darwin`. This allows VMs to transparently run aarch64 and x86_64 Linux binaries simultaneously. - Install x86_64 binaries with Nix using the `--system` flag. For example, `nix profile install --system x86_64 <pkg>`. - The current Devbox project directory is now automatically detected and mounted. It can be found in `~/devbox` in the VM. - Devbox is automatically installed when the VM is created using the `github:jetpack-io/devbox?ref=gcurtis/flake` flake. - Starting a VM is now completely silent. The kernel's console is sent to `.devbox/vm/console` instead of stdout so that the first thing the user sees is their own shell prompt. - This work really well when launching a paused VM. If the VM resumes fast enough, it feels like using a normal shell. - Bootstrapping from an NixOS installer ISO with the `-install` flag is now fully automated. This is done by reading/writing to the VM's console using a pipe (similar to a program like `expect`). - Fixed a bug where stopping the VM would always return an error.
- Loading branch information
Showing
9 changed files
with
446 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# ignore files by Jetbrains IDEs | ||
*.idea | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package vm | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
"os" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/Code-Hex/vz/v3" | ||
) | ||
|
||
func scriptedConsole(ctx context.Context, logger *slog.Logger, prompt string, script []string) (*vz.VirtioConsoleDeviceSerialPortConfiguration, error) { | ||
stdinr, stdinw, err := os.Pipe() | ||
if err != nil { | ||
return nil, fmt.Errorf("create stdin pipe: %v", err) | ||
} | ||
stdoutr, stdoutw, err := os.Pipe() | ||
if err != nil { | ||
return nil, fmt.Errorf("create stdout pipe: %v", err) | ||
} | ||
|
||
go func() { | ||
var idle *time.Timer | ||
idleDur := time.Second | ||
sawPrompt := false | ||
doneWriting := false | ||
scanner := bufio.NewScanner(io.TeeReader(stdoutr, os.Stdout)) | ||
for scanner.Scan() && ctx.Err() == nil { | ||
logger.Debug("install console", "stdout", scanner.Text()) | ||
|
||
if doneWriting { | ||
continue | ||
} | ||
if idle != nil { | ||
doneWriting = !idle.Reset(idleDur) | ||
continue | ||
} | ||
|
||
sawPrompt = sawPrompt || strings.Contains(scanner.Text(), prompt) | ||
if !sawPrompt { | ||
continue | ||
} | ||
idle = time.AfterFunc(idleDur, sync.OnceFunc(func() { | ||
_, err := stdinw.WriteString(strings.Join(script, " && ") + "\n") | ||
if err != nil { | ||
logger.Error("error writing to VM standard input", "err", err) | ||
} | ||
stdinw.Close() | ||
})) | ||
} | ||
if err := scanner.Err(); err != nil { | ||
logger.Error("error reading install console stdout", "err", err) | ||
} | ||
}() | ||
|
||
attach, err := vz.NewFileHandleSerialPortAttachment(stdinr, stdoutw) | ||
if err != nil { | ||
return nil, fmt.Errorf("create serial port attachment: %v", err) | ||
} | ||
config, err := vz.NewVirtioConsoleDeviceSerialPortConfiguration(attach) | ||
if err != nil { | ||
return nil, fmt.Errorf("create serial port configuration: %v", err) | ||
} | ||
return config, nil | ||
} |
Oops, something went wrong.