Skip to content

Commit c9dbf0e

Browse files
committed
mount-paths: add exclude paths
1 parent ad1433f commit c9dbf0e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/main.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{
1313
};
1414

1515
use nix::{
16-
mount::{mount, MsFlags},
16+
mount::{mount, umount, MsFlags},
1717
sched::{unshare, CloneFlags},
1818
sys::signal::{kill, Signal},
1919
sys::wait::{waitpid, WaitPidFlag, WaitStatus},
@@ -246,7 +246,7 @@ impl<'a> RunChroot<'a> {
246246
let target = self.resolve_nix_path(path.clone(), true)
247247
.unwrap_or_else(|err| panic!("failed to resolve symlink {}: {}", &path.display(), err));
248248

249-
eprintln!("MIRROR SYMLINK {} -> {}", link_path.display(), target.display());
249+
eprintln!("MIRROR SYMLINK {} -> {}", target.display(), link_path.display());
250250

251251
symlink(&target, &link_path).unwrap_or_else(|err| {
252252
panic!(
@@ -284,10 +284,12 @@ impl<'a> RunChroot<'a> {
284284

285285
if stat.is_dir() {
286286
self.bind_mount_directory(entry);
287-
} else if stat.is_file() {
287+
} else if stat.is_file() || path == Path::new("/dev/null") {
288288
self.bind_mount_file(entry);
289289
} else if stat.file_type().is_symlink() {
290290
self.mirror_symlink(entry);
291+
} else {
292+
panic!("don't know what to do with: {}", path.display())
291293
}
292294
}
293295

@@ -312,6 +314,10 @@ impl<'a> RunChroot<'a> {
312314
// TODO: test mounting in something to `/`; should work
313315
// TODO: test `cargo` or something else where the symlink's name is actually important (both as an explicit bind mount and an incidental one to make sure the logic is right)
314316

317+
let mount_exclude_list = vec![
318+
(Path::new("/var/run/nscd")),
319+
];
320+
315321
// can be "absolute" (wrt to the profile dir) or relative
316322
let profile_links = vec![
317323
(Path::new("/sbin/zic"), Path::new("/usr/bin/zic")),
@@ -324,8 +330,8 @@ impl<'a> RunChroot<'a> {
324330
let regular_links = vec![
325331
(PathBuf::from("/some/dir/home/.nix-profile/bin/cargo"), Path::new("/bin/cargo")),
326332
(PathBuf::from("/some/dir/config/group"), Path::new("/etc/group")),
333+
(PathBuf::from("/some/dir/config/passwd"), Path::new("/etc/passwd")),
327334
];
328-
329335
// mount in explicit mounts (profile relative and absolute):
330336
let user = unistd::User::from_uid(uid).unwrap().unwrap();
331337
let profile_dir = self.nixdir.join("var/nix/profiles/per-user").join(&user.name).join("profile");
@@ -350,6 +356,12 @@ impl<'a> RunChroot<'a> {
350356
(prof_p, chroot_p)
351357
})
352358
.map(|(prof_p, chroot_p)| (profile_dir.as_ref().unwrap().join(prof_p), chroot_p))
359+
.chain(
360+
// TODO: this should actually probably happen first.
361+
mount_exclude_list
362+
.iter()
363+
.map(|&ex| (PathBuf::from("/dev/null"), ex))
364+
)
353365
.chain(
354366
regular_links
355367
.into_iter()
@@ -398,6 +410,12 @@ impl<'a> RunChroot<'a> {
398410
self.bind_mount_direntry(&entry);
399411
}
400412

413+
for p in mount_exclude_list {
414+
let mount = self.rootdir.join(p.strip_prefix("/").unwrap());
415+
eprintln!("UNBIND {}", mount.display());
416+
umount(&mount).unwrap();
417+
}
418+
401419
// mount the store
402420
let nix_mount = self.rootdir.join("nix");
403421
fs::create_dir(&nix_mount)

0 commit comments

Comments
 (0)