Skip to content

Commit

Permalink
Passthru NixOS system & OpenGL Driver
Browse files Browse the repository at this point in the history
Signed-off-by: Tristan Ross <[email protected]>
  • Loading branch information
RossComputerGuy committed Jun 20, 2024
1 parent 912afa5 commit 2183a0f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions crates/krun-guest/src/mount.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::fs::File;
use std::fs::{File, create_dir_all};
use std::env::var_os;
use std::os::fd::AsFd;

use anyhow::{Context, Result};
use rustix::fs::CWD;
use rustix::mount::{mount2, move_mount, open_tree, MountFlags, MoveMountFlags, OpenTreeFlags};
use rustix::mount::{mount2, move_mount, mount_recursive_bind, open_tree, MountFlags, MoveMountFlags, OpenTreeFlags};

pub fn mount_filesystems() -> Result<()> {
mount2(
Expand Down Expand Up @@ -40,6 +41,26 @@ pub fn mount_filesystems() -> Result<()> {
.context("Failed to move_mount `/etc/resolv.conf`")?;
}

let opengl_driver = var_os("OPENGL_DRIVER");
if let Some(dir) = opengl_driver {
create_dir_all("/run/opengl-driver")?;
mount_recursive_bind(
dir,
"/run/opengl-driver",
)
.context("Failed to mount `/run/opengl-driver`")?;
}

let nixos_curr_sys = var_os("NIXOS_CURRENT_SYSTEM");
if let Some(dir) = nixos_curr_sys {
create_dir_all("/run/current-system")?;
mount_recursive_bind(
dir,
"/run/current-system",
)
.context("Failed to mount `/run/current-system`")?;
}

mount2(
Some("binfmt_misc"),
"/proc/sys/fs/binfmt_misc",
Expand Down
2 changes: 2 additions & 0 deletions crates/krun/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const WELL_KNOWN_ENV_VARS: [&str; 5] = [
"MESA_LOADER_DRIVER_OVERRIDE", // needed for asahi
"PATH", // needed by `krun-guest` program
"RUST_LOG",
"OPENGL_DRIVER", // needed for OpenGL on NixOS
"NIXOS_CURRENT_SYSTEM", // needed for some paths to work on NixOS
];

/// See https://github.com/AsahiLinux/docs/wiki/Devices
Expand Down

0 comments on commit 2183a0f

Please sign in to comment.