Skip to content

Commit

Permalink
feat: Add sharing of /etc directory from host to packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dleggo committed Feb 26, 2025
1 parent ab2e87a commit b7afaf1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ indicatif = "0.17.11"
kdl = "6.3.3"
log = "0.4.25"
nix = { version = "0.29.0", features = ["process"] }
pathdiff = "0.2.3"
pubgrub = "0.2.1"
rand = "0.9.0"
reqwest = { version = "0.12.12", features = [
Expand Down
30 changes: 28 additions & 2 deletions src/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use log::{error, info};
use std::path::{Path, PathBuf};
use std::{
os::unix::fs::symlink,
path::{Path, PathBuf},
};

use anyhow::{anyhow, bail, Result};
use anyhow::{anyhow, bail, Context, Result};
use rand::prelude::*;
use sys_mount::{unmount, Mount, MountFlags, UnmountFlags};

Expand Down Expand Up @@ -124,6 +127,29 @@ pub fn run_pkg(
binds.push(dir_target);
}

std::fs::DirBuilder::new()
.recursive(true)
.create(out_dir.join("etc"))?;
for ent in Path::new("/etc").read_dir()? {
let ent = ent?;
let relative_ent = make_path_relative(&ent.path());
if ent.path().is_dir() {
std::fs::DirBuilder::new()
.recursive(true)
.create(out_dir.join(&ent.path()))?;
} else {
let target = out_dir.join("fpkg-root").join(&relative_ent);
let source = out_dir.join(&relative_ent);
let target = pathdiff::diff_paths(&target, &source)
.ok_or(anyhow!("Failed to diff paths"))?;
symlink(&target, &source).context(anyhow!(
"Failed to symlink {} to {}",
target.display(),
source.display()
))?;
}
}

let mut cleanup = false;

let mut prefix = "/";
Expand Down

0 comments on commit b7afaf1

Please sign in to comment.